Skip to content

Commit c802c41

Browse files
authored
Merge pull request #1060 from cloudflare/ignoreLabelsValue
Validate ignoreLabelsValue
2 parents c095cda + 5b8c8c2 commit c802c41

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

Diff for: docs/changelog.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v0.64.1
4+
5+
### Fixed
6+
7+
- Validate `ignoreLabelsValue` option values in the pint config.
8+
39
## v0.64.0
410

511
### Added

Diff for: docs/checks/promql/series.md

+29
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ check "promql/series" {
164164
should **NOT** report problems if there's a query that uses a **value** that does not exist.
165165
This can be also set per rule using `# pint rule/set promql/series ignore/label-value $labelName`
166166
comments, see below.
167+
The value of this option is a map where the key is a metric selector to match on and the value
168+
is the list of label names.
167169

168170
Example:
169171

@@ -193,6 +195,33 @@ check "promql/series" {
193195
}
194196
```
195197

198+
You can use any metric selectors as keys in `ignoreLabelsValue` if you want apply it only
199+
to metric selectors in queries that match the selector in `ignoreLabelsValue`.
200+
For example if you have a rule that uses the same metric with two different selectors:
201+
202+
```yaml
203+
- alerts: ...
204+
expr: |
205+
rate(http_requests_total{env="prod", code="401"}[5m]) > 0
206+
or
207+
rate(http_requests_total{env="dev", code="401"}[5m]) > 0
208+
```
209+
210+
And you want to disable pint warnings only for the second selector (`http_requests_total{env="dev", code="401"}`)
211+
but not the first one (`http_requests_total{env="prod", code="401"}`) you can do that by adding any label matcher
212+
used in the query:
213+
214+
```js
215+
check "promql/series" {
216+
ignoreLabelsValue = {
217+
"http_requests_total{env=\"dev\"}" = [ "code" ]
218+
}
219+
}
220+
```
221+
222+
You can only use label matchers that would match the selector from the query itself, not from the time series
223+
the query would return. This whole logic applies only to the query, not to the results of it.
224+
196225
### min-age
197226

198227
But default this check will report a problem if a metric was present

Diff for: internal/checks/promql_series.go

+6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ func (c *PromqlSeriesSettings) Validate() error {
6060
c.lookbackStepDuration = time.Duration(dur)
6161
}
6262

63+
for selector := range c.IgnoreLabelsValue {
64+
if _, err := promParser.ParseMetricSelector(selector); err != nil {
65+
return fmt.Errorf("%q is not a valid PromQL metric selector: %w", selector, err)
66+
}
67+
}
68+
6369
return nil
6470
}
6571

Diff for: internal/config/config_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -2148,6 +2148,22 @@ func TestConfigErrors(t *testing.T) {
21482148
config: `check "promql/series" { ignoreMetrics = [".+++"] }`,
21492149
err: "error parsing regexp: invalid nested repetition operator: `++`",
21502150
},
2151+
{
2152+
config: `check "promql/series" {
2153+
ignoreLabelsValue = {
2154+
"foo bar" = [ "abc" ]
2155+
}
2156+
}`,
2157+
err: `"foo bar" is not a valid PromQL metric selector: 1:5: parse error: unexpected identifier "bar"`,
2158+
},
2159+
{
2160+
config: `check "promql/series" {
2161+
ignoreLabelsValue = {
2162+
"foo{" = [ "abc" ]
2163+
}
2164+
}`,
2165+
err: `"foo{" is not a valid PromQL metric selector: 1:5: parse error: unexpected end of input inside braces`,
2166+
},
21512167
{
21522168
config: `rule {
21532169
link ".+++" {}

0 commit comments

Comments
 (0)