-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add hasSourceTenantsForMetrics validator, refactor, optimize do…
…cs html rendering, add some additional tests Signed-off-by: Martin Chodur <[email protected]>
- Loading branch information
Showing
23 changed files
with
495 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
<h1>Validation rules</h1> | ||
|
||
<h2><a href="#check-severity-label">check-severity-label</a></h2> | ||
<ul> | ||
<li>Alert has labels: <code>severity</code></li> | ||
<li>Alert label <code>severity</code> has one of the allowed values: <code>info</code>,<code>warning</code>,<code>critical</code></li> | ||
<li>Alert if rule has label <code>severity</code> with value <code>info</code> , it cannot have label <code>page</code></li> | ||
<li>Alert expression can be successfully evaluated on the live Prometheus instance</li> | ||
<li>Alert expression uses only labels that are actually present in Prometheus</li> | ||
<li>Alert expression selectors actually matches any series in Prometheus</li> | ||
<li>Alert expression does not use data older than <code>6h0m0s</code></li> | ||
</ul> | ||
|
||
<h2><a href="#check-team-label">check-team-label</a></h2> | ||
<ul> | ||
<li>Alert has labels: <code>xxx</code></li> | ||
<li>Alert label <code>team</code> has one of the allowed values: <code>[email protected]</code></li> | ||
</ul> | ||
|
||
<h2><a href="#check-playbook-annotation">check-playbook-annotation</a></h2> | ||
<ul> | ||
<li>Alert has any of these annotations: <code>playbook</code>,<code>link</code></li> | ||
<li>Alert Annotation <code>link</code> is a valid URL and does not return HTTP status 404</li> | ||
</ul> | ||
|
||
<h2><a href="#check-alert-title">check-alert-title</a></h2> | ||
<ul> | ||
<li>Alert has all of these annotations: <code>title</code></li> | ||
</ul> | ||
|
||
<h2><a href="#check-prometheus-limitations">check-prometheus-limitations</a></h2> | ||
<ul> | ||
<li>All rules expression does not use data older than <code>6h0m0s</code></li> | ||
<li>All rules does not use any of the <code>cluster</code>,<code>locality</code>,<code>prometheus-type</code>,<code>replica</code> labels is in its expression</li> | ||
<li>All rules verifies if the rule group, the rule belongs to, has the required source_tenants configured, according to the mapping of metric names to tenants: <code>k8s</code>:<code>^container_.*|kube_.*$</code></li> | ||
</ul> | ||
|
||
<h2><a href="#another-checks">another-checks</a></h2> | ||
<ul> | ||
<li>All rules labels does not have empty values</li> | ||
</ul> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
Validation rules: | ||
|
||
check-severity-label | ||
- Alert has labels: `severity` | ||
- Alert label `severity` has one of the allowed values: `info`,`warning`,`critical` | ||
- Alert if rule has label `severity` with value `info` , it cannot have label `page` | ||
- Alert expression can be successfully evaluated on the live Prometheus instance | ||
- Alert expression uses only labels that are actually present in Prometheus | ||
- Alert expression selectors actually matches any series in Prometheus | ||
- Alert expression does not use data older than `6h0m0s` | ||
|
||
check-team-label | ||
- Alert has labels: `xxx` | ||
- Alert label `team` has one of the allowed values: `[email protected]` | ||
|
||
check-playbook-annotation | ||
- Alert has any of these annotations: `playbook`,`link` | ||
- Alert Annotation `link` is a valid URL and does not return HTTP status 404 | ||
|
||
check-alert-title | ||
- Alert has all of these annotations: `title` | ||
|
||
check-prometheus-limitations | ||
- All rules expression does not use data older than `6h0m0s` | ||
- All rules does not use any of the `cluster`,`locality`,`prometheus-type`,`replica` labels is in its expression | ||
- All rules verifies if the rule group, the rule belongs to, has the required source_tenants configured, according to the mapping of metric names to tenants: `k8s`:`^container_.*|kube_.*$` | ||
|
||
another-checks | ||
- All rules labels does not have empty values | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package unmarshaler | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/prometheus/common/model" | ||
"github.com/prometheus/prometheus/model/rulefmt" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type fakeTestFile struct { | ||
RuleFiles []yaml.Node `yaml:"rule_files,omitempty"` | ||
EvaluationInterval yaml.Node `yaml:"evaluation_interval,omitempty"` | ||
GroupEvalOrder []yaml.Node `yaml:"group_eval_order,omitempty"` | ||
Tests []yaml.Node `yaml:"tests,omitempty"` | ||
} | ||
|
||
type RulesFile struct { | ||
Groups []RuleGroup `yaml:"groups"` | ||
fakeTestFile // Just so we can unmarshal also PromQL test files but ignore them because it has no Groups | ||
} | ||
|
||
type RuleGroup struct { | ||
Name string `yaml:"name"` | ||
Interval model.Duration `yaml:"interval,omitempty"` | ||
PartialResponseStrategy string `yaml:"partial_response_strategy,omitempty"` | ||
SourceTenants []string `yaml:"source_tenants,omitempty"` | ||
Rules []ruleWithComment `yaml:"rules"` | ||
} | ||
|
||
type ruleWithComment struct { | ||
node yaml.Node | ||
rule rulefmt.RuleNode | ||
} | ||
|
||
func (r *ruleWithComment) OriginalRule() rulefmt.Rule { | ||
return rulefmt.Rule{ | ||
Record: r.rule.Record.Value, | ||
Alert: r.rule.Alert.Value, | ||
Expr: r.rule.Expr.Value, | ||
For: r.rule.For, | ||
Labels: r.rule.Labels, | ||
Annotations: r.rule.Annotations, | ||
} | ||
} | ||
|
||
func (r *ruleWithComment) UnmarshalYAML(value *yaml.Node) error { | ||
err := value.Decode(&r.node) | ||
if err != nil { | ||
return err | ||
} | ||
err = value.Decode(&r.rule) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (r *ruleWithComment) DisabledValidators(commentPrefix string) []string { | ||
commentPrefix += ":" | ||
var disabledValidators []string | ||
allComments := strings.Split(r.node.HeadComment, "\n") | ||
for _, line := range strings.Split(r.rule.Expr.Value, "\n") { | ||
before, comment, found := strings.Cut(line, "#") | ||
if !found || strings.TrimSpace(before) != "" { | ||
continue | ||
} | ||
allComments = append(allComments, comment) | ||
} | ||
for _, comment := range allComments { | ||
_, csv, found := strings.Cut(comment, commentPrefix) | ||
if !found { | ||
continue | ||
} | ||
validators := strings.Split(csv, ",") | ||
for _, v := range validators { | ||
vv := strings.TrimSpace(v) | ||
disabledValidators = append(disabledValidators, vv) | ||
} | ||
} | ||
return disabledValidators | ||
} |
Oops, something went wrong.