forked from thanos-io/thanos
-
Notifications
You must be signed in to change notification settings - Fork 7
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 (
thanos-io#7338) * fixing extended functions support in more places Signed-off-by: Pedro Tanaka <[email protected]> * Adding new failint for the Parse() method Signed-off-by: Pedro Tanaka <[email protected]> * Adding new method for ParseMetricSelector Signed-off-by: Pedro Tanaka <[email protected]> * Fixing missing imports Extending test to check behavior More missing imports Signed-off-by: Pedro Tanaka <[email protected]> * Fixing method name Signed-off-by: Pedro Tanaka <[email protected]> * Solving references to forbidden functions Signed-off-by: Pedro Tanaka <[email protected]> * Treating promql validation from ParseExpr Signed-off-by: Pedro Tanaka <[email protected]> * fixing funcs Signed-off-by: Pedro Tanaka <[email protected]> --------- Signed-off-by: Pedro Tanaka <[email protected]> Signed-off-by: Pedro Tanaka <[email protected]>
- Loading branch information
1 parent
2dcfd2c
commit 8784785
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.