diff --git a/pkg/apis/compute/cloudaccount.go b/pkg/apis/compute/cloudaccount.go index 2cb6e2ffcc..5f0e40f1ed 100644 --- a/pkg/apis/compute/cloudaccount.go +++ b/pkg/apis/compute/cloudaccount.go @@ -360,6 +360,10 @@ type CloudaccountDetail struct { } func (self CloudaccountDetail) GetMetricTags() map[string]string { + enabled := "true" + if self.Enabled != nil && !*self.Enabled { + enabled = "false" + } ret := map[string]string{ "id": self.Id, "cloudaccount_id": self.Id, @@ -371,6 +375,7 @@ func (self CloudaccountDetail) GetMetricTags() map[string]string { "tenant_id": self.ProjectId, "tenant": self.Project, "status": self.Status, + "enabled": enabled, } return AppendMetricTags(ret, self.MetadataResourceInfo, self.ProjectizedResourceInfo) } diff --git a/pkg/apis/monitor/alertquery_const.go b/pkg/apis/monitor/alertquery_const.go index b812154a0a..795a51e035 100644 --- a/pkg/apis/monitor/alertquery_const.go +++ b/pkg/apis/monitor/alertquery_const.go @@ -184,6 +184,7 @@ var ( "brand": "brand", "domain_id": "domain_id", "project_domain": "project_domain", + "enabled": "enabled", } TenantTags = map[string]string{ diff --git a/pkg/monitor/alerting/conditions/query.go b/pkg/monitor/alerting/conditions/query.go index 44e6e54f9f..49f51c6c0d 100644 --- a/pkg/monitor/alerting/conditions/query.go +++ b/pkg/monitor/alerting/conditions/query.go @@ -182,6 +182,11 @@ func (c *QueryCondition) Eval(context *alerting.EvalContext) (*alerting.Conditio } for _, series := range seriesList { + if c.ResType == monitor.METRIC_RES_TYPE_CLOUDACCOUNT { + if enabled, ok := series.Tags["enabled"]; ok && enabled == "false" { + continue + } + } if c.IsCloudResource() { isLatestOfSerie, resource := c.serieIsLatestResource(nil, series) if !isLatestOfSerie { @@ -557,6 +562,7 @@ func newQueryCondition(model *monitor.AlertCondition, index int) (*QueryConditio cond.checkGroupByField() cond.setResType() + models.AppendCloudAccountDefaultQueryTags(&cond.Query.Model, true) return cond, nil } diff --git a/pkg/monitor/models/unifiedmonitor.go b/pkg/monitor/models/unifiedmonitor.go index cd303a4452..c06b9373da 100644 --- a/pkg/monitor/models/unifiedmonitor.go +++ b/pkg/monitor/models/unifiedmonitor.go @@ -505,6 +505,29 @@ func setDefaultValue( Condition: "and", }) } + AppendCloudAccountDefaultQueryTags(&query.Model, isAlert) +} + +// AppendCloudAccountDefaultQueryTags appends default tag filters for cloud account metrics. +func AppendCloudAccountDefaultQueryTags(model *monitor.MetricQuery, isAlert bool) { + if !isAlert || model == nil { + return + } + metricMeasurement, _ := MetricMeasurementManager.GetCache().Get(model.Measurement) + if metricMeasurement == nil || metricMeasurement.ResType != monitor.METRIC_RES_TYPE_CLOUDACCOUNT { + return + } + for _, tagFilter := range model.Tags { + if tagFilter.Key == "enabled" { + return + } + } + model.Tags = append(model.Tags, monitor.MetricQueryTag{ + Key: "enabled", + Operator: "=", + Value: "true", + Condition: "and", + }) } func checkQueryGroupBy(query *monitor.AlertQuery, inputQuery *monitor.MetricQueryInput, isAlert bool) {