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-bscp/cmd/cache-service/app/app.go b/bcs-services/bcs-bscp/cmd/cache-service/app/app.go index 37fe6cbfd0..c81d0b3b2a 100644 --- a/bcs-services/bcs-bscp/cmd/cache-service/app/app.go +++ b/bcs-services/bcs-bscp/cmd/cache-service/app/app.go @@ -122,7 +122,7 @@ func (cs *cacheService) prepare(opt *options.Option) error { cs.bds = bds // initial DAO set - set, err := dao.NewDaoSet(cc.CacheService().Sharding, cc.CacheService().Credential) + set, err := dao.NewDaoSet(cc.CacheService().Sharding, cc.CacheService().Credential, cc.CacheService().Gorm) if err != nil { return fmt.Errorf("initial dao set failed, err: %v", err) } diff --git a/bcs-services/bcs-bscp/cmd/data-service/app/app.go b/bcs-services/bcs-bscp/cmd/data-service/app/app.go index 510a9f2848..ba346a9c27 100644 --- a/bcs-services/bcs-bscp/cmd/data-service/app/app.go +++ b/bcs-services/bcs-bscp/cmd/data-service/app/app.go @@ -135,7 +135,7 @@ func (ds *dataService) prepare(opt *options.Option) error { } // initial DAO set - set, err := dao.NewDaoSet(cc.DataService().Sharding, cc.DataService().Credential) + set, err := dao.NewDaoSet(cc.DataService().Sharding, cc.DataService().Credential, cc.DataService().Gorm) if err != nil { return fmt.Errorf("initial dao set failed, err: %v", err) } diff --git a/bcs-services/bcs-bscp/etc/bcs-bscp.yml b/bcs-services/bcs-bscp/etc/bcs-bscp.yml index 5d9483bc5b..1ae493c90c 100644 --- a/bcs-services/bcs-bscp/etc/bcs-bscp.yml +++ b/bcs-services/bcs-bscp/etc/bcs-bscp.yml @@ -56,6 +56,11 @@ redisCluster: password: db: 1 +# gorm related settings +gorm: + # 日志级别,支持silent、error、warn、info四种级别(不区分大小写),默认为info + logLevel: + downstream: bounceIntervalHour: 48 diff --git a/bcs-services/bcs-bscp/pkg/cc/service.go b/bcs-services/bcs-bscp/pkg/cc/service.go index dbd31bb008..24a0b21a55 100644 --- a/bcs-services/bcs-bscp/pkg/cc/service.go +++ b/bcs-services/bcs-bscp/pkg/cc/service.go @@ -196,6 +196,7 @@ type CacheServiceSetting struct { Credential Credential `yaml:"credential"` Sharding Sharding `yaml:"sharding"` RedisCluster RedisCluster `yaml:"redisCluster"` + Gorm Gorm `yaml:"gorm"` } // trySetFlagBindIP try set flag bind ip. @@ -215,6 +216,7 @@ func (s *CacheServiceSetting) trySetDefault() { s.Log.trySetDefault() s.Sharding.trySetDefault() s.RedisCluster.trySetDefault() + s.Gorm.trySetDefault() } // Validate CacheServiceSetting option. @@ -236,6 +238,10 @@ func (s CacheServiceSetting) Validate() error { return err } + if err := s.Gorm.validate(); err != nil { + return err + } + return nil } @@ -300,6 +306,7 @@ type DataServiceSetting struct { Repo Repository `yaml:"repository"` Vault Vault `yaml:"vault"` FeatureFlags FeatureFlags `yaml:"featureFlags"` + Gorm Gorm `yaml:"gorm"` } // trySetFlagBindIP try set flag bind ip. @@ -321,6 +328,7 @@ func (s *DataServiceSetting) trySetDefault() { s.Repo.trySetDefault() s.Vault.getConfigFromEnv() s.FeatureFlags.trySetDefault() + s.Gorm.trySetDefault() } // Validate DataServiceSetting option. @@ -354,6 +362,10 @@ func (s DataServiceSetting) Validate() error { return err } + if err := s.Gorm.validate(); err != nil { + return err + } + return nil } @@ -535,7 +547,7 @@ func (s *VaultServerSetting) trySetFlagPort(port, grpcPort int) error { return s.Network.trySetFlagPort(port, grpcPort) } -// trySetDefault set the CacheServiceSetting default value if user not configured. +// trySetDefault set the VaultServerSetting default value if user not configured. func (s *VaultServerSetting) trySetDefault() { s.Network.trySetDefault() s.Service.trySetDefault() @@ -543,7 +555,7 @@ func (s *VaultServerSetting) trySetDefault() { s.Sharding.trySetDefault() } -// Validate CacheServiceSetting option. +// Validate VaultServerSetting option. func (s VaultServerSetting) Validate() error { if err := s.Network.validate(); err != nil { diff --git a/bcs-services/bcs-bscp/pkg/cc/types.go b/bcs-services/bcs-bscp/pkg/cc/types.go index 1e63181305..550c5f02b7 100644 --- a/bcs-services/bcs-bscp/pkg/cc/types.go +++ b/bcs-services/bcs-bscp/pkg/cc/types.go @@ -23,6 +23,7 @@ import ( "time" etcd3 "go.etcd.io/etcd/client/v3" + "gorm.io/gorm/logger" "github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/logs" "github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/tools" @@ -1388,3 +1389,58 @@ func (g GSE) validate() error { } return nil } + +// Gorm defines the grom related settings. +type Gorm struct { + LogLevel GormLogLevel `yaml:"logLevel"` +} + +// GormLogLevel is gorm log level type +type GormLogLevel string + +const ( + // GormLogSilent used for gorm log level + GormLogSilent GormLogLevel = "silent" + // GormLogError used for gorm log level + GormLogError GormLogLevel = "error" + // GormLogWarn used for gorm log level + GormLogWarn GormLogLevel = "warn" + // GormLogInfo used for gorm log level + GormLogInfo GormLogLevel = "info" +) + +// GetLogLevel get log level for gorm. +func (g Gorm) GetLogLevel() logger.LogLevel { + switch strings.ToLower(string(g.LogLevel)) { + case string(GormLogSilent): + return logger.Silent + case string(GormLogError): + return logger.Error + case string(GormLogWarn): + return logger.Warn + case string(GormLogInfo): + return logger.Info + default: + return logger.Info + } +} + +// validate if the gorm is valid or not. +func (g Gorm) validate() error { + switch strings.ToLower(string(g.LogLevel)) { + case string(GormLogSilent): + case string(GormLogError): + case string(GormLogWarn): + case string(GormLogInfo): + default: + return fmt.Errorf("unsopported log level: %s", g.LogLevel) + } + return nil +} + +// trySetDefault try set the default value of gorm +func (g *Gorm) trySetDefault() { + if g.LogLevel == "" { + g.LogLevel = GormLogInfo + } +} diff --git a/bcs-services/bcs-bscp/pkg/dal/dao/dao.go b/bcs-services/bcs-bscp/pkg/dal/dao/dao.go index bff6e54f9c..14aaa965b1 100644 --- a/bcs-services/bcs-bscp/pkg/dal/dao/dao.go +++ b/bcs-services/bcs-bscp/pkg/dal/dao/dao.go @@ -73,7 +73,7 @@ type Set interface { } // NewDaoSet create the DAO set instance. -func NewDaoSet(opt cc.Sharding, credentialSetting cc.Credential) (Set, error) { +func NewDaoSet(opt cc.Sharding, credentialSetting cc.Credential, gormSetting cc.Gorm) (Set, error) { // opt cc.Database sd, err := sharding.InitSharding(&opt) @@ -82,7 +82,7 @@ func NewDaoSet(opt cc.Sharding, credentialSetting cc.Credential) (Set, error) { } adminDB, err := gorm.Open(mysql.Open(sharding.URI(opt.AdminDatabase)), - &gorm.Config{Logger: logger.Default.LogMode(logger.Info)}) + &gorm.Config{Logger: logger.Default.LogMode(gormSetting.GetLogLevel())}) if err != nil { return nil, err } diff --git a/bcs-services/bcs-bscp/ui/src/api/group.ts b/bcs-services/bcs-bscp/ui/src/api/group.ts index 123bade19e..e3f943460a 100644 --- a/bcs-services/bcs-bscp/ui/src/api/group.ts +++ b/bcs-services/bcs-bscp/ui/src/api/group.ts @@ -50,7 +50,8 @@ export const getServiceGroupList = (biz_id: string, app_id: number) => * @param biz_id 空间ID * @returns */ -export const getSpaceGroupList = (biz_id: string) => http.get(`/config/biz/${biz_id}/groups`).then((res) => res.data); +export const getSpaceGroupList = (biz_id: string, topId?: number) => + http.get(`/config/biz/${biz_id}/groups`, { params: { top_ids: topId } }).then((res) => res.data); /** * 新增分组 diff --git a/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/config-selector.vue b/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/config-selector.vue index 5ea9ed423e..b3143cc949 100644 --- a/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/config-selector.vue +++ b/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/config-selector.vue @@ -9,7 +9,7 @@ :input-search="false" :clearable="false" :loading="loading" - :search-placeholder="$t('配置项名称')" + :search-placeholder="basicInfo?.serviceType.value === 'file' ? $t('配置文件名') : $t('配置项名称')" :no-data-text="$t('暂无可用配置')" :no-match-text="$t('搜索结果为空')" @change="handleConfigChange"> diff --git a/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/content/cmd-example.vue b/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/content/cmd-example.vue index a242f950bc..5b46887fad 100644 --- a/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/content/cmd-example.vue +++ b/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/content/cmd-example.vue @@ -7,7 +7,9 @@ :dual-system-support="true" :config-show="true" :config-label="basicInfo?.serviceType.value === 'file' ? '配置文件名' : '配置项名称'" - @update-option-data="getOptionData" /> + :selected-key-data="props.selectedKeyData" + @update-option-data="getOptionData" + @selected-key-data="emits('selected-key-data', $event)" />

{{ $t('配置指引与示例预览') }}

@@ -51,6 +53,7 @@ import { ref, Ref, computed, inject, onMounted, nextTick } from 'vue'; import { copyToClipBoard } from '../../../../../../utils/index'; import { IVariableEditParams } from '../../../../../../../types/variable'; + import { newICredentialItem } from '../../../../../../../types/client'; import BkMessage from 'bkui-vue/lib/message'; import FormOption from '../form-option.vue'; import CodePreview from '../code-preview.vue'; @@ -58,7 +61,13 @@ import { useI18n } from 'vue-i18n'; import { useRoute } from 'vue-router'; - const props = defineProps<{ contentScrollTop: Function; kvName: string }>(); + const props = defineProps<{ + contentScrollTop: Function; + kvName: string; + selectedKeyData: newICredentialItem['spec'] | null; + }>(); + + const emits = defineEmits(['selected-key-data']); const { t } = useI18n(); const route = useRoute(); diff --git a/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/content/container-example.vue b/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/content/container-example.vue index db42c547c0..806f52f787 100644 --- a/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/content/container-example.vue +++ b/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/content/container-example.vue @@ -4,7 +4,9 @@ ref="fileOptionRef" :p2p-show="true" :associate-config-show="true" - @update-option-data="getOptionData" /> + :selected-key-data="props.selectedKeyData" + @update-option-data="getOptionData" + @selected-key-data="emits('selected-key-data', $event)" />
{{ $t('示例预览') }} {{ $t('复制示例') }} @@ -26,12 +28,14 @@ import BkMessage from 'bkui-vue/lib/message'; import FormOption from '../form-option.vue'; import CodePreview from '../code-preview.vue'; - import { IExampleFormData } from '../../../../../../../types/client'; + import { IExampleFormData, newICredentialItem } from '../../../../../../../types/client'; import { useI18n } from 'vue-i18n'; import { useRoute } from 'vue-router'; import yamlString from '/src/assets/example-data/file-container.yaml?raw'; - const props = defineProps<{ contentScrollTop: Function }>(); + const props = defineProps<{ contentScrollTop: Function; selectedKeyData: newICredentialItem['spec'] | null }>(); + + const emits = defineEmits(['selected-key-data']); const { t } = useI18n(); const route = useRoute(); diff --git a/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/content/kv-example.vue b/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/content/kv-example.vue index a222d39485..bdba589fe9 100644 --- a/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/content/kv-example.vue +++ b/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/content/kv-example.vue @@ -5,7 +5,9 @@ :directory-show="false" :config-show="props.kvName === 'http' || (props.kvName === 'python' && activeTab === 0)" :config-label="basicInfo?.serviceType.value === 'file' ? '配置文件名' : '配置项名称'" - @update-option-data="(data) => getOptionData(data)" /> + :selected-key-data="props.selectedKeyData" + @update-option-data="(data) => getOptionData(data)" + @selected-key-data="emits('selected-key-data', $event)" />
{{ $t('示例预览') }} @@ -42,6 +44,7 @@ import { copyToClipBoard } from '../../../../../../utils/index'; import { CloseLine } from 'bkui-vue/lib/icon'; import { IVariableEditParams } from '../../../../../../../types/variable'; + import { newICredentialItem } from '../../../../../../../types/client'; import BkMessage from 'bkui-vue/lib/message'; import FormOption from '../form-option.vue'; import codePreview from '../code-preview.vue'; @@ -50,8 +53,11 @@ const props = defineProps<{ kvName: string; + selectedKeyData: newICredentialItem['spec'] | null; }>(); + const emits = defineEmits(['selected-key-data']); + const basicInfo = inject<{ serviceName: Ref; serviceType: Ref }>('basicInfo'); const { t } = useI18n(); const route = useRoute(); @@ -72,7 +78,6 @@ labelArr: [], labelArrType: '', // 展示格式 configName: '', // 配置项 - tempDir: '', // http临时目录路径(file) }); // 代码预览上方提示框 diff --git a/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/content/node-mana-example.vue b/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/content/node-mana-example.vue index 198dc78d6f..f6583e853a 100644 --- a/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/content/node-mana-example.vue +++ b/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/content/node-mana-example.vue @@ -5,7 +5,9 @@ :associate-config-show="true" :dual-system-support="true" :line-break-show="true" - @update-option-data="getOptionData" /> + :selected-key-data="props.selectedKeyData" + @update-option-data="getOptionData" + @selected-key-data="emits('selected-key-data', $event)" />
{{ $t('示例预览') }}
@@ -114,6 +116,7 @@ import { ref, Ref, inject } from 'vue'; import { useRoute } from 'vue-router'; import { Share, CopyShape } from 'bkui-vue/lib/icon'; + import { newICredentialItem } from '../../../../../../../types/client'; import { copyToClipBoard } from '../../../../../../utils/index'; import BkMessage from 'bkui-vue/lib/message'; import FormOption from '../form-option.vue'; @@ -124,6 +127,10 @@ value: String; } + const props = defineProps<{ selectedKeyData: newICredentialItem['spec'] | null }>(); + + const emits = defineEmits(['selected-key-data']); + const { t, locale } = useI18n(); const route = useRoute(); const basicInfo = inject<{ serviceName: Ref; serviceType: Ref }>('basicInfo'); diff --git a/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/form-option.vue b/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/form-option.vue index c546d932a4..237937bd29 100644 --- a/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/form-option.vue +++ b/bcs-services/bcs-bscp/ui/src/views/space/client/example/components/form-option.vue @@ -11,7 +11,11 @@ placement: 'top', }" /> - + @@ -27,10 +31,13 @@ - + Linux - +