Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## v0.76.2

### Fixed

- For queries using binary expressions between two vectors Prometheus will remove the metric name
from resulting series, pint will now also apply the same logic when checking queries.

## v0.76.1

### Fixed
Expand Down
12 changes: 12 additions & 0 deletions internal/checks/alerts_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,18 @@ func TestTemplateCheck(t *testing.T) {
expr: sum(foo) > 0
annotations:
summary: '{{ .Labels.job }} is above zero on {{ $labels.__name__ }}'
`,
checker: newTemplateCheck,
prometheus: noProm,
problems: true,
},
{
description: "__name__ is stripped in foo+foo",
content: `
- alert: Foo
expr: foo + on(__name__, job) foo > 0
annotations:
summary: '{{ .Labels.job }} is above zero on {{ $labels.__name__ }}'
`,
checker: newTemplateCheck,
prometheus: noProm,
Expand Down
43 changes: 43 additions & 0 deletions internal/checks/alerts_template_test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,49 @@

---

[TestTemplateCheck/__name___is_stripped_in_foo+foo - 1]
- description: __name__ is stripped in foo+foo
content: |4

- alert: Foo
expr: foo + on(__name__, job) foo > 0
annotations:
summary: '{{ .Labels.job }} is above zero on {{ $labels.__name__ }}'
output: |
3 | expr: foo + on(__name__, job) foo > 0
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Binary operation between two vectors removes metric names.
| [...]
5 | summary: '{{ .Labels.job }} is above zero on {{ $labels.__name__ }}'
^^^^^^^^^ Template is using `__name__` label but the query results won't have this label.
problem:
reporter: alerts/template
summary: template uses non-existent label
details: ""
diagnostics:
- message: Template is using `__name__` label but the query results won't have this label.
pos:
- line: 5
firstcolumn: 15
lastcolumn: 71
firstcolumn: 46
lastcolumn: 54
kind: 0
- message: Binary operation between two vectors removes metric names.
pos:
- line: 3
firstcolumn: 9
lastcolumn: 39
firstcolumn: 1
lastcolumn: 27
kind: 1
lines:
first: 2
last: 5
severity: 2
anchor: 0

---

[TestTemplateCheck/abs_/_scalar - 1]
[]

Expand Down
3 changes: 3 additions & 0 deletions internal/parser/utils/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@ func parseBinOps(expr string, n *promParser.BinaryExpr) (src []Source) {
AddedLabels: n.VectorMatching.Include,
})
}
ls.excludeLabel("Binary operation between two vectors removes metric names.", n.PositionRange(), labels.MetricName)
ls.IsConditional, ls.ReturnInfo.IsReturnBool = checkConditions(ls, n.Op, n.ReturnBool)
src = append(src, ls)
}
Expand Down Expand Up @@ -1022,6 +1023,7 @@ func parseBinOps(expr string, n *promParser.BinaryExpr) (src []Source) {
AddedLabels: n.VectorMatching.Include,
})
}
rs.excludeLabel("Binary operation between two vectors removes metric names.", n.PositionRange(), labels.MetricName)
rs.IsConditional, rs.ReturnInfo.IsReturnBool = checkConditions(rs, n.Op, n.ReturnBool)
src = append(src, rs)
}
Expand Down Expand Up @@ -1065,6 +1067,7 @@ func parseBinOps(expr string, n *promParser.BinaryExpr) (src []Source) {
AddedLabels: n.VectorMatching.Include,
})
}
ls.excludeLabel("Binary operation between two vectors removes metric names.", n.PositionRange(), labels.MetricName)
ls.IsConditional, ls.ReturnInfo.IsReturnBool = checkConditions(ls, n.Op, n.ReturnBool)
src = append(src, ls)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/parser/utils/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ count by (dc) (
`topk(10, prometheus_build_info*prometheus_ready)`,
`bottomk(10, prometheus_build_info*prometheus_ready)`,
`histogram_fraction(0, 0.1, metric)`,
`foo * foo `,
`foo + on(__name__, job) foo `,
`foo + on(__name__, job) group_left foo `,
`foo + on(__name__, job) group_right foo `,
}

func TestLabelsSource(t *testing.T) {
Expand Down
Loading
Loading