mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
Merge pull request #9061 from zhaoxiangchun/bugfix/zxc-nodata-master
fix(monitor): delete suggestConfig auto Initialized data
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis/monitor"
|
||||
@@ -58,7 +57,6 @@ serLoop:
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "NoDataQueryCondition NewEvalMatch error")
|
||||
}
|
||||
log.Errorf("nodata match:%#v", match)
|
||||
normalHostIds[val] = match
|
||||
continue serLoop
|
||||
}
|
||||
|
||||
@@ -761,7 +761,6 @@ func (alert *SCommonAlert) ValidateUpdateData(
|
||||
return data, errors.Wrap(err, "metric_query Unmarshal error")
|
||||
}
|
||||
scope, _ := data.GetString("scope")
|
||||
log.Errorf("update query from:%s", metricQuery.From)
|
||||
err = CommonAlertManager.ValidateMetricQuery(metricQuery, scope, userCred)
|
||||
if err != nil {
|
||||
return data, errors.Wrap(err, "metric query error")
|
||||
|
||||
@@ -379,6 +379,8 @@ func (self *SSuggestSysAlert) GetSuggestConfig(scope rbacutils.TRbacScope, domai
|
||||
q := SuggestSysRuleConfigManager.Query().Equals("type", drvType).Equals("resource_type", resType)
|
||||
if !batchIgnore {
|
||||
q = q.Equals("resource_id", resId)
|
||||
} else {
|
||||
q = q.IsNull("resource_id")
|
||||
}
|
||||
q = SuggestSysRuleConfigManager.FilterByScope(q, scope, scopeId)
|
||||
configs := make([]SSuggestSysRuleConfig, 0)
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
"yunion.io/x/onecloud/pkg/util/rbacutils"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
)
|
||||
@@ -89,6 +90,34 @@ func (man *SSuggestSysRuleConfigManager) InitScopeConfigs(ctx context.Context, u
|
||||
}
|
||||
}
|
||||
|
||||
func (manager *SSuggestSysRuleConfigManager) Init() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (man *SSuggestSysRuleConfigManager) Run(ctx context.Context) error {
|
||||
return man.deleteUnusedConfig()
|
||||
}
|
||||
|
||||
func (manager *SSuggestSysRuleConfigManager) deleteUnusedConfig() error {
|
||||
userCred := auth.AdminCredential()
|
||||
configs, err := manager.GetConfigsByScope(rbacutils.ScopeNone, userCred, false)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "SSuggestSysRuleConfigManager get ignore is false configs error")
|
||||
}
|
||||
for i, _ := range configs {
|
||||
err := (&configs[i]).CustomizeDelete(context.Background(), userCred, jsonutils.NewDict(),
|
||||
jsonutils.NewDict())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "init CustomizeDelete SuggestSysRuleConfig error")
|
||||
}
|
||||
err = (&configs[i]).Delete(context.Background(), userCred)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "init Delete SuggestSysRuleConfig error")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
SUGGEST_SCOPE_CONFIG = "suggest_scope_config"
|
||||
)
|
||||
@@ -434,6 +463,7 @@ func (man *SSuggestSysRuleConfigManager) ListItemFilter(ctx context.Context, q *
|
||||
if query.ResourceType != nil {
|
||||
q.Equals("resource_type", *query.ResourceType)
|
||||
}
|
||||
q.IsTrue("ignore_alert")
|
||||
if query.IgnoreAlert != nil {
|
||||
if *query.IgnoreAlert {
|
||||
q.IsTrue("ignore_alert")
|
||||
|
||||
Reference in New Issue
Block a user