From a43bfebdfc45de381df4f87e98bf63fcb8f253e7 Mon Sep 17 00:00:00 2001 From: Lukasz Mierzwa Date: Tue, 19 Nov 2024 11:18:23 +0000 Subject: [PATCH] Add tests for new query syntax --- docs/changelog.md | 12 +++++ internal/parser/parser_test.go | 82 ++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index cc835c55..edfad774 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,17 @@ # Changelog +## v0.68.0 + +### Changed + +- pint now uses [Prometheus 3.0](https://prometheus.io/blog/2024/11/14/prometheus-3-0/) libraries + for parsing PromQL, which adds support for new query syntax that allows for dots and UTF-8 chars + in metric/label names, example: + + ```js + {"status.üp"} == 0 + ``` + ## v0.67.3 ### Fixed diff --git a/internal/parser/parser_test.go b/internal/parser/parser_test.go index 194057af..229647ba 100644 --- a/internal/parser/parser_test.go +++ b/internal/parser/parser_test.go @@ -2798,6 +2798,88 @@ groups: `), strict: true, }, + { + content: []byte(` +groups: +- name: foo + rules: + - record: foo + expr: | + {"up"} +`), + output: []parser.Rule{ + { + Lines: parser.LineRange{First: 5, Last: 7}, + RecordingRule: &parser.RecordingRule{ + Record: parser.YamlNode{ + Lines: parser.LineRange{First: 5, Last: 5}, + Value: "foo", + }, + Expr: parser.PromQLExpr{ + Value: &parser.YamlNode{ + Lines: parser.LineRange{First: 6, Last: 7}, + Value: "{\"up\"}\n", + }, + }, + }, + }, + }, + }, + { + content: []byte(` +groups: +- name: foo + rules: + - record: foo + expr: | + {'up'} +`), + output: []parser.Rule{ + { + Lines: parser.LineRange{First: 5, Last: 7}, + RecordingRule: &parser.RecordingRule{ + Record: parser.YamlNode{ + Lines: parser.LineRange{First: 5, Last: 5}, + Value: "foo", + }, + Expr: parser.PromQLExpr{ + Value: &parser.YamlNode{ + Lines: parser.LineRange{First: 6, Last: 7}, + Value: "{'up'}\n", + }, + }, + }, + }, + }, + }, + { + content: []byte(` +groups: +- name: foo + rules: + - record: foo + expr: | + {'up' == 1} +`), + output: []parser.Rule{ + { + Lines: parser.LineRange{First: 5, Last: 7}, + RecordingRule: &parser.RecordingRule{ + Record: parser.YamlNode{ + Lines: parser.LineRange{First: 5, Last: 5}, + Value: "foo", + }, + Expr: parser.PromQLExpr{ + Value: &parser.YamlNode{ + Lines: parser.LineRange{First: 6, Last: 7}, + Value: "{'up' == 1}\n", + }, + SyntaxError: errors.New("unexpected character inside braces: '1'"), + }, + }, + }, + }, + }, } alwaysEqual := cmp.Comparer(func(_, _ interface{}) bool { return true })