diff --git a/bcs-services/bcs-bscp/cmd/api-server/service/defaultresource.go b/bcs-services/bcs-bscp/cmd/api-server/service/defaultresource.go index e5ab465bc0..85d449aa17 100644 --- a/bcs-services/bcs-bscp/cmd/api-server/service/defaultresource.go +++ b/bcs-services/bcs-bscp/cmd/api-server/service/defaultresource.go @@ -59,6 +59,4 @@ func (p *proxy) initBizsOfTmplSpaces() { bizsOfTS.Bizs[bizID] = struct{}{} } logs.Infof("init bizs of template spaces success, len(biz):%d", len(resp.BizIds)) - - return } diff --git a/bcs-services/bcs-bscp/cmd/auth-server/service/auth/adaptor.go b/bcs-services/bcs-bscp/cmd/auth-server/service/auth/adaptor.go index 5f42f272b1..bfbb65db6b 100644 --- a/bcs-services/bcs-bscp/cmd/auth-server/service/auth/adaptor.go +++ b/bcs-services/bcs-bscp/cmd/auth-server/service/auth/adaptor.go @@ -26,7 +26,7 @@ import ( // AdaptAuthOptions convert bscp auth resource to iam action id and resources func AdaptAuthOptions(a *meta.ResourceAttribute) (client.ActionID, []client.Resource, error) { if a == nil { - return "", nil, errf.New(errf.InvalidParameter, fmt.Sprintf("resource attribute is not set")) + return "", nil, errf.New(errf.InvalidParameter, "resource attribute is not set") } // skip actions do not need to relate to resources diff --git a/bcs-services/bcs-bscp/cmd/auth-server/service/filter.go b/bcs-services/bcs-bscp/cmd/auth-server/service/filter.go index fe74404b1c..1b95e0e499 100644 --- a/bcs-services/bcs-bscp/cmd/auth-server/service/filter.go +++ b/bcs-services/bcs-bscp/cmd/auth-server/service/filter.go @@ -52,20 +52,20 @@ func (g *gateway) setFilter(next http.Handler) http.Handler { module = paths[4] } else { logs.Errorf("received url path length not conform to the regulations, path: %s", r.URL.Path) - fmt.Fprintf(w, errf.New(http.StatusNotFound, "Not Found").Error()) + fmt.Fprint(w, errf.New(http.StatusNotFound, "Not Found").Error()) return } switch moduleType(module) { case iamModule: if err := iamRequestFilter(g.iamSys, w, r); err != nil { - fmt.Fprintf(w, errf.Error(err).Error()) + fmt.Fprint(w, errf.Error(err).Error()) return } case authModule: if err := authRequestFilter(w, r); err != nil { - fmt.Fprintf(w, errf.Error(err).Error()) + fmt.Fprint(w, errf.Error(err).Error()) return } @@ -73,7 +73,7 @@ func (g *gateway) setFilter(next http.Handler) http.Handler { default: logs.Errorf("received unknown module's request req: %v", r) - fmt.Fprintf(w, errf.New(http.StatusNotFound, "Not Found").Error()) + fmt.Fprint(w, errf.New(http.StatusNotFound, "Not Found").Error()) return } diff --git a/bcs-services/bcs-bscp/cmd/auth-server/service/service.go b/bcs-services/bcs-bscp/cmd/auth-server/service/service.go index b29595452c..7649e1a4ff 100644 --- a/bcs-services/bcs-bscp/cmd/auth-server/service/service.go +++ b/bcs-services/bcs-bscp/cmd/auth-server/service/service.go @@ -23,6 +23,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/status" "google.golang.org/protobuf/proto" @@ -129,7 +130,7 @@ func newClientSet(sd serviced.Discover, tls cc.TLSConfig, iamSettings cc.IAM, di if !tls.Enable() { // dial without ssl - opts = append(opts, grpc.WithInsecure()) + opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials())) } else { // dial with ssl. tlsC, err := tools.ClientTLSConfVerify(tls.InsecureSkipVerify, tls.CAFile, tls.CertFile, tls.KeyFile, diff --git a/bcs-services/bcs-bscp/cmd/cache-service/service/cache/keys/cache.go b/bcs-services/bcs-bscp/cmd/cache-service/service/cache/keys/cache.go index 3ca1184198..f04b62e822 100644 --- a/bcs-services/bcs-bscp/cmd/cache-service/service/cache/keys/cache.go +++ b/bcs-services/bcs-bscp/cmd/cache-service/service/cache/keys/cache.go @@ -72,8 +72,8 @@ func (k keyGenerator) ReleasedGroup(bizID uint32, appID uint32) string { func (k keyGenerator) ReleasedGroupTtlSec(withRange bool) int { if withRange { - rand.Seed(time.Now().UnixNano()) - seconds := rand.Intn(k.releasedGroupTTLRange[1]-k.releasedGroupTTLRange[0]) + k.releasedGroupTTLRange[0] + r := rand.New(rand.NewSource(time.Now().UnixNano())) + seconds := r.Intn(k.releasedGroupTTLRange[1]-k.releasedGroupTTLRange[0]) + k.releasedGroupTTLRange[0] return seconds } @@ -93,8 +93,8 @@ func (k keyGenerator) CredentialMatchedCI(bizID uint32, credential string) strin func (k keyGenerator) CredentialMatchedCITtlSec(withRange bool) int { if withRange { - rand.Seed(time.Now().UnixNano()) - seconds := rand.Intn(k.credentialMatchedCITTLRange[1]- + r := rand.New(rand.NewSource(time.Now().UnixNano())) + seconds := r.Intn(k.credentialMatchedCITTLRange[1]- k.credentialMatchedCITTLRange[0]) + k.credentialMatchedCITTLRange[0] return seconds } @@ -114,8 +114,8 @@ func (k keyGenerator) Credential(bizID uint32, str string) string { // CredentialTtlSec generate the credential's TTL seconds func (k keyGenerator) CredentialTtlSec(withRange bool) int { if withRange { - rand.Seed(time.Now().UnixNano()) - seconds := rand.Intn(k.credentialTTLRange[1]-k.credentialTTLRange[0]) + k.credentialTTLRange[0] + r := rand.New(rand.NewSource(time.Now().UnixNano())) + seconds := r.Intn(k.credentialTTLRange[1]-k.credentialTTLRange[0]) + k.credentialTTLRange[0] return seconds } return k.credentialTTLRange[0] @@ -135,8 +135,8 @@ func (k keyGenerator) ReleasedCI(bizID uint32, releaseID uint32) string { func (k keyGenerator) ReleasedCITtlSec(withRange bool) int { if withRange { - rand.Seed(time.Now().UnixNano()) - seconds := rand.Intn(k.releasedCITTLRange[1]-k.releasedCITTLRange[0]) + k.releasedCITTLRange[0] + r := rand.New(rand.NewSource(time.Now().UnixNano())) + seconds := r.Intn(k.releasedCITTLRange[1]-k.releasedCITTLRange[0]) + k.releasedCITTLRange[0] return seconds } @@ -156,8 +156,8 @@ func (k keyGenerator) ReleasedHook(bizID uint32, releaseID uint32) string { func (k keyGenerator) ReleasedHookTtlSec(withRange bool) int { if withRange { - rand.Seed(time.Now().UnixNano()) - seconds := rand.Intn(k.releasedHookTTLRange[1]-k.releasedHookTTLRange[0]) + k.releasedHookTTLRange[0] + r := rand.New(rand.NewSource(time.Now().UnixNano())) + seconds := r.Intn(k.releasedHookTTLRange[1]-k.releasedHookTTLRange[0]) + k.releasedHookTTLRange[0] return seconds } @@ -186,8 +186,8 @@ func (k keyGenerator) AppMeta(bizID uint32, appID uint32) string { func (k keyGenerator) AppMetaTtlSec(withRange bool) int { if withRange { - rand.Seed(time.Now().UnixNano()) - seconds := rand.Intn(k.appMetaTTLRange[1]-k.appMetaTTLRange[0]) + k.appMetaTTLRange[0] + r := rand.New(rand.NewSource(time.Now().UnixNano())) + seconds := r.Intn(k.appMetaTTLRange[1]-k.appMetaTTLRange[0]) + k.appMetaTTLRange[0] return seconds } @@ -201,8 +201,8 @@ func (k keyGenerator) NullValue() string { // NullKeyTtlSec return the null key's ttl seconds func (k keyGenerator) NullKeyTtlSec() int { - rand.Seed(time.Now().UnixNano()) - seconds := rand.Intn(k.nullKeyTTLRange[1]-k.nullKeyTTLRange[0]) + k.nullKeyTTLRange[0] + r := rand.New(rand.NewSource(time.Now().UnixNano())) + seconds := r.Intn(k.nullKeyTTLRange[1]-k.nullKeyTTLRange[0]) + k.nullKeyTTLRange[0] return seconds } diff --git a/bcs-services/bcs-bscp/cmd/cache-service/service/gateway.go b/bcs-services/bcs-bscp/cmd/cache-service/service/gateway.go index c70c4bd46a..c8748e9c7d 100644 --- a/bcs-services/bcs-bscp/cmd/cache-service/service/gateway.go +++ b/bcs-services/bcs-bscp/cmd/cache-service/service/gateway.go @@ -24,6 +24,7 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" "google.golang.org/grpc" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/credentials/insecure" "bscp.io/pkg/cc" "bscp.io/pkg/dal/bedis" @@ -85,7 +86,7 @@ func newCacheServiceMux() (*runtime.ServeMux, error) { tls := network.TLS if !tls.Enable() { // dial without ssl - opts = append(opts, grpc.WithInsecure()) + opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials())) } else { // dial with ssl. tlsC, err := tools.ClientTLSConfVerify(tls.InsecureSkipVerify, tls.CAFile, tls.CertFile, tls.KeyFile, diff --git a/bcs-services/bcs-bscp/cmd/config-server/service/credential_scope.go b/bcs-services/bcs-bscp/cmd/config-server/service/credential_scope.go index 5fc23b2d4f..f4521cfa37 100644 --- a/bcs-services/bcs-bscp/cmd/config-server/service/credential_scope.go +++ b/bcs-services/bcs-bscp/cmd/config-server/service/credential_scope.go @@ -69,17 +69,9 @@ func (s *Service) UpdateCredentialScope(ctx context.Context, req *pbcs.UpdateCre CredentialId: req.CredentialId, } - for _, add := range req.AddScope { - r.Created = append(r.Created, add) - } - - for _, updated := range req.AlterScope { - r.Updated = append(r.Updated, updated) - } - - for _, del := range req.DelId { - r.Deleted = append(r.Deleted, del) - } + r.Created = append(r.Created, req.AddScope...) + r.Updated = append(r.Updated, req.AlterScope...) + r.Deleted = append(r.Deleted, req.DelId...) _, err = s.client.DS.UpdateCredentialScopes(grpcKit.RpcCtx(), r) if err != nil { diff --git a/bcs-services/bcs-bscp/cmd/config-server/service/gateway.go b/bcs-services/bcs-bscp/cmd/config-server/service/gateway.go index 06c652ea59..705c0b5f0b 100644 --- a/bcs-services/bcs-bscp/cmd/config-server/service/gateway.go +++ b/bcs-services/bcs-bscp/cmd/config-server/service/gateway.go @@ -24,6 +24,7 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" "google.golang.org/grpc" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/credentials/insecure" "bscp.io/pkg/cc" "bscp.io/pkg/logs" @@ -79,7 +80,7 @@ func newConfigServerMux() (*runtime.ServeMux, error) { tls := network.TLS if !tls.Enable() { // dial without ssl - opts = append(opts, grpc.WithInsecure()) + opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials())) } else { // dial with ssl. tlsC, err := tools.ClientTLSConfVerify(tls.InsecureSkipVerify, tls.CAFile, tls.CertFile, tls.KeyFile, diff --git a/bcs-services/bcs-bscp/cmd/config-server/service/hook.go b/bcs-services/bcs-bscp/cmd/config-server/service/hook.go index c967da0055..1f82cc51fd 100644 --- a/bcs-services/bcs-bscp/cmd/config-server/service/hook.go +++ b/bcs-services/bcs-bscp/cmd/config-server/service/hook.go @@ -105,11 +105,11 @@ func (s *Service) ListHooks(ctx context.Context, req *pbcs.ListHooksReq) (*pbcs. } if !req.All { - if req.Start < 0 { + if req.Start == 0 { return nil, errors.New("start has to be greater than 0") } - if req.Limit < 0 { + if req.Limit == 0 { return nil, errors.New("limit has to be greater than 0") } diff --git a/bcs-services/bcs-bscp/cmd/config-server/service/hook_revision.go b/bcs-services/bcs-bscp/cmd/config-server/service/hook_revision.go index 862434a350..9d0479ce55 100644 --- a/bcs-services/bcs-bscp/cmd/config-server/service/hook_revision.go +++ b/bcs-services/bcs-bscp/cmd/config-server/service/hook_revision.go @@ -82,11 +82,11 @@ func (s *Service) ListHookRevisions(ctx context.Context, req *pbcs.ListHookRevis } if !req.All { - if req.Start < 0 { + if req.Start == 0 { return nil, errors.New("start has to be greater than 0") } - if req.Limit < 0 { + if req.Limit == 0 { return nil, errors.New("limit has to be greater than 0") } diff --git a/bcs-services/bcs-bscp/cmd/config-server/service/service.go b/bcs-services/bcs-bscp/cmd/config-server/service/service.go index 2dd6561b6d..41bd3fa950 100644 --- a/bcs-services/bcs-bscp/cmd/config-server/service/service.go +++ b/bcs-services/bcs-bscp/cmd/config-server/service/service.go @@ -32,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/credentials/insecure" ) // Service do all the data service's work @@ -89,7 +90,7 @@ func newClientSet(sd serviced.Discover, tls cc.TLSConfig) (*ClientSet, error) { if !tls.Enable() { // dial without ssl - opts = append(opts, grpc.WithInsecure()) + opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials())) } else { // dial with ssl. tlsC, err := tools.ClientTLSConfVerify(tls.InsecureSkipVerify, tls.CAFile, tls.CertFile, tls.KeyFile, diff --git a/bcs-services/bcs-bscp/cmd/data-service/db-migration/migrations/20230526152150_add_hook.go b/bcs-services/bcs-bscp/cmd/data-service/db-migration/migrations/20230526152150_add_hook.go index e6fa4709da..5bec709485 100644 --- a/bcs-services/bcs-bscp/cmd/data-service/db-migration/migrations/20230526152150_add_hook.go +++ b/bcs-services/bcs-bscp/cmd/data-service/db-migration/migrations/20230526152150_add_hook.go @@ -120,64 +120,6 @@ func mig20230526152150GormUp(tx *gorm.DB) error { // mig20230526152150GormDown for down migration func mig20230526152150GormDown(tx *gorm.DB) error { - // Hook 脚本 - type Hook struct { - ID uint `gorm:"type:bigint(1) unsigned not null;primaryKey;autoIncrement:false"` - - // Spec is specifics of the resource defined with user - Name string `gorm:"type:varchar(64) not null;uniqueIndex:idx_bizID_name,priority:2"` - Meme string `gorm:"type:varchar(64) not null"` - Type string `gorm:"type:varchar(64) not null"` - Tag string `gorm:"type:varchar(64) not null"` - - // Attachment is attachment info of the resource - BizID uint `gorm:"type:bigint(1) unsigned not null;uniqueIndex:idx_bizID_name,priority:1"` - - // Revision is revision info of the resource - Creator string `gorm:"type:varchar(64) not null"` - Reviser string `gorm:"type:varchar(64) not null"` - CreatedAt time.Time `gorm:"type:datetime(6) not null"` - UpdatedAt time.Time `gorm:"type:datetime(6) not null"` - } - - // HookRevision 脚本版本 - type HookRevision struct { - ID uint `gorm:"type:bigint(1) unsigned not null;primaryKey;autoIncrement:false"` - - // Spec is specifics of the resource defined with user - Name string `gorm:"type:varchar(64) not null;uniqueIndex:idx_bizID_revisionName,priority:2"` - Meme string `gorm:"type:varchar(64) not null"` - State string `gorm:"type:varchar(64) not null"` - Content string `gorm:"type:longtext"` - - // Attachment is attachment info of the resource - BizID uint `gorm:"type:bigint(1) unsigned not null"` - HookID uint `gorm:"type:bigint(1) unsigned not null;uniqueIndex:idx_bizID_revisionName,priority:1"` - - // Revision is revision info of the resource - Creator string `gorm:"type:varchar(64) not null"` - Reviser string `gorm:"type:varchar(64) not null"` - CreatedAt time.Time `gorm:"type:datetime(6) not null"` - UpdatedAt time.Time `gorm:"type:datetime(6) not null"` - } - - // ReleasedHook : 已随配置项版本发布的配置脚本 - type ReleasedHook struct { - ID uint `gorm:"type:bigint(1) unsigned not null;primaryKey;autoIncrement:false"` - APPID uint `gorm:"type:bigint(1) unsigned not null;uniqueIndex:idx_appID_releaseID_hookType,priority:1"` - ReleaseID uint `gorm:"type:bigint(1) unsigned not null;uniqueIndex:idx_appID_releaseID_hookType,priority:2"` - HookID uint `gorm:"type:bigint(1) unsigned not null"` - HookRevisionID uint `gorm:"type:bigint(1) unsigned not null"` - HookName string `gorm:"type:varchar(64) not null"` - HookRevisionName string `gorm:"type:varchar(64) not null"` - Content string `gorm:"type:longtext"` - ScriptType string `gorm:"type:varchar(64) not null"` - HookType string `gorm:"type:varchar(64) not null;uniqueIndex:idx_appID_releaseID_hookType,priority:3"` - BizID uint `gorm:"type:bigint(1) unsigned not null"` - Reviser string `gorm:"type:varchar(64) not null"` - UpdatedAt time.Time `gorm:"type:datetime(6) not null"` - } - // IDGenerators : ID生成器 type IDGenerators struct { ID uint `gorm:"type:bigint(1) unsigned not null;primaryKey"` diff --git a/bcs-services/bcs-bscp/cmd/data-service/db-migration/migrator/migrator.go b/bcs-services/bcs-bscp/cmd/data-service/db-migration/migrator/migrator.go index e21e489dbe..0b8d75f114 100644 --- a/bcs-services/bcs-bscp/cmd/data-service/db-migration/migrator/migrator.go +++ b/bcs-services/bcs-bscp/cmd/data-service/db-migration/migrator/migrator.go @@ -213,9 +213,9 @@ func (m *Migrator) MigrationStatus() error { mg := m.Migrations[v] if mg.done { - fmt.Println(fmt.Sprintf("Migration %s completed", mg.Name)) + fmt.Printf("Migration %s completed\n", mg.Name) } else { - fmt.Println(fmt.Sprintf("Migration %s pending", mg.Name)) + fmt.Printf("Migration %s pending\n", mg.Name) } } diff --git a/bcs-services/bcs-bscp/cmd/data-service/service/gateway.go b/bcs-services/bcs-bscp/cmd/data-service/service/gateway.go index 878cee95cd..42ad38196e 100644 --- a/bcs-services/bcs-bscp/cmd/data-service/service/gateway.go +++ b/bcs-services/bcs-bscp/cmd/data-service/service/gateway.go @@ -24,6 +24,7 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" "google.golang.org/grpc" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/credentials/insecure" "bscp.io/pkg/cc" "bscp.io/pkg/dal/dao" @@ -82,7 +83,7 @@ func newDataServiceMux() (*runtime.ServeMux, error) { tls := network.TLS if !tls.Enable() { // dial without ssl - opts = append(opts, grpc.WithInsecure()) + opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials())) } else { // dial with ssl. tlsC, err := tools.ClientTLSConfVerify(tls.InsecureSkipVerify, tls.CAFile, tls.CertFile, tls.KeyFile, diff --git a/bcs-services/bcs-bscp/cmd/feed-server/bll/eventc/types.go b/bcs-services/bcs-bscp/cmd/feed-server/bll/eventc/types.go index 91a41f8184..e15eae9a85 100644 --- a/bcs-services/bcs-bscp/cmd/feed-server/bll/eventc/types.go +++ b/bcs-services/bcs-bscp/cmd/feed-server/bll/eventc/types.go @@ -173,9 +173,7 @@ func (eq *eventQueue) popAll() []*types.EventMeta { defer eq.lock.Unlock() copied := make([]*types.EventMeta, len(eq.queue)) - for idx := range eq.queue { - copied[idx] = eq.queue[idx] - } + copy(copied, eq.queue) // reset the queue. eq.queue = make([]*types.EventMeta, 0) diff --git a/bcs-services/bcs-bscp/cmd/feed-server/bll/release/release.go b/bcs-services/bcs-bscp/cmd/feed-server/bll/release/release.go index 2c214a7a15..dda6f1b91d 100644 --- a/bcs-services/bcs-bscp/cmd/feed-server/bll/release/release.go +++ b/bcs-services/bcs-bscp/cmd/feed-server/bll/release/release.go @@ -77,6 +77,9 @@ func (rs *ReleasedService) ListAppLatestReleaseMeta(kt *kit.Kit, opts *types.App } pre, post, err := rs.cache.ReleasedHook.Get(kt, opts.BizID, releaseID) + if err != nil { + return nil, err + } uriDec := rs.provider.URIDecorator(opts.BizID) meta := &types.AppLatestReleaseMeta{ diff --git a/bcs-services/bcs-bscp/pkg/cc/load.go b/bcs-services/bcs-bscp/pkg/cc/load.go index 912ed7f004..8f845c6af4 100644 --- a/bcs-services/bcs-bscp/pkg/cc/load.go +++ b/bcs-services/bcs-bscp/pkg/cc/load.go @@ -15,7 +15,7 @@ package cc import ( "errors" "fmt" - "io/ioutil" + "os" "bscp.io/pkg/config" "github.com/spf13/viper" @@ -67,7 +67,7 @@ func mergeConfigFile(filenames []string) ([]byte, error) { masterConf := map[string]interface{}{} for _, filename := range filenames { - file, err := ioutil.ReadFile(filename) + file, err := os.ReadFile(filename) if err != nil { return nil, fmt.Errorf("load Setting from file: %s failed, err: %v", filename, err) } diff --git a/bcs-services/bcs-bscp/pkg/criteria/errf/code.go b/bcs-services/bcs-bscp/pkg/criteria/errf/code.go index 72353bc5b9..2636b6e1b6 100644 --- a/bcs-services/bcs-bscp/pkg/criteria/errf/code.go +++ b/bcs-services/bcs-bscp/pkg/criteria/errf/code.go @@ -50,9 +50,6 @@ const ( UnHealth int32 = 4000009 // ErrGroupAlreadyPublished means the group has already been published in specified app. ErrGroupAlreadyPublished int32 = 4000010 - - // endOfThisScope is a flag to show this scope's error code's end. - endOfThisScope int32 = 4089999 ) // Note: Sidecar related error code scope, ranges at [4090000, 409999] diff --git a/bcs-services/bcs-bscp/pkg/criteria/errf/error.go b/bcs-services/bcs-bscp/pkg/criteria/errf/error.go index 2f62e5292d..03528e02d2 100644 --- a/bcs-services/bcs-bscp/pkg/criteria/errf/error.go +++ b/bcs-services/bcs-bscp/pkg/criteria/errf/error.go @@ -61,7 +61,7 @@ func New(code int32, message string) error { // Newf create an error with error code and formatted message. func Newf(code int32, format string, args ...interface{}) error { - return &ErrorF{Code: code, Message: fmt.Sprintf(format, args)} + return &ErrorF{Code: code, Message: fmt.Sprintf(format, args...)} } const grpcErrPrefix = "rpc error: code = Unknown desc = " diff --git a/bcs-services/bcs-bscp/pkg/criteria/uuid/uuid.go b/bcs-services/bcs-bscp/pkg/criteria/uuid/uuid.go index faa250b1c8..991212be9a 100644 --- a/bcs-services/bcs-bscp/pkg/criteria/uuid/uuid.go +++ b/bcs-services/bcs-bscp/pkg/criteria/uuid/uuid.go @@ -33,7 +33,7 @@ func UUID() string { // time interval is quick enough. // The UUID uses 100 ns increments, so it's short enough to actively // wait for a new value. - for uuid.Equal(lastUUID, result) == true { + for uuid.Equal(lastUUID, result) { result = uuid.NewUUID() } diff --git a/bcs-services/bcs-bscp/pkg/dal/dao/hook_revision.go b/bcs-services/bcs-bscp/pkg/dal/dao/hook_revision.go index 61cfbbcb96..ed49552fbf 100644 --- a/bcs-services/bcs-bscp/pkg/dal/dao/hook_revision.go +++ b/bcs-services/bcs-bscp/pkg/dal/dao/hook_revision.go @@ -185,7 +185,7 @@ func (dao *hookRevisionDao) List(kit *kit.Kit, q = q.Where(m.State.Eq(opt.State.String())) } - result := make([]*table.HookRevision, 0) + var result []*table.HookRevision var count int64 var err error diff --git a/bcs-services/bcs-bscp/pkg/dal/sharding/one.go b/bcs-services/bcs-bscp/pkg/dal/sharding/one.go index 26bb47a975..5532cddf66 100644 --- a/bcs-services/bcs-bscp/pkg/dal/sharding/one.go +++ b/bcs-services/bcs-bscp/pkg/dal/sharding/one.go @@ -128,8 +128,8 @@ func (o *One) AutoTxn(kit *kit.Kit, run TxnFunc) error { // if the operation need to retry, retry for at most 3 times, each wait for 50~500ms for retryCount := 1; retryCount <= 3; retryCount++ { logs.Warnf("retry transaction, retry count: %d, rid: %s", retryCount, kit.Rid) - rand.Seed(time.Now().UnixNano()) - time.Sleep(time.Millisecond * time.Duration(rand.Intn(450)+50)) + r := rand.New(rand.NewSource(time.Now().UnixNano())) + time.Sleep(time.Millisecond * time.Duration(r.Intn(450)+50)) retry, err = o.autoTxn(kit, run) if err != nil { diff --git a/bcs-services/bcs-bscp/pkg/dal/table/table.go b/bcs-services/bcs-bscp/pkg/dal/table/table.go index c3a607188c..729ce82e08 100644 --- a/bcs-services/bcs-bscp/pkg/dal/table/table.go +++ b/bcs-services/bcs-bscp/pkg/dal/table/table.go @@ -48,9 +48,7 @@ type Columns struct { // Columns returns all the db columns func (col Columns) Columns() []string { copied := make([]string, len(col.columns)) - for idx := range col.columns { - copied[idx] = col.columns[idx] - } + copy(copied, col.columns) return copied } @@ -285,8 +283,6 @@ func (r Revision) IsEmpty() bool { return true } -const lagSeconds = 5 * 60 - // ValidateCreate validate revision when created // no need to validate time here, because the time is injected by gorm automatically func (r Revision) ValidateCreate() error { diff --git a/bcs-services/bcs-bscp/pkg/logs/logger.go b/bcs-services/bcs-bscp/pkg/logs/logger.go index 5f48c92bce..b11b2b368a 100644 --- a/bcs-services/bcs-bscp/pkg/logs/logger.go +++ b/bcs-services/bcs-bscp/pkg/logs/logger.go @@ -24,7 +24,6 @@ import ( type logPrefix string const ( - etcdPrefix logPrefix = "[etcd] " redisPrefix logPrefix = "[redis] " grpcPrefix logPrefix = "[grpc] " ) diff --git a/bcs-services/bcs-bscp/pkg/logs/logs.go b/bcs-services/bcs-bscp/pkg/logs/logs.go index dd3b0b8801..e8cc1f352b 100644 --- a/bcs-services/bcs-bscp/pkg/logs/logs.go +++ b/bcs-services/bcs-bscp/pkg/logs/logs.go @@ -23,7 +23,6 @@ import ( "bscp.io/pkg/version" "github.com/go-redis/redis/v8" - etcd3 "go.etcd.io/etcd/client/v3" "google.golang.org/grpc/grpclog" ) @@ -84,16 +83,16 @@ func InitLogger(logConfig LogConfig) { // access other service log. redis.SetLogger(newLogger(redisPrefix)) - etcd3.SetLogger(newLogger(etcdPrefix)) grpclog.SetLoggerV2(newLogger(grpcPrefix)) // The default glog flush interval is 5 seconds, which is frighteningly long. go func() { d := time.Duration(5 * time.Second) - tick := time.Tick(d) + ticker := time.NewTicker(d) + defer ticker.Stop() for { - <-tick + <-ticker.C glog.Flush() } }() diff --git a/bcs-services/bcs-bscp/pkg/protocol/cache-service/helper.go b/bcs-services/bcs-bscp/pkg/protocol/cache-service/helper.go index 52ec9c0ab1..66a231b3dc 100644 --- a/bcs-services/bcs-bscp/pkg/protocol/cache-service/helper.go +++ b/bcs-services/bcs-bscp/pkg/protocol/cache-service/helper.go @@ -17,7 +17,7 @@ import ( ) // Validate BenchAppMetaReq. -func (m BenchAppMetaReq) Validate() error { +func (m *BenchAppMetaReq) Validate() error { if m.BizId == 0 { return errf.New(errf.InvalidParameter, "invalid biz_id, biz_id should > 0") } @@ -30,7 +30,7 @@ func (m BenchAppMetaReq) Validate() error { } // Validate BenchReleasedCIReq. -func (m BenchReleasedCIReq) Validate() error { +func (m *BenchReleasedCIReq) Validate() error { if m.BizId == 0 { return errf.New(errf.InvalidParameter, "invalid biz_id, biz_id should > 0") } diff --git a/bcs-services/bcs-bscp/pkg/protocol/core/content/convert.go b/bcs-services/bcs-bscp/pkg/protocol/core/content/convert.go index 691246f380..e92ea6eba8 100644 --- a/bcs-services/bcs-bscp/pkg/protocol/core/content/convert.go +++ b/bcs-services/bcs-bscp/pkg/protocol/core/content/convert.go @@ -99,7 +99,7 @@ func PbContent(c *table.Content) *Content { } // MarshalJSONPB ContentSpec to json. -func (m ContentSpec) MarshalJSONPB(mars *jsonpb.Marshaler) ([]byte, error) { +func (m *ContentSpec) MarshalJSONPB(mars *jsonpb.Marshaler) ([]byte, error) { return jsoni.Marshal(m) } diff --git a/bcs-services/bcs-bscp/pkg/rest/request.go b/bcs-services/bcs-bscp/pkg/rest/request.go index 7043b6e57b..478feb54f8 100644 --- a/bcs-services/bcs-bscp/pkg/rest/request.go +++ b/bcs-services/bcs-bscp/pkg/rest/request.go @@ -18,7 +18,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net" "net/http" "net/url" @@ -179,13 +178,10 @@ func (r *Request) Body(body interface{}) *Request { r.body = []byte("") return r } - break case reflect.String: r.body = []byte(body.(string)) return r - case reflect.Struct: - break default: r.err = errors.New("body should be one of interface, map, pointer or slice value") @@ -349,7 +345,7 @@ func (r *Request) Do() *Result { } if r.ctx != nil { - req.WithContext(r.ctx) + req = req.WithContext(r.ctx) } req.Header = cloneHeader(r.headers) @@ -401,7 +397,7 @@ func (r *Request) Do() *Result { var body []byte if resp.Body != nil { - data, err := ioutil.ReadAll(resp.Body) + data, err := io.ReadAll(resp.Body) if err != nil { if err == io.ErrUnexpectedEOF { // retry now @@ -464,7 +460,7 @@ func ridFromContext(ctx context.Context) string { } rid := ctx.Value(constant.RidKey) ridValue, ok := rid.(string) - if ok == true { + if ok { return ridValue } return "" diff --git a/bcs-services/bcs-bscp/pkg/rest/response.go b/bcs-services/bcs-bscp/pkg/rest/response.go index ec5c847d8a..88e72e9cf5 100644 --- a/bcs-services/bcs-bscp/pkg/rest/response.go +++ b/bcs-services/bcs-bscp/pkg/rest/response.go @@ -98,13 +98,11 @@ func WriteResp(w http.ResponseWriter, resp interface{}) { return } - _, err = fmt.Fprintf(w, string(bytes)) + _, err = fmt.Fprint(w, string(bytes)) if err != nil { logs.ErrorDepthf(1, "write resp to ResponseWriter failed, err: %v", err) return } - - return } // OKResponse is a http standard response diff --git a/bcs-services/bcs-bscp/pkg/runtime/brpc/pool.go b/bcs-services/bcs-bscp/pkg/runtime/brpc/pool.go index 8ec9a29d60..a14abac37c 100644 --- a/bcs-services/bcs-bscp/pkg/runtime/brpc/pool.go +++ b/bcs-services/bcs-bscp/pkg/runtime/brpc/pool.go @@ -22,6 +22,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/keepalive" ) @@ -96,7 +97,7 @@ func newOneClient(opt PoolOption) (interface{}, error) { if !opt.TLS.Enable() { // dial without ssl - opts = append(opts, grpc.WithInsecure()) + opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials())) } else { // dial with ssl. tlsC, err := tools.ClientTLSConfVerify(tls.InsecureSkipVerify, tls.CAFile, tls.CertFile, tls.KeyFile, diff --git a/bcs-services/bcs-bscp/pkg/runtime/ctl/ctl.go b/bcs-services/bcs-bscp/pkg/runtime/ctl/ctl.go index 086909bf65..bb0643d220 100644 --- a/bcs-services/bcs-bscp/pkg/runtime/ctl/ctl.go +++ b/bcs-services/bcs-bscp/pkg/runtime/ctl/ctl.go @@ -17,7 +17,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net/http" "bscp.io/pkg/criteria/constant" @@ -108,7 +108,7 @@ func (b *Ctl) httpHandler(w http.ResponseWriter, req *http.Request) { rawParams[key] = json.RawMessage(value[0]) } } else { - body, err := ioutil.ReadAll(req.Body) + body, err := io.ReadAll(req.Body) if err != nil { rest.WriteResp(w, rest.NewBaseResp(errf.InvalidParameter, "read body failed, err: "+err.Error())) return @@ -156,5 +156,4 @@ func (b *Ctl) httpHandler(w http.ResponseWriter, req *http.Request) { } rest.WriteResp(w, &rest.Response{Code: errf.OK, Data: data}) - return } diff --git a/bcs-services/bcs-bscp/pkg/runtime/handler/handler.go b/bcs-services/bcs-bscp/pkg/runtime/handler/handler.go index 4e2e894086..8f05e20f03 100644 --- a/bcs-services/bcs-bscp/pkg/runtime/handler/handler.go +++ b/bcs-services/bcs-bscp/pkg/runtime/handler/handler.go @@ -17,7 +17,7 @@ import ( "bytes" "context" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httputil" _ "net/http/pprof" // nolint @@ -195,7 +195,7 @@ func RequestBodyLogger(ignorePattern ...string) func(http.Handler) http.Handler buf := bytes.NewBuffer(nil) ww.Tee(buf) - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { render.Render(w, r, rest.BadRequest(err)) return @@ -212,7 +212,7 @@ func RequestBodyLogger(ignorePattern ...string) func(http.Handler) http.Handler ) }() - r.Body = ioutil.NopCloser(bytes.NewBuffer(body)) + r.Body = io.NopCloser(bytes.NewBuffer(body)) next.ServeHTTP(ww, r) } diff --git a/bcs-services/bcs-bscp/pkg/runtime/selector/operator.go b/bcs-services/bcs-bscp/pkg/runtime/selector/operator.go index e376f196a2..981c0f2fbf 100644 --- a/bcs-services/bcs-bscp/pkg/runtime/selector/operator.go +++ b/bcs-services/bcs-bscp/pkg/runtime/selector/operator.go @@ -186,7 +186,7 @@ func (gt *GreaterThanType) Match(match *Element, labels map[string]string) (bool return false, nil } - to, err := strconv.ParseFloat(compare, 10) + to, err := strconv.ParseFloat(compare, 32) if err != nil { return false, fmt.Errorf("parse gt oper's target label value: %s to float failed, err: %v", compare, err) } @@ -225,7 +225,7 @@ func (ge *GreaterThanEqualType) Match(match *Element, with map[string]string) (b return false, nil } - to, err := strconv.ParseFloat(compare, 10) + to, err := strconv.ParseFloat(compare, 32) if err != nil { return false, fmt.Errorf("parse ge oper's target label value: %s to float failed, err: %v", compare, err) } @@ -264,7 +264,7 @@ func (lt *LessThanType) Match(match *Element, labels map[string]string) (bool, e return false, nil } - to, err := strconv.ParseFloat(compare, 10) + to, err := strconv.ParseFloat(compare, 32) if err != nil { return false, fmt.Errorf("parse lt oper's target label value: %s to float failed, err: %v", compare, err) } diff --git a/bcs-services/bcs-bscp/pkg/serviced/serviced.go b/bcs-services/bcs-bscp/pkg/serviced/serviced.go index 8680ba04aa..6b5e58b023 100644 --- a/bcs-services/bcs-bscp/pkg/serviced/serviced.go +++ b/bcs-services/bcs-bscp/pkg/serviced/serviced.go @@ -17,7 +17,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net" "net/http" "strconv" @@ -336,7 +336,7 @@ func (s *serviced) Healthz() error { return fmt.Errorf("response status: %d", resp.StatusCode) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("read etcd healthz body failed, err: %v", err) } diff --git a/bcs-services/bcs-bscp/pkg/sf-share/types.go b/bcs-services/bcs-bscp/pkg/sf-share/types.go index 09e4e4f837..3433a088d3 100644 --- a/bcs-services/bcs-bscp/pkg/sf-share/types.go +++ b/bcs-services/bcs-bscp/pkg/sf-share/types.go @@ -16,7 +16,7 @@ import ( "encoding/base64" "errors" "fmt" - "io/ioutil" + "os" "strings" "bscp.io/pkg/cc" @@ -314,17 +314,17 @@ func LoadTLSBytes(tls cc.Repository) (*TLSBytes, error) { return new(TLSBytes), nil } - ca, err := ioutil.ReadFile(tls.BkRepo.TLS.CAFile) + ca, err := os.ReadFile(tls.BkRepo.TLS.CAFile) if err != nil { return nil, err } - cert, err := ioutil.ReadFile(tls.BkRepo.TLS.CertFile) + cert, err := os.ReadFile(tls.BkRepo.TLS.CertFile) if err != nil { return nil, err } - key, err := ioutil.ReadFile(tls.BkRepo.TLS.KeyFile) + key, err := os.ReadFile(tls.BkRepo.TLS.KeyFile) if err != nil { return nil, err } diff --git a/bcs-services/bcs-bscp/pkg/tools/algorithm.go b/bcs-services/bcs-bscp/pkg/tools/algorithm.go index 9d581a19e1..518a217470 100644 --- a/bcs-services/bcs-bscp/pkg/tools/algorithm.go +++ b/bcs-services/bcs-bscp/pkg/tools/algorithm.go @@ -19,6 +19,7 @@ import ( "encoding/base64" "fmt" "math/rand" + "time" ) var ( @@ -70,8 +71,9 @@ var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345 // randStr 随机生成字符串 func randStr(n int) string { b := make([]rune, n) + r := rand.New(rand.NewSource(time.Now().UnixNano())) for i := range b { - b[i] = letters[rand.Intn(len(letters))] + b[i] = letters[r.Intn(len(letters))] } return string(b) } diff --git a/bcs-services/bcs-bscp/pkg/tools/random.go b/bcs-services/bcs-bscp/pkg/tools/random.go index 1231d70e2e..ee6d24aa75 100644 --- a/bcs-services/bcs-bscp/pkg/tools/random.go +++ b/bcs-services/bcs-bscp/pkg/tools/random.go @@ -20,19 +20,19 @@ import ( // RandomRange return a random value which is between the value of between[0] and between[1]. // so, do assure that between[0] < between[1]. func RandomRange(between [2]int) int { - rand.Seed(time.Now().UnixNano()) - return rand.Intn(between[1]-between[0]) + between[0] + r := rand.New(rand.NewSource(time.Now().UnixNano())) + return r.Intn(between[1]-between[0]) + between[0] } var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") // RandString randomly generate a string of specified length. func RandString(n int) string { - rand.Seed(time.Now().UnixNano()) + r := rand.New(rand.NewSource(time.Now().UnixNano())) b := make([]rune, n) for i := range b { - b[i] = letterRunes[rand.Intn(len(letterRunes))] + b[i] = letterRunes[r.Intn(len(letterRunes))] } return string(b) diff --git a/bcs-services/bcs-bscp/pkg/tools/retry.go b/bcs-services/bcs-bscp/pkg/tools/retry.go index be2ab02e61..035dba4826 100644 --- a/bcs-services/bcs-bscp/pkg/tools/retry.go +++ b/bcs-services/bcs-bscp/pkg/tools/retry.go @@ -79,8 +79,8 @@ func (r *RetryPolicy) Sleep() { } // no matter retry how many times, sleep a const time and with an extra rand time. - rand.Seed(time.Now().UnixNano()) - randTime := rand.Intn(int(r.rangeMillSeconds[1])-int(r.rangeMillSeconds[0])) + int(r.rangeMillSeconds[0]) + rd := rand.New(rand.NewSource(time.Now().UnixNano())) + randTime := rd.Intn(int(r.rangeMillSeconds[1])-int(r.rangeMillSeconds[0])) + int(r.rangeMillSeconds[0]) duration := r.rangeMillSeconds[0] + uint(randTime) time.Sleep(time.Duration(duration) * time.Millisecond) return diff --git a/bcs-services/bcs-bscp/pkg/tools/ssl.go b/bcs-services/bcs-bscp/pkg/tools/ssl.go index 4b5b84ddf2..65f10fd1ec 100644 --- a/bcs-services/bcs-bscp/pkg/tools/ssl.go +++ b/bcs-services/bcs-bscp/pkg/tools/ssl.go @@ -17,7 +17,7 @@ import ( "crypto/x509" "encoding/pem" "fmt" - "io/ioutil" + "os" ) // TLSConfig is inner tls config. @@ -86,7 +86,7 @@ func ServerTLSConfVerify(caFile, certFile, keyFile, passwd string) (*tls.Config, } func loadCa(caFile string) (*x509.CertPool, error) { - ca, err := ioutil.ReadFile(caFile) + ca, err := os.ReadFile(caFile) if err != nil { return nil, err } @@ -100,7 +100,7 @@ func loadCa(caFile string) (*x509.CertPool, error) { } func loadCertificates(certFile, keyFile, passwd string) (*tls.Certificate, error) { - priKey, err := ioutil.ReadFile(keyFile) + priKey, err := os.ReadFile(keyFile) if err != nil { return nil, err } @@ -122,7 +122,7 @@ func loadCertificates(certFile, keyFile, passwd string) (*tls.Certificate, error }) } - certData, err := ioutil.ReadFile(certFile) + certData, err := os.ReadFile(certFile) if err != nil { return nil, err } diff --git a/bcs-services/bcs-bscp/pkg/types/group.go b/bcs-services/bcs-bscp/pkg/types/group.go index cebb6bb987..5f6ed36a2a 100644 --- a/bcs-services/bcs-bscp/pkg/types/group.go +++ b/bcs-services/bcs-bscp/pkg/types/group.go @@ -70,19 +70,19 @@ type ListGroupRleasesdAppsOption struct { // Validate the list group's published apps options func (opt *ListGroupRleasesdAppsOption) Validate() error { - if opt.BizID <= 0 { + if opt.BizID == 0 { return errf.New(errf.InvalidParameter, "invalid biz id, should >= 1") } - if opt.GroupID <= 0 { + if opt.GroupID == 0 { return errf.New(errf.InvalidParameter, "invalid group id, should >= 1") } - if opt.Start < 0 { + if opt.Start == 0 { return errf.New(errf.InvalidParameter, "invalid start, should >= 0") } - if opt.Limit <= 0 { + if opt.Limit == 0 { return errf.New(errf.InvalidParameter, "invalid limit, should >= 1") } return nil diff --git a/bcs-services/bcs-bscp/pkg/types/page.go b/bcs-services/bcs-bscp/pkg/types/page.go index 30377a412b..811637c1ca 100644 --- a/bcs-services/bcs-bscp/pkg/types/page.go +++ b/bcs-services/bcs-bscp/pkg/types/page.go @@ -175,16 +175,12 @@ func (bp BasePage) Validate(opt ...*PageOption) (err error) { } } - if enableUnlimited { - // allow the unlimited query, then valid this. - if bp.Start < 0 || bp.Limit < 0 { - return errors.New("page.start >= 0, page.limit value should >= 0") - } - } else { + if !enableUnlimited { + // not allow the unlimited query, then valid this. // if the user is not allowed to query with unlimited limit, then // 1. limit should >=1 // 2. validate whether the limit is larger than the max limit value - if bp.Limit <= 0 { + if bp.Limit == 0 { return errors.New("page.limit value should >= 1") } diff --git a/bcs-services/bcs-bscp/test/benchmark/case/cache-service/cs_test.go b/bcs-services/bcs-bscp/test/benchmark/case/cache-service/cs_test.go index 433b2a1ffb..82a83d0a10 100644 --- a/bcs-services/bcs-bscp/test/benchmark/case/cache-service/cs_test.go +++ b/bcs-services/bcs-bscp/test/benchmark/case/cache-service/cs_test.go @@ -22,6 +22,7 @@ import ( "testing" "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" pbcs "bscp.io/pkg/protocol/cache-service" "bscp.io/test/benchmark/run" @@ -91,7 +92,8 @@ func init() { // build cache service conn pool. csPool.conn = make([]pbcs.CacheClient, conSize) opts := make([]grpc.DialOption, 0) - opts = append(opts, grpc.WithInsecure(), grpc.WithWriteBufferSize(16*1024*1024), + opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()), + grpc.WithWriteBufferSize(16*1024*1024), grpc.WithReadBufferSize(32*1024*1024), grpc.WithInitialConnWindowSize(32*1024*1024)) for i := 0; i < conSize; i++ { conn, err := grpc.Dial(host, opts...) diff --git a/bcs-services/bcs-bscp/test/benchmark/case/feed-server/fs_http_test.go b/bcs-services/bcs-bscp/test/benchmark/case/feed-server/fs_http_test.go index 2ed5c4d556..bd135bf825 100644 --- a/bcs-services/bcs-bscp/test/benchmark/case/feed-server/fs_http_test.go +++ b/bcs-services/bcs-bscp/test/benchmark/case/feed-server/fs_http_test.go @@ -553,7 +553,7 @@ func TestScene11(t *testing.T) { // TestScene12 在基础数据下,1000个应用随机匹配Namespace策略 func TestScene12(t *testing.T) { - rand.Seed(time.Now().UnixNano()) + r := rand.New(rand.NewSource(time.Now().UnixNano())) list, err := getQueryReleaseMeta() if err != nil { @@ -563,7 +563,7 @@ func TestScene12(t *testing.T) { if debug { // random debug an application. - meta := list[rand.Intn(appRandomNum)] + meta := list[r.Intn(appRandomNum)] req := &types.ListFileAppLatestReleaseMetaReq{ BizId: meta.BizID, @@ -583,7 +583,7 @@ func TestScene12(t *testing.T) { } m := run.FireLoadTest(func() error { - meta := list[rand.Intn(appRandomNum)] + meta := list[r.Intn(appRandomNum)] req := &types.ListFileAppLatestReleaseMetaReq{ BizId: meta.BizID, AppId: meta.AppID, @@ -609,7 +609,7 @@ func TestScene12(t *testing.T) { // TestScene13 在基础数据下,1000个应用随机匹配Namespace策略,压测地址是代理 FeedServer 的 ApiGateway。 func TestScene13(t *testing.T) { - rand.Seed(time.Now().UnixNano()) + r := rand.New(rand.NewSource(time.Now().UnixNano())) list, err := getQueryReleaseMeta() if err != nil { @@ -625,7 +625,7 @@ func TestScene13(t *testing.T) { if debug { // random debug an application. - meta := list[rand.Intn(appRandomNum)] + meta := list[r.Intn(appRandomNum)] req := &types.ListFileAppLatestReleaseMetaReq{ BizId: meta.BizID, @@ -645,7 +645,7 @@ func TestScene13(t *testing.T) { } m := run.FireLoadTest(func() error { - meta := list[rand.Intn(appRandomNum)] + meta := list[r.Intn(appRandomNum)] req := &types.ListFileAppLatestReleaseMetaReq{ BizId: meta.BizID, AppId: meta.AppID, diff --git a/bcs-services/bcs-bscp/test/client/cache/cache.go b/bcs-services/bcs-bscp/test/client/cache/cache.go index feeb7544f4..86f0b9882c 100644 --- a/bcs-services/bcs-bscp/test/client/cache/cache.go +++ b/bcs-services/bcs-bscp/test/client/cache/cache.go @@ -22,6 +22,7 @@ import ( "bscp.io/pkg/types" "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" ) // Client cache service client @@ -31,7 +32,7 @@ type Client struct { // NewCacheClient get a new cache client func NewCacheClient(host string) (*Client, error) { - conn, err := grpc.Dial(host, grpc.WithInsecure()) + conn, err := grpc.Dial(host, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { return nil, err } diff --git a/bcs-services/bcs-bscp/test/mock/repo/app/config.go b/bcs-services/bcs-bscp/test/mock/repo/app/config.go index 76969640d8..75f56a81a1 100644 --- a/bcs-services/bcs-bscp/test/mock/repo/app/config.go +++ b/bcs-services/bcs-bscp/test/mock/repo/app/config.go @@ -15,8 +15,8 @@ package app import ( "errors" "fmt" - "io/ioutil" "net" + "os" "bscp.io/pkg/cc" @@ -175,7 +175,7 @@ func LoadSettings(sys *cc.SysOption) (*Setting, error) { } // configure file is configured, then load configuration from file. - file, err := ioutil.ReadFile(sys.ConfigFiles[0]) + file, err := os.ReadFile(sys.ConfigFiles[0]) if err != nil { return nil, fmt.Errorf("load setting from file: %s failed, err: %v", sys.ConfigFiles[0], err) } diff --git a/bcs-services/bcs-bscp/test/mock/repo/service/node.go b/bcs-services/bcs-bscp/test/mock/repo/service/node.go index f4f812d5ab..a6c095972a 100644 --- a/bcs-services/bcs-bscp/test/mock/repo/service/node.go +++ b/bcs-services/bcs-bscp/test/mock/repo/service/node.go @@ -16,7 +16,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "os" "path/filepath" @@ -64,7 +63,7 @@ func (s *Service) queryMetadataInfo(w http.ResponseWriter, r *http.Request) { } defer file.Close() - bytes, err := ioutil.ReadAll(file) + bytes, err := io.ReadAll(file) if len(bytes) == 0 || err != nil { resp.WriteResp(w, make(map[string]interface{}, 0)) return @@ -154,7 +153,7 @@ func (s *Service) uploadNode(w http.ResponseWriter, r *http.Request) { return } - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) if err != nil { resp.Err(w, fmt.Errorf("read body failed, err: %v", err)) return @@ -325,7 +324,7 @@ func (s *Service) downloadAll(w http.ResponseWriter, path string) error { } defer file.Close() - bytes, err := ioutil.ReadAll(file) + bytes, err := io.ReadAll(file) if err != nil { return fmt.Errorf("read node failed, err: %v", err) } @@ -341,7 +340,7 @@ func (s *Service) recordNodeDetail(path, sign, metadata string) error { } defer readFile.Close() - bytes, err := ioutil.ReadAll(readFile) + bytes, err := io.ReadAll(readFile) if err != nil { return fmt.Errorf("read node detail failed, err: %v", err) } diff --git a/bcs-services/bcs-bscp/test/mock/repo/service/types.go b/bcs-services/bcs-bscp/test/mock/repo/service/types.go index 8fcae868bb..48b49e7197 100644 --- a/bcs-services/bcs-bscp/test/mock/repo/service/types.go +++ b/bcs-services/bcs-bscp/test/mock/repo/service/types.go @@ -16,7 +16,6 @@ import ( "encoding/base64" "fmt" "io" - "io/ioutil" "net/http" "strconv" "strings" @@ -68,7 +67,7 @@ func (r *BaseResp) WriteResp(w http.ResponseWriter, data interface{}) { } func unmarshal(body io.ReadCloser, data interface{}) error { - bodyByte, err := ioutil.ReadAll(body) + bodyByte, err := io.ReadAll(body) if err != nil { return err } diff --git a/bcs-services/bcs-bscp/test/suite/cases/helper.go b/bcs-services/bcs-bscp/test/suite/cases/helper.go index c9f763f500..b4418f9aae 100644 --- a/bcs-services/bcs-bscp/test/suite/cases/helper.go +++ b/bcs-services/bcs-bscp/test/suite/cases/helper.go @@ -47,9 +47,9 @@ func RandString(n int) string { str := strings.Builder{} length := len(chars) - rand.Seed(time.Now().UnixNano()) + r := rand.New(rand.NewSource(time.Now().UnixNano())) for i := 0; i < n; i++ { - str.WriteString(chars[rand.Intn(length)]) + str.WriteString(chars[r.Intn(length)]) } return str.String() diff --git a/bcs-services/bcs-bscp/test/suite/cases/sidecar/sidecar_test.go b/bcs-services/bcs-bscp/test/suite/cases/sidecar/sidecar_test.go index 491ffe6d02..61a4a9354d 100644 --- a/bcs-services/bcs-bscp/test/suite/cases/sidecar/sidecar_test.go +++ b/bcs-services/bcs-bscp/test/suite/cases/sidecar/sidecar_test.go @@ -14,7 +14,7 @@ package sidecar import ( "fmt" - "io/ioutil" + "io" "os/exec" "testing" "time" @@ -131,7 +131,7 @@ func startSidecar(cmdStr string) error { } // read exec stdout. - result, err := ioutil.ReadAll(stdout) + result, err := io.ReadAll(stdout) if err != nil { return err } diff --git a/bcs-services/bcs-bscp/test/suite/tools/statistics.go b/bcs-services/bcs-bscp/test/suite/tools/statistics.go index 4220420347..257afbe89d 100644 --- a/bcs-services/bcs-bscp/test/suite/tools/statistics.go +++ b/bcs-services/bcs-bscp/test/suite/tools/statistics.go @@ -15,7 +15,7 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" + "io" "log" "os" "regexp" @@ -90,7 +90,7 @@ func getResultFromFile(path string) ([]*Result, error) { return nil, err } defer file.Close() - bytes, err := ioutil.ReadAll(file) + bytes, err := io.ReadAll(file) if err != nil { return nil, err } diff --git a/bcs-services/bcs-bscp/test/suite/tools/tool.go b/bcs-services/bcs-bscp/test/suite/tools/tool.go index 55923a9ade..ae22d2e338 100644 --- a/bcs-services/bcs-bscp/test/suite/tools/tool.go +++ b/bcs-services/bcs-bscp/test/suite/tools/tool.go @@ -15,7 +15,6 @@ package main import ( "bufio" "flag" - "io/ioutil" "log" "os" ) @@ -33,7 +32,7 @@ func main() { "file that by go convey test result, save file path") flag.Parse() - files, err := ioutil.ReadDir(inputDir) + files, err := os.ReadDir(inputDir) if err != nil { log.Fatalln(err) }