提交 c490ab09 编写于 作者: N ning

fix: cli upgrade

上级 ac4ff33d
...@@ -18,9 +18,9 @@ func Upgrade(configFile string) error { ...@@ -18,9 +18,9 @@ func Upgrade(configFile string) error {
return err return err
} }
ctx := ctx.NewContext(context.Background(), db, false) ctx := ctx.NewContext(context.Background(), db, true)
for _, cluster := range config.Clusters { for _, cluster := range config.Clusters {
count, err := models.GetDatasourcesCountBy(ctx, "", "", cluster.Name) count, err := models.GetDatasourcesCountByName(ctx, cluster.Name)
if err != nil { if err != nil {
logger.Errorf("get datasource %s count error: %v", cluster.Name, err) logger.Errorf("get datasource %s count error: %v", cluster.Name, err)
continue continue
......
...@@ -848,6 +848,10 @@ func AlertRuleUpgradeToV6(ctx *ctx.Context, dsm map[string]Datasource) error { ...@@ -848,6 +848,10 @@ func AlertRuleUpgradeToV6(ctx *ctx.Context, dsm map[string]Datasource) error {
} }
lst[i].DatasourceIds = string(b) lst[i].DatasourceIds = string(b)
if lst[i].PromQl == "" {
continue
}
ruleConfig := PromRuleConfig{ ruleConfig := PromRuleConfig{
Queries: []PromQuery{ Queries: []PromQuery{
{ {
......
...@@ -153,6 +153,15 @@ func GetDatasourceIdsByEngineName(ctx *ctx.Context, engineName string) ([]int64, ...@@ -153,6 +153,15 @@ func GetDatasourceIdsByEngineName(ctx *ctx.Context, engineName string) ([]int64,
return ids, err return ids, err
} }
func GetDatasourcesCountByName(ctx *ctx.Context, name string) (int64, error) {
session := DB(ctx).Model(&Datasource{})
if name != "" {
session = session.Where("name = ?", name)
}
return Count(session)
}
func GetDatasourcesCountBy(ctx *ctx.Context, typ, cate, name string) (int64, error) { func GetDatasourcesCountBy(ctx *ctx.Context, typ, cate, name string) (int64, error) {
session := DB(ctx).Model(&Datasource{}) session := DB(ctx).Model(&Datasource{})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册