-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*: Promql changes to add support to extended functions throught Thanos (
#7338) * fixing extended functions support in more places Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com> * Adding new failint for the Parse() method Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com> * Adding new method for ParseMetricSelector Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com> * Fixing missing imports Extending test to check behavior More missing imports Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com> * Fixing method name Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com> * Solving references to forbidden functions Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com> * Treating promql validation from ParseExpr Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com> * fixing funcs Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com> --------- Signed-off-by: Pedro Tanaka <pedro.stanaka@gmail.com> Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
- Loading branch information
1 parent
ab8f2b3
commit 970cbbe
Showing
21 changed files
with
171 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) The Thanos Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
package extpromql_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/efficientgo/core/testutil" | ||
"github.com/prometheus/prometheus/model/labels" | ||
"github.com/prometheus/prometheus/promql/parser" | ||
|
||
"github.com/thanos-io/thanos/pkg/extpromql" | ||
) | ||
|
||
func TestParseMetricSelector(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
input string | ||
}{ | ||
{ | ||
name: "single selector", | ||
input: `http_requests_total{method="GET"}`, | ||
}, | ||
{ | ||
name: "empty selectors", | ||
input: `process_cpu_seconds_total`, | ||
}, | ||
{ | ||
name: "multiple selectors", | ||
input: `http_requests_total{method="GET",code="200"}`, | ||
}, | ||
{ | ||
name: "multiple selectors with different matchers", | ||
input: `http_requests_total{method="GET",code!="200"}`, | ||
}, | ||
{ | ||
name: "multiple selectors with regex", | ||
input: `http_requests_total{method="GET",code=~"2.*"}`, | ||
}, | ||
{ | ||
name: "selector with negative regex", | ||
input: `{code!~"2.*"}`, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
//lint:ignore faillint Testing against prometheus parser. | ||
want, err := parser.ParseMetricSelector(tc.input) | ||
if err != nil { | ||
t.Fatalf("Prometheus ParseMetricSelector failed: %v", err) | ||
} | ||
|
||
got, err := extpromql.ParseMetricSelector(tc.input) | ||
if err != nil { | ||
t.Fatalf("ParseMetricSelector failed: %v", err) | ||
} | ||
|
||
testutil.Equals(t, stringFmt(want), stringFmt(got)) | ||
}) | ||
} | ||
} | ||
|
||
func stringFmt(got []*labels.Matcher) string { | ||
return fmt.Sprintf("%v", got) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.