mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #9459 from zhaoxiangchun/feature/zxc-commonalert-setnodata-master
feat(monitor): add alert slience time and modify scoperesource FetchUniqValues func
This commit is contained in:
@@ -42,6 +42,8 @@ type AlertRecordRule struct {
|
||||
// 比较运算符, 比如: >, <, >=, <=
|
||||
Comparator string `json:"comparator"`
|
||||
// 报警阀值
|
||||
Threshold string `json:"threshold"`
|
||||
Period string `json:"period"`
|
||||
Threshold string `json:"threshold"`
|
||||
Period string `json:"period"`
|
||||
AlertDuration int64 `json:"alert_duration"`
|
||||
ConditionType string `json:"condition_type"`
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ type CommonAlertCreateInput struct {
|
||||
|
||||
// 查询指标周期
|
||||
Period string `json:"period"`
|
||||
// 报警连续持续周期数
|
||||
AlertDuration int64 `json:"alert_duration"`
|
||||
// 通知方式, 比如: email, mobile
|
||||
Channel []string `json:"channel"`
|
||||
// 通知接受者
|
||||
@@ -89,6 +91,8 @@ type CommonAlertUpdateInput struct {
|
||||
|
||||
// 查询指标周期
|
||||
Period string `json:"period"`
|
||||
// 报警连续持续周期数
|
||||
AlertDuration int64 `json:"alert_duration"`
|
||||
// 通知方式, 比如: email, mobile
|
||||
Channel []string `json:"channel"`
|
||||
// 通知接受者
|
||||
@@ -101,12 +105,14 @@ type CommonAlertUpdateInput struct {
|
||||
|
||||
type CommonAlertDetails struct {
|
||||
AlertDetails
|
||||
Period string `json:"period"`
|
||||
Level string `json:"level"`
|
||||
NotifierId string `json:"notifier_id"`
|
||||
Channel []string `json:"channel"`
|
||||
Recipients []string `json:"recipients"`
|
||||
Status string `json:"status"`
|
||||
Period string `json:"period"`
|
||||
// 报警连续持续周期数
|
||||
AlertDuration int64 `json:"alert_duration"`
|
||||
Level string `json:"level"`
|
||||
NotifierId string `json:"notifier_id"`
|
||||
Channel []string `json:"channel"`
|
||||
Recipients []string `json:"recipients"`
|
||||
Status string `json:"status"`
|
||||
// 报警类型
|
||||
AlertType string `json:"alert_type"`
|
||||
CommonAlertMetricDetails []*CommonAlertMetricDetails `json:"common_alert_metric_details"`
|
||||
|
||||
@@ -54,7 +54,6 @@ func (m *SScopedResourceBaseManager) FetchUniqValues(ctx context.Context, data j
|
||||
uniqValues := sUniqValues{}
|
||||
switch parentScope {
|
||||
case rbacutils.ScopeSystem:
|
||||
uniqValues.Scope = scope
|
||||
case rbacutils.ScopeDomain:
|
||||
domain, _ := data.GetString("project_domain")
|
||||
uniqValues.Domain = domain
|
||||
@@ -62,6 +61,7 @@ func (m *SScopedResourceBaseManager) FetchUniqValues(ctx context.Context, data j
|
||||
project, _ := data.GetString("project")
|
||||
uniqValues.Project = project
|
||||
}
|
||||
uniqValues.Scope = scope
|
||||
return jsonutils.Marshal(uniqValues)
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ func (c *EvalContext) GetNewState() monitor.AlertStateType {
|
||||
}
|
||||
|
||||
since := time.Since(c.Rule.LastStateChange)
|
||||
if c.PrevAlertState == monitor.AlertStatePending && since > c.Rule.For {
|
||||
if c.PrevAlertState == monitor.AlertStatePending && since >= c.Rule.For {
|
||||
return monitor.AlertStateAlerting
|
||||
}
|
||||
|
||||
|
||||
@@ -228,5 +228,7 @@ func newAlertRecordRule(evalCtx *EvalContext) monitor.AlertRecordRule {
|
||||
alertRule.Period = fmt.Sprintf("%dm", evalCtx.Rule.Frequency/60)
|
||||
}
|
||||
|
||||
alertRule.AlertDuration = int64(evalCtx.Rule.For)/evalCtx.Rule.Frequency + 1
|
||||
|
||||
return alertRule
|
||||
}
|
||||
|
||||
@@ -177,6 +177,7 @@ func newRuleDescription(rule *Rule, alertDetails *monitor.CommonAlertMetricDetai
|
||||
FieldDesc: alertDetails.FieldDescription.DisplayName,
|
||||
Comparator: alertDetails.Comparator,
|
||||
Threshold: RationalizeValueFromUnit(alertDetails.Threshold, alertDetails.FieldDescription.Unit, ""),
|
||||
ConditionType: alertDetails.ConditionType,
|
||||
},
|
||||
}
|
||||
rule.RuleDescription = append(rule.RuleDescription, &ruleDes)
|
||||
|
||||
@@ -89,6 +89,9 @@ func (man *SCommonAlertManager) ValidateCreateData(
|
||||
if data.Period == "" {
|
||||
data.Period = "5m"
|
||||
}
|
||||
if data.AlertDuration == 0 {
|
||||
data.AlertDuration = 1
|
||||
}
|
||||
if data.Name == "" {
|
||||
return data, merrors.NewArgIsEmptyErr("name")
|
||||
}
|
||||
@@ -478,7 +481,7 @@ func (alert *SCommonAlert) GetMoreDetails(ctx context.Context, out monitor.Commo
|
||||
} else {
|
||||
out.Period = fmt.Sprintf("%dm", alert.Frequency/60)
|
||||
}
|
||||
|
||||
out.AlertDuration = alert.For/alert.Frequency + 1
|
||||
err = alert.getCommonAlertMetricDetails(&out)
|
||||
if err != nil {
|
||||
return out, err
|
||||
@@ -626,6 +629,9 @@ func getMetricDescriptionDetails(metricDetails *monitor.CommonAlertMetricDetails
|
||||
}
|
||||
if fieldDes, ok := influxdbMeasurements[0].FieldDescriptions[field]; ok {
|
||||
metricDetails.FieldDescription = fieldDes
|
||||
if metricDetails.FieldDescription.Unit == monitor.METRIC_UNIT_COUNT {
|
||||
metricDetails.FieldDescription.Unit = ""
|
||||
}
|
||||
if len(metricDetails.FieldOpt) != 0 {
|
||||
metricDetails.FieldDescription.Name = metricDetails.Field
|
||||
metricDetails.FieldDescription.DisplayName = metricDetails.Field
|
||||
@@ -661,6 +667,7 @@ func (man *SCommonAlertManager) toAlertCreatInput(input monitor.CommonAlertCreat
|
||||
ret := new(monitor.AlertCreateInput)
|
||||
ret.Name = input.Name
|
||||
ret.Frequency = int64(freq / time.Second)
|
||||
ret.For = ret.Frequency * (input.AlertDuration - 1)
|
||||
ret.Level = input.Level
|
||||
//ret.Settings =monitor.AlertSetting{}
|
||||
for _, metricquery := range input.CommonMetricInputQuery.MetricQuery {
|
||||
|
||||
Reference in New Issue
Block a user