feat(monitor): support listing monitor_resource by alert_state (#22287)

This commit is contained in:
Zexi Li
2025-03-18 11:52:25 +08:00
committed by GitHub
parent 2b60f5a217
commit 357b5c1f43
4 changed files with 20 additions and 9 deletions
+4 -3
View File
@@ -39,9 +39,10 @@ type MonitorResourceListInput struct {
apis.EnabledResourceBaseListInput
compute.ManagedResourceListInput
ResId []string `json:"res_id"`
ResType string `json:"res_type"`
OnlyResId bool `json:"only_res_id"`
ResId []string `json:"res_id"`
ResType string `json:"res_type"`
OnlyResId bool `json:"only_res_id"`
AlertStates []string `json:"alert_states"`
ResName string `json:"res_name"`
}
@@ -33,9 +33,10 @@ func (o *MonitorResourceJointAlertOptions) Property() string {
type MonitorResourceListOptions struct {
options.BaseListOptions
ResType string `help:"filter by resource type" json:"res_type"`
ResId []string `help:"filter by resource id" json:"res_id"`
ResName string `help:"filter by resource name" json:"res_name"`
ResType string `help:"filter by resource type" json:"res_type"`
ResId []string `help:"filter by resource id" json:"res_id"`
ResName string `help:"filter by resource name" json:"res_name"`
AlertStates []string `help:"filter by alert state" json:"alert_states"`
}
func (o *MonitorResourceListOptions) Params() (jsonutils.JSONObject, error) {
+9 -3
View File
@@ -110,9 +110,15 @@ func (c FormatCond) String() string {
return "no_data"
}
func (c *QueryCondition) filterTags(tags map[string]string, details monitor.CommonAlertMetricDetails) map[string]string {
func (c *QueryCondition) filterTags(tags map[string]string, cloudTags map[string]string, details monitor.CommonAlertMetricDetails) map[string]string {
ret := make(map[string]string)
for key, val := range tags {
allTags := make(map[string]string)
for _, ts := range []map[string]string{tags, cloudTags} {
for k, v := range ts {
allTags[k] = v
}
}
for key, val := range allTags {
//if strings.HasSuffix(key, "_id") {
// continue
//}
@@ -303,7 +309,7 @@ func (c *QueryCondition) NewEvalMatch(
queryKeyInfo = evalMatch.Metric
}
evalMatch.Unit = alertDetails.FieldDescription.Unit
evalMatch.Tags = c.filterTags(series.Tags, *alertDetails)
evalMatch.Tags = c.filterTags(series.Tags, series.CloudTags, *alertDetails)
evalMatch.Value = value
evalMatch.ValueStr = models.RationalizeValueFromUnit(*value, alertDetails.FieldDescription.Unit,
alertDetails.FieldOpt)
+3
View File
@@ -203,6 +203,9 @@ func (manager *SMonitorResourceManager) FieldListFilter(q *sqlchemy.SQuery, quer
if len(query.ResName) != 0 {
q.Contains("name", query.ResName)
}
if len(query.AlertStates) != 0 {
q.In("alert_state", query.AlertStates)
}
return q
}