You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
8
8
## [Unreleased]
9
9
10
+
## [3.6.1] - 2024-12-01
11
+
- Fixed: FIxed the `expressionUsesOnlyAllowedLabelsForMetricRegexp` validator that might return false positives when used on more complex expressions with vector matching and functions using labels.
12
+
10
13
## [3.6.0] - 2024-11-29
11
14
- Added: Configuration file can now be in Jsonnet format if the config file name ends with `.jsonnet` and it will get automatically evaluated.
Fails if the rule uses any labels beside those listed in `allowedLabels`, in combination with given metric regexp in its `expr` label matchers, aggregations or joins.
272
-
Different metric name matchers are handled as follows:
273
-
* `{__name__="foo",..}, foo{...}` - `foo` is matched literally against given `metricNameRegexp`, if matches, expr is validated against `allowedLabels`
Fails if the rule uses any labels beside those listed in `allowedLabels`, in combination with given metric regexp in its `expr` label matchers, aggregations or joins. If the metric name is omitted in the query, or matched using regexp or any negative matcher on the `__name__` label, the rule will be skipped.
272
+
273
+
The check rather ignores validation of labels, where it cannot be sure if they are targeting only the metric in question, like aggregations by labels on top of vector matching expression where the labels might come from the other part of the expr.
276
274
277
275
> If using kube-state-metrics for exposing labels information about K8S objects (kube_*_labels) only those labels whitelisted by kube-state-metrics admin will be available.
278
276
> Might be useful to check that users does not use any other in their expressions.
return""// Ignore the error, this shouldn't happen anyway, parser should already catch this.
45
+
}
46
+
returnval.Val
47
+
}
48
+
40
49
// Returns a list of labels which are used in given expr in relation to given metric.
41
-
// Beside labels within vector selector itself, it adds labels used in Aggregate expressions and labels used in Binary expression.
42
-
// For Binary expressions it may report false positives as the current implementation does not consider on which side of group_left/group_right is the given metric.
50
+
// It traverses the whole expression tree top to bottom and collects all labels used in selectors, operators, functions etc.
51
+
// In case of vector matching, it also collects labels used in vector matching only relevant to the part of the expression where the metric is used.
52
+
// If the vector matching uses grouping, any labels used on top of the expression are not validated, since they might come from the other side of the expression.
// If any group_left/group_right is used, we need to reset the used labels, since any labels used on top of this expression might come from the other side of the expression.
74
+
ifv.VectorMatching.Include!=nil {
75
+
usedLabels=map[string]struct{}{}
76
+
}
77
+
// Validate only the on(...) labels. The ignoring(...) might target the other side of the binary expression.
78
+
ifv.VectorMatching.On {
79
+
for_, l:=rangev.VectorMatching.MatchingLabels {
80
+
usedLabels[l] =struct{}{}
81
+
}
82
+
}
83
+
// We want to validate the group_left/group_right labels only if the validated metric is on the "one" of the many-one/one-to.many side.
84
+
nextExpr:=path[i+1].String()
85
+
if (v.VectorMatching.Card==parser.CardManyToOne&&v.RHS.String() ==nextExpr) || (v.VectorMatching.Card==parser.CardOneToMany&&v.LHS.String() ==nextExpr) {
86
+
for_, l:=rangev.VectorMatching.Include {
87
+
usedLabels[l] =struct{}{}
88
+
}
89
+
}
90
+
case*parser.Call:
91
+
switchv.Func.Name {
92
+
case"label_replace":
93
+
// Any PromQL "above" this label_replace can use the destination synthetic label, so drop it from the list of already used labels.
0 commit comments