File tree 4 files changed +57
-0
lines changed
4 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
3
+ ## v0.64.1
4
+
5
+ ### Fixed
6
+
7
+ - Validate ` ignoreLabelsValue ` option values in the pint config.
8
+
3
9
## v0.64.0
4
10
5
11
### Added
Original file line number Diff line number Diff line change @@ -164,6 +164,8 @@ check "promql/series" {
164
164
should **NOT** report problems if there's a query that uses a **value** that does not exist.
165
165
This can be also set per rule using `# pint rule/set promql/series ignore/label-value $labelName`
166
166
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.
167
169
168
170
Example :
169
171
@@ -193,6 +195,33 @@ check "promql/series" {
193
195
}
194
196
` ` `
195
197
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
+
196
225
# ## min-age
197
226
198
227
But default this check will report a problem if a metric was present
Original file line number Diff line number Diff line change @@ -60,6 +60,12 @@ func (c *PromqlSeriesSettings) Validate() error {
60
60
c .lookbackStepDuration = time .Duration (dur )
61
61
}
62
62
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
+
63
69
return nil
64
70
}
65
71
Original file line number Diff line number Diff line change @@ -2148,6 +2148,22 @@ func TestConfigErrors(t *testing.T) {
2148
2148
config : `check "promql/series" { ignoreMetrics = [".+++"] }` ,
2149
2149
err : "error parsing regexp: invalid nested repetition operator: `++`" ,
2150
2150
},
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
+ },
2151
2167
{
2152
2168
config : `rule {
2153
2169
link ".+++" {}
You can’t perform that action at this time.
0 commit comments