-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix metric name extracting in AggKey
Co-authored-by: msaf1980 <[email protected]>
- Loading branch information
1 parent
6b03de9
commit d77e3ee
Showing
6 changed files
with
194 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,10 @@ func TestExtractName(t *testing.T) { | |
"sum(seriesByTag('tag2=value*', 'name=metric'))", | ||
"seriesByTag('tag2=value*', 'name=metric')", | ||
}, | ||
{ | ||
"sum(metric.name;tag=value)", | ||
"metric.name;tag=value", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
|
@@ -98,3 +102,108 @@ func TestExtractName(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestExtractNameTag(t *testing.T) { | ||
var tests = []struct { | ||
input string | ||
metric string | ||
}{ | ||
{ | ||
"f", | ||
"f", | ||
}, | ||
{ | ||
"func(f)", | ||
"f", | ||
}, | ||
{ | ||
"foo.bar.baz", | ||
"foo.bar.baz", | ||
}, | ||
{ | ||
"nonNegativeDerivative(foo.bar.baz)", | ||
"foo.bar.baz", | ||
}, | ||
{ | ||
"movingAverage(foo.bar.baz,10)", | ||
"foo.bar.baz", | ||
}, | ||
{ | ||
"scale(scaleToSeconds(nonNegativeDerivative(foo.bar.baz),60),60)", | ||
"foo.bar.baz", | ||
}, | ||
{ | ||
"divideSeries(foo.bar.baz,baz.qux.zot)", | ||
"foo.bar.baz", | ||
}, | ||
{ | ||
"{something}", | ||
"{something}", | ||
}, | ||
{ | ||
"ab=", | ||
"ab=", | ||
}, | ||
{ | ||
"ab=.c", | ||
"ab=.c", | ||
}, | ||
{ | ||
"ab==", | ||
"ab==", | ||
}, | ||
{ | ||
"scale(scaleToSeconds(nonNegativeDerivative(ab==.c),60),60)", | ||
"ab==.c", | ||
}, | ||
{ | ||
"divideSeries(metric[12])", | ||
"metric[12]", | ||
}, | ||
{ | ||
"average(metric{1,2}e,'sum')", | ||
"metric{1,2}e", | ||
}, | ||
{ | ||
"aliasByNode(alias([email protected], 2), 1)", | ||
"[email protected]", | ||
}, | ||
{ | ||
"aliasByTags(alias([email protected], 2), 1)", | ||
"[email protected]", | ||
}, | ||
// non-ASCII symbols | ||
{ | ||
"alias(Количество изменений)", | ||
"Количество изменений", | ||
}, | ||
{ | ||
"some(Количество изменений, Аргумент)", | ||
"Количество изменений", | ||
}, | ||
{ | ||
"seriesByTag('tag2=value*', 'name=metric')", | ||
"seriesByTag('tag2=value*', 'name=metric')", | ||
}, | ||
{ | ||
"sum(seriesByTag('tag2=value*', 'name=metric'))", | ||
"seriesByTag('tag2=value*', 'name=metric')", | ||
}, | ||
{ | ||
"sum(metric.name;tag=value)", | ||
"metric.name", | ||
}, | ||
{ | ||
"metric1.foo==.bar.baz", | ||
"metric1.foo==.bar.baz", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.input, func(t *testing.T) { | ||
if m := ExtractNameTag(tt.input); m != tt.metric { | ||
t.Errorf("ExtractNameTag(%q)=%q, want %q", tt.input, m, tt.metric) | ||
} | ||
}) | ||
} | ||
} |