diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index daba732baa..f10398439b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -18,7 +18,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.54.2 + version: v1.61.0 args: --timeout=30m working-directory: bcs-services/bcs-webconsole bcs-monitor: @@ -38,7 +38,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.54.2 + version: v1.61.0 args: --timeout=30m working-directory: bcs-services/bcs-monitor bcs-bscp: @@ -118,7 +118,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.54.2 + version: v1.61.0 args: --timeout=30m --out-format=colored-line-number working-directory: bcs-services/bcs-project-manager bcs-user-manager: @@ -139,7 +139,7 @@ jobs: uses: golangci/golangci-lint-action@v3 with: version: v1.54.2 - args: --timeout=30m + args: --timeout=30m --out-format=colored-line-number working-directory: bcs-services/bcs-user-manager bcs-cluster-resources: name: bcs-cluster-resources @@ -158,7 +158,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.54.2 + version: v1.61.0 args: --timeout=30m working-directory: bcs-services/cluster-resources @@ -179,7 +179,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.54.2 + version: v1.61.0 args: --timeout=30m working-directory: bcs-common/common/task - name: Test diff --git a/bcs-common/common/task/stores/iface/interfaces.go b/bcs-common/common/task/stores/iface/interfaces.go index 7983d9411e..d031d89207 100644 --- a/bcs-common/common/task/stores/iface/interfaces.go +++ b/bcs-common/common/task/stores/iface/interfaces.go @@ -30,8 +30,8 @@ type ListOption struct { CurrentStep string Status string Creator string - StartGte *time.Time // StartGte start time greater or equal to - StartLte *time.Time // StartLte start time less or equal to + CreatedGte *time.Time // CreatedGte create time greater or equal to + CreatedLte *time.Time // CreatedLte create time less or equal to Sort map[string]int // Sort map for sort list results Offset int64 // Offset offset for list results Limit int64 // Limit limit for list results diff --git a/bcs-common/common/task/stores/mysql/helper.go b/bcs-common/common/task/stores/mysql/helper.go index ce31769204..15ef315cc9 100644 --- a/bcs-common/common/task/stores/mysql/helper.go +++ b/bcs-common/common/task/stores/mysql/helper.go @@ -90,8 +90,9 @@ func toTask(task *TaskRecord, steps []*StepRecord) *types.Task { End: task.End, ExecutionTime: task.ExecutionTime, MaxExecutionSeconds: task.MaxExecutionSeconds, - Creator: task.Creator, + CreatedAt: task.CreatedAt, LastUpdate: task.UpdatedAt, + Creator: task.Creator, Updater: task.Updater, } diff --git a/bcs-common/common/task/stores/mysql/mysql.go b/bcs-common/common/task/stores/mysql/mysql.go index 8174472a6b..60259f6689 100644 --- a/bcs-common/common/task/stores/mysql/mysql.go +++ b/bcs-common/common/task/stores/mysql/mysql.go @@ -15,8 +15,6 @@ package mysql import ( "context" - "net/url" - "strconv" "gorm.io/driver/mysql" "gorm.io/gorm" @@ -27,19 +25,30 @@ import ( ) type mysqlStore struct { - dsn string - showDebug bool - db *gorm.DB + dsn string + debug bool + db *gorm.DB +} + +type option func(*mysqlStore) + +// WithDebug 是否显示sql语句 +func WithDebug(debug bool) option { + return func(s *mysqlStore) { + s.debug = debug + } } // New init mysql iface.Store -func New(dsn string) (iface.Store, error) { - store := &mysqlStore{dsn: dsn, showDebug: false} - store.initDsn(dsn) +func New(dsn string, opts ...option) (iface.Store, error) { + store := &mysqlStore{dsn: dsn, debug: false} + for _, opt := range opts { + opt(store) + } // 是否显示sql语句 level := logger.Warn - if store.showDebug { + if store.debug { level = logger.Info } @@ -54,29 +63,6 @@ func New(dsn string) (iface.Store, error) { return store, nil } -// initDsn 解析debug参数是否开启sql显示, 任意异常都原样不动 -func (s *mysqlStore) initDsn(raw string) { - u, err := url.Parse(raw) - if err != nil { - return - } - query := u.Query() - - // 是否开启debug - debugStr := query.Get("debug") - if debugStr != "" { - debug, err := strconv.ParseBool(debugStr) - if err != nil { - return - } - s.showDebug = debug - query.Del("debug") - u.RawQuery = query.Encode() - } - - s.dsn = u.String() -} - // EnsureTable implement istore EnsureTable interface func (s *mysqlStore) EnsureTable(ctx context.Context, dst ...any) error { // 没有自定义数据, 使用默认表结构 @@ -120,11 +106,11 @@ func (s *mysqlStore) ListTask(ctx context.Context, opt *iface.ListOption) (*ifac }) // mysql store 使用创建时间过滤 - if opt.StartGte != nil { - tx = tx.Where("created_at >= ?", opt.StartGte) + if opt.CreatedGte != nil { + tx = tx.Where("created_at >= ?", opt.CreatedGte) } - if opt.StartLte != nil { - tx = tx.Where("created_at <= ?", opt.StartLte) + if opt.CreatedLte != nil { + tx = tx.Where("created_at <= ?", opt.CreatedLte) } // 只使用id排序 diff --git a/bcs-common/common/task/types/type.go b/bcs-common/common/task/types/type.go index ce4a09b35e..40d707053a 100644 --- a/bcs-common/common/task/types/type.go +++ b/bcs-common/common/task/types/type.go @@ -72,6 +72,7 @@ type Task struct { Updater string `json:"updater"` Start time.Time `json:"start"` End time.Time `json:"end"` + CreatedAt time.Time `json:"createdAt"` LastUpdate time.Time `json:"lastUpdate"` } diff --git a/bcs-services/bcs-user-manager/app/app.go b/bcs-services/bcs-user-manager/app/app.go index dbc0e4e72b..734ec0d3c1 100644 --- a/bcs-services/bcs-user-manager/app/app.go +++ b/bcs-services/bcs-user-manager/app/app.go @@ -133,9 +133,9 @@ func parseConfig(op *options.UserManagerOptions) (*config.UserMgrConfig, error) // RedisDSN 没有配置,检查 RedisConfig if userMgrConfig.RedisDSN == "" { - redisConfig, err := parseRedisConfig(op.RedisConfig) + redisConfig, aErr := parseRedisConfig(op.RedisConfig) if err != nil { - return nil, fmt.Errorf("error parsing redis config and exit: %s", err.Error()) + return nil, fmt.Errorf("error parsing redis config and exit: %s", aErr.Error()) } userMgrConfig.RedisConfig = redisConfig }