mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-31 01:35:56 +08:00
fix(monitor): skip disable account alert (#24979)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -184,6 +184,7 @@ var (
|
||||
"brand": "brand",
|
||||
"domain_id": "domain_id",
|
||||
"project_domain": "project_domain",
|
||||
"enabled": "enabled",
|
||||
}
|
||||
|
||||
TenantTags = map[string]string{
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user