diff --git a/docker/initsql/a-n9e.sql b/docker/initsql/a-n9e.sql index 0fffc607..76d8a2c2 100644 --- a/docker/initsql/a-n9e.sql +++ b/docker/initsql/a-n9e.sql @@ -350,6 +350,7 @@ CREATE TABLE `recording_rule` ( `cluster` varchar(128) not null, `name` varchar(255) not null comment 'new metric name', `note` varchar(255) not null comment 'rule note', + `disabled` tinyint(1) not null comment '0:enabled 1:disabled', `prom_ql` varchar(8192) not null comment 'promql', `prom_eval_interval` int not null comment 'evaluate interval', `append_tags` varchar(255) default '' comment 'split by space: service=n9e mod=api', diff --git a/src/models/recording_rule.go b/src/models/recording_rule.go index 348ac04f..d309fd10 100644 --- a/src/models/recording_rule.go +++ b/src/models/recording_rule.go @@ -16,6 +16,7 @@ type RecordingRule struct { Cluster string `json:"cluster"` // take effect by cluster Name string `json:"name"` // new metric name Note string `json:"note"` // note + Disabled int `json:"disabled"` // 0: enabled, 1: disabled PromQl string `json:"prom_ql"` // just one ql for promql PromEvalInterval int `json:"prom_eval_interval"` // unit:s AppendTags string `json:"-"` // split by space: service=n9e mod=api @@ -63,7 +64,8 @@ func (re *RecordingRule) Verify() error { re.AppendTags = strings.TrimSpace(re.AppendTags) rer := strings.Fields(re.AppendTags) for i := 0; i < len(rer); i++ { - if len(strings.Split(rer[i], "=")) != 2 || !model.LabelNameRE.MatchString(strings.Split(rer[i], "=")[0]) { + pair := strings.Split(rer[i], "=") + if len(pair) != 2 || !model.LabelNameRE.MatchString(pair[0]) { return fmt.Errorf("AppendTags(%s) invalid", rer[i]) } } @@ -171,7 +173,7 @@ func RecordingRuleGetById(id int64) (*RecordingRule, error) { func RecordingRuleGetsByCluster(cluster string) ([]*RecordingRule, error) { session := DB() if cluster != "" { - session = DB().Where("cluster = ?", cluster) + session = session.Where("cluster = ?", cluster) } var lst []*RecordingRule diff --git a/src/server/engine/worker.go b/src/server/engine/worker.go index ed26d3f7..99b3219d 100644 --- a/src/server/engine/worker.go +++ b/src/server/engine/worker.go @@ -220,6 +220,10 @@ func (ws *WorkersType) BuildRe(rids []int64) { continue } + if rule.Disabled == 1 { + continue + } + hash := str.MD5(fmt.Sprintf("%d_%d_%s_%s", rule.Id, rule.PromEvalInterval,