refactor recording rule and and field disabled (#1022)
This commit is contained in:
parent
6b1d283cda
commit
2ef541cdd7
|
@ -350,6 +350,7 @@ CREATE TABLE `recording_rule` (
|
||||||
`cluster` varchar(128) not null,
|
`cluster` varchar(128) not null,
|
||||||
`name` varchar(255) not null comment 'new metric name',
|
`name` varchar(255) not null comment 'new metric name',
|
||||||
`note` varchar(255) not null comment 'rule note',
|
`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_ql` varchar(8192) not null comment 'promql',
|
||||||
`prom_eval_interval` int not null comment 'evaluate interval',
|
`prom_eval_interval` int not null comment 'evaluate interval',
|
||||||
`append_tags` varchar(255) default '' comment 'split by space: service=n9e mod=api',
|
`append_tags` varchar(255) default '' comment 'split by space: service=n9e mod=api',
|
||||||
|
|
|
@ -16,6 +16,7 @@ type RecordingRule struct {
|
||||||
Cluster string `json:"cluster"` // take effect by cluster
|
Cluster string `json:"cluster"` // take effect by cluster
|
||||||
Name string `json:"name"` // new metric name
|
Name string `json:"name"` // new metric name
|
||||||
Note string `json:"note"` // note
|
Note string `json:"note"` // note
|
||||||
|
Disabled int `json:"disabled"` // 0: enabled, 1: disabled
|
||||||
PromQl string `json:"prom_ql"` // just one ql for promql
|
PromQl string `json:"prom_ql"` // just one ql for promql
|
||||||
PromEvalInterval int `json:"prom_eval_interval"` // unit:s
|
PromEvalInterval int `json:"prom_eval_interval"` // unit:s
|
||||||
AppendTags string `json:"-"` // split by space: service=n9e mod=api
|
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)
|
re.AppendTags = strings.TrimSpace(re.AppendTags)
|
||||||
rer := strings.Fields(re.AppendTags)
|
rer := strings.Fields(re.AppendTags)
|
||||||
for i := 0; i < len(rer); i++ {
|
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])
|
return fmt.Errorf("AppendTags(%s) invalid", rer[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,7 +173,7 @@ func RecordingRuleGetById(id int64) (*RecordingRule, error) {
|
||||||
func RecordingRuleGetsByCluster(cluster string) ([]*RecordingRule, error) {
|
func RecordingRuleGetsByCluster(cluster string) ([]*RecordingRule, error) {
|
||||||
session := DB()
|
session := DB()
|
||||||
if cluster != "" {
|
if cluster != "" {
|
||||||
session = DB().Where("cluster = ?", cluster)
|
session = session.Where("cluster = ?", cluster)
|
||||||
}
|
}
|
||||||
|
|
||||||
var lst []*RecordingRule
|
var lst []*RecordingRule
|
||||||
|
|
|
@ -220,6 +220,10 @@ func (ws *WorkersType) BuildRe(rids []int64) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rule.Disabled == 1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
hash := str.MD5(fmt.Sprintf("%d_%d_%s_%s",
|
hash := str.MD5(fmt.Sprintf("%d_%d_%s_%s",
|
||||||
rule.Id,
|
rule.Id,
|
||||||
rule.PromEvalInterval,
|
rule.PromEvalInterval,
|
||||||
|
|
Loading…
Reference in New Issue