@ -328,12 +328,40 @@ func TestMappingStrings(t *testing.T) {
) ` ,
} ,
{
in : ` avg(avg_over_time( { job=~"myapps.*"} |= "stats" | json busy="utilization" | unwrap busy [5m])) ` ,
out : ` avg(avg_over_time( { job=~"myapps.*"} |= "stats" | json busy="utilization" | unwrap busy [5m])) ` ,
in : ` avg(avg_over_time( { job=~"myapps.*"} |= "stats" | json busy="utilization" | unwrap busy [5m])) ` ,
out : ` (
sum (
downstream < sum ( avg_over_time ( { job = ~ "myapps.*" } |= "stats" | json busy = "utilization" | unwrap busy [ 5 m ] ) ) , shard = 0 _of_2 >
++
downstream < sum ( avg_over_time ( { job = ~ "myapps.*" } |= "stats" | json busy = "utilization" | unwrap busy [ 5 m ] ) ) , shard = 1_ of_2 > )
/
sum (
downstream < count ( avg_over_time ( { job = ~ "myapps.*" } |= "stats" | json busy = "utilization" | unwrap busy [ 5 m ] ) ) , shard = 0 _of_2 >
++
downstream < count ( avg_over_time ( { job = ~ "myapps.*" } |= "stats" | json busy = "utilization" | unwrap busy [ 5 m ] ) ) , shard = 1_ of_2 >
)
) ` ,
} ,
{
in : ` avg_over_time( { job=~"myapps.*"} |= "stats" | json busy="utilization" | unwrap busy [5m]) ` ,
out : ` avg_over_time( { job=~"myapps.*"} |= "stats" | json busy="utilization" | unwrap busy [5m]) ` ,
in : ` avg_over_time( { job=~"myapps.*"} |= "stats" | json busy="utilization" | unwrap busy [5m]) ` ,
out : ` downstream < avg_over_time ( { job = ~ "myapps.*" } |= "stats" | json busy = "utilization" | unwrap busy [ 5 m ] ) , shard = 0 _of_2 >
++ downstream < avg_over_time ( { job = ~ "myapps.*" } |= "stats" | json busy = "utilization" | unwrap busy [ 5 m ] ) , shard = 1_ of_2 > ` ,
} ,
{
in : ` avg_over_time( { job=~"myapps.*"} |= "stats" | json busy="utilization" | unwrap busy [5m]) by (cluster) ` ,
out : ` (
sum by ( cluster ) (
downstream < sum by ( cluster ) ( sum_over_time ( { job = ~ "myapps.*" } |= "stats" | json busy = "utilization" | unwrap busy [ 5 m ] ) ) , shard = 0 _of_2 >
++
downstream < sum by ( cluster ) ( sum_over_time ( { job = ~ "myapps.*" } |= "stats" | json busy = "utilization" | unwrap busy [ 5 m ] ) ) , shard = 1_ of_2 >
)
/
sum by ( cluster ) (
downstream < sum by ( cluster ) ( count_over_time ( { job = ~ "myapps.*" } |= "stats" | json busy = "utilization" [ 5 m ] ) ) , shard = 0 _of_2 >
++
downstream < sum by ( cluster ) ( count_over_time ( { job = ~ "myapps.*" } |= "stats" | json busy = "utilization" [ 5 m ] ) ) , shard = 1_ of_2 >
)
) ` ,
} ,
// should be noop if VectorExpr
{
@ -1180,6 +1208,124 @@ func TestMapping(t *testing.T) {
} ,
} ,
} ,
{
in : ` avg_over_time( { foo="bar"} | unwrap bytes [5m]) by (cluster) ` ,
expr : & syntax . BinOpExpr {
Op : syntax . OpTypeDiv ,
SampleExpr : & syntax . VectorAggregationExpr {
Grouping : & syntax . Grouping {
Groups : [ ] string { "cluster" } ,
} ,
Operation : syntax . OpTypeSum ,
Left : & ConcatSampleExpr {
DownstreamSampleExpr : DownstreamSampleExpr {
shard : & astmapper . ShardAnnotation {
Shard : 0 ,
Of : 2 ,
} ,
SampleExpr : & syntax . VectorAggregationExpr {
Grouping : & syntax . Grouping {
Groups : [ ] string { "cluster" } ,
} ,
Operation : syntax . OpTypeSum ,
Left : & syntax . RangeAggregationExpr {
Operation : syntax . OpRangeTypeSum ,
Left : & syntax . LogRange {
Left : & syntax . MatchersExpr {
Mts : [ ] * labels . Matcher { mustNewMatcher ( labels . MatchEqual , "foo" , "bar" ) } ,
} ,
Interval : 5 * time . Minute ,
Unwrap : & syntax . UnwrapExpr {
Identifier : "bytes" ,
} ,
} ,
} ,
} ,
} ,
next : & ConcatSampleExpr {
DownstreamSampleExpr : DownstreamSampleExpr {
shard : & astmapper . ShardAnnotation {
Shard : 1 ,
Of : 2 ,
} ,
SampleExpr : & syntax . VectorAggregationExpr {
Grouping : & syntax . Grouping {
Groups : [ ] string { "cluster" } ,
} ,
Operation : syntax . OpTypeSum ,
Left : & syntax . RangeAggregationExpr {
Operation : syntax . OpRangeTypeSum ,
Left : & syntax . LogRange {
Left : & syntax . MatchersExpr {
Mts : [ ] * labels . Matcher { mustNewMatcher ( labels . MatchEqual , "foo" , "bar" ) } ,
} ,
Interval : 5 * time . Minute ,
Unwrap : & syntax . UnwrapExpr {
Identifier : "bytes" ,
} ,
} ,
} ,
} ,
} ,
next : nil ,
} ,
} ,
} ,
RHS : & syntax . VectorAggregationExpr {
Operation : syntax . OpTypeSum ,
Grouping : & syntax . Grouping {
Groups : [ ] string { "cluster" } ,
} ,
Left : & ConcatSampleExpr {
DownstreamSampleExpr : DownstreamSampleExpr {
shard : & astmapper . ShardAnnotation {
Shard : 0 ,
Of : 2 ,
} ,
SampleExpr : & syntax . VectorAggregationExpr {
Grouping : & syntax . Grouping {
Groups : [ ] string { "cluster" } ,
} ,
Operation : syntax . OpTypeSum ,
Left : & syntax . RangeAggregationExpr {
Operation : syntax . OpRangeTypeCount ,
Left : & syntax . LogRange {
Left : & syntax . MatchersExpr {
Mts : [ ] * labels . Matcher { mustNewMatcher ( labels . MatchEqual , "foo" , "bar" ) } ,
} ,
Interval : 5 * time . Minute ,
} ,
} ,
} ,
} ,
next : & ConcatSampleExpr {
DownstreamSampleExpr : DownstreamSampleExpr {
shard : & astmapper . ShardAnnotation {
Shard : 1 ,
Of : 2 ,
} ,
SampleExpr : & syntax . VectorAggregationExpr {
Grouping : & syntax . Grouping {
Groups : [ ] string { "cluster" } ,
} ,
Operation : syntax . OpTypeSum ,
Left : & syntax . RangeAggregationExpr {
Operation : syntax . OpRangeTypeCount ,
Left : & syntax . LogRange {
Left : & syntax . MatchersExpr {
Mts : [ ] * labels . Matcher { mustNewMatcher ( labels . MatchEqual , "foo" , "bar" ) } ,
} ,
Interval : 5 * time . Minute ,
} ,
} ,
} ,
} ,
next : nil ,
} ,
} ,
} ,
} ,
} ,
} {
t . Run ( tc . in , func ( t * testing . T ) {
ast , err := syntax . ParseExpr ( tc . in )