@ -314,271 +314,271 @@ func TestSelectHintsSetCorrectly(t *testing.T) {
{
query : "foo" , start : 10000 ,
expected : [ ] * storage . SelectHints {
{ Start : 5000 , End : 10000 } ,
{ Start : 5001 , End : 10000 } ,
} ,
} , {
query : "foo @ 15" , start : 10000 ,
expected : [ ] * storage . SelectHints {
{ Start : 10000 , End : 15000 } ,
{ Start : 10001 , End : 15000 } ,
} ,
} , {
query : "foo @ 1" , start : 10000 ,
expected : [ ] * storage . SelectHints {
{ Start : - 4000 , End : 1000 } ,
{ Start : - 3999 , End : 1000 } ,
} ,
} , {
query : "foo[2m]" , start : 200000 ,
expected : [ ] * storage . SelectHints {
{ Start : 80000 , End : 200000 , Range : 120000 } ,
{ Start : 80001 , End : 200000 , Range : 120000 } ,
} ,
} , {
query : "foo[2m] @ 180" , start : 200000 ,
expected : [ ] * storage . SelectHints {
{ Start : 60000 , End : 180000 , Range : 120000 } ,
{ Start : 60001 , End : 180000 , Range : 120000 } ,
} ,
} , {
query : "foo[2m] @ 300" , start : 200000 ,
expected : [ ] * storage . SelectHints {
{ Start : 180000 , End : 300000 , Range : 120000 } ,
{ Start : 180001 , End : 300000 , Range : 120000 } ,
} ,
} , {
query : "foo[2m] @ 60" , start : 200000 ,
expected : [ ] * storage . SelectHints {
{ Start : - 60000 , End : 60000 , Range : 120000 } ,
{ Start : - 59999 , End : 60000 , Range : 120000 } ,
} ,
} , {
query : "foo[2m] offset 2m" , start : 300000 ,
expected : [ ] * storage . SelectHints {
{ Start : 60000 , End : 180000 , Range : 120000 } ,
{ Start : 60001 , End : 180000 , Range : 120000 } ,
} ,
} , {
query : "foo[2m] @ 200 offset 2m" , start : 300000 ,
expected : [ ] * storage . SelectHints {
{ Start : - 40000 , End : 80000 , Range : 120000 } ,
{ Start : - 39999 , End : 80000 , Range : 120000 } ,
} ,
} , {
query : "foo[2m:1s]" , start : 300000 ,
expected : [ ] * storage . SelectHints {
{ Start : 175000 , End : 300000 , Step : 1000 } ,
{ Start : 175001 , End : 300000 , Step : 1000 } ,
} ,
} , {
query : "count_over_time(foo[2m:1s])" , start : 300000 ,
expected : [ ] * storage . SelectHints {
{ Start : 175000 , End : 300000 , Func : "count_over_time" , Step : 1000 } ,
{ Start : 175001 , End : 300000 , Func : "count_over_time" , Step : 1000 } ,
} ,
} , {
query : "count_over_time(foo[2m:1s] @ 300)" , start : 200000 ,
expected : [ ] * storage . SelectHints {
{ Start : 175000 , End : 300000 , Func : "count_over_time" , Step : 1000 } ,
{ Start : 175001 , End : 300000 , Func : "count_over_time" , Step : 1000 } ,
} ,
} , {
query : "count_over_time(foo[2m:1s] @ 200)" , start : 200000 ,
expected : [ ] * storage . SelectHints {
{ Start : 75000 , End : 200000 , Func : "count_over_time" , Step : 1000 } ,
{ Start : 75001 , End : 200000 , Func : "count_over_time" , Step : 1000 } ,
} ,
} , {
query : "count_over_time(foo[2m:1s] @ 100)" , start : 200000 ,
expected : [ ] * storage . SelectHints {
{ Start : - 25000 , End : 100000 , Func : "count_over_time" , Step : 1000 } ,
{ Start : - 24999 , End : 100000 , Func : "count_over_time" , Step : 1000 } ,
} ,
} , {
query : "count_over_time(foo[2m:1s] offset 10s)" , start : 300000 ,
expected : [ ] * storage . SelectHints {
{ Start : 165000 , End : 290000 , Func : "count_over_time" , Step : 1000 } ,
{ Start : 165001 , End : 290000 , Func : "count_over_time" , Step : 1000 } ,
} ,
} , {
query : "count_over_time((foo offset 10s)[2m:1s] offset 10s)" , start : 300000 ,
expected : [ ] * storage . SelectHints {
{ Start : 155000 , End : 280000 , Func : "count_over_time" , Step : 1000 } ,
{ Start : 155001 , End : 280000 , Func : "count_over_time" , Step : 1000 } ,
} ,
} , {
// When the @ is on the vector selector, the enclosing subquery parameters
// don't affect the hint ranges.
query : "count_over_time((foo @ 200 offset 10s)[2m:1s] offset 10s)" , start : 300000 ,
expected : [ ] * storage . SelectHints {
{ Start : 185000 , End : 190000 , Func : "count_over_time" , Step : 1000 } ,
{ Start : 185001 , End : 190000 , Func : "count_over_time" , Step : 1000 } ,
} ,
} , {
// When the @ is on the vector selector, the enclosing subquery parameters
// don't affect the hint ranges.
query : "count_over_time((foo @ 200 offset 10s)[2m:1s] @ 100 offset 10s)" , start : 300000 ,
expected : [ ] * storage . SelectHints {
{ Start : 185000 , End : 190000 , Func : "count_over_time" , Step : 1000 } ,
{ Start : 185001 , End : 190000 , Func : "count_over_time" , Step : 1000 } ,
} ,
} , {
query : "count_over_time((foo offset 10s)[2m:1s] @ 100 offset 10s)" , start : 300000 ,
expected : [ ] * storage . SelectHints {
{ Start : - 45000 , End : 80000 , Func : "count_over_time" , Step : 1000 } ,
{ Start : - 44999 , End : 80000 , Func : "count_over_time" , Step : 1000 } ,
} ,
} , {
query : "foo" , start : 10000 , end : 20000 ,
expected : [ ] * storage . SelectHints {
{ Start : 5000 , End : 20000 , Step : 1000 } ,
{ Start : 5001 , End : 20000 , Step : 1000 } ,
} ,
} , {
query : "foo @ 15" , start : 10000 , end : 20000 ,
expected : [ ] * storage . SelectHints {
{ Start : 10000 , End : 15000 , Step : 1000 } ,
{ Start : 10001 , End : 15000 , Step : 1000 } ,
} ,
} , {
query : "foo @ 1" , start : 10000 , end : 20000 ,
expected : [ ] * storage . SelectHints {
{ Start : - 4000 , End : 1000 , Step : 1000 } ,
{ Start : - 3999 , End : 1000 , Step : 1000 } ,
} ,
} , {
query : "rate(foo[2m] @ 180)" , start : 200000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : 60000 , End : 180000 , Range : 120000 , Func : "rate" , Step : 1000 } ,
{ Start : 60001 , End : 180000 , Range : 120000 , Func : "rate" , Step : 1000 } ,
} ,
} , {
query : "rate(foo[2m] @ 300)" , start : 200000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : 180000 , End : 300000 , Range : 120000 , Func : "rate" , Step : 1000 } ,
{ Start : 180001 , End : 300000 , Range : 120000 , Func : "rate" , Step : 1000 } ,
} ,
} , {
query : "rate(foo[2m] @ 60)" , start : 200000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : - 60000 , End : 60000 , Range : 120000 , Func : "rate" , Step : 1000 } ,
{ Start : - 59999 , End : 60000 , Range : 120000 , Func : "rate" , Step : 1000 } ,
} ,
} , {
query : "rate(foo[2m])" , start : 200000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : 80000 , End : 500000 , Range : 120000 , Func : "rate" , Step : 1000 } ,
{ Start : 80001 , End : 500000 , Range : 120000 , Func : "rate" , Step : 1000 } ,
} ,
} , {
query : "rate(foo[2m] offset 2m)" , start : 300000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : 60000 , End : 380000 , Range : 120000 , Func : "rate" , Step : 1000 } ,
{ Start : 60001 , End : 380000 , Range : 120000 , Func : "rate" , Step : 1000 } ,
} ,
} , {
query : "rate(foo[2m:1s])" , start : 300000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : 175000 , End : 500000 , Func : "rate" , Step : 1000 } ,
{ Start : 175001 , End : 500000 , Func : "rate" , Step : 1000 } ,
} ,
} , {
query : "count_over_time(foo[2m:1s])" , start : 300000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : 175000 , End : 500000 , Func : "count_over_time" , Step : 1000 } ,
{ Start : 175001 , End : 500000 , Func : "count_over_time" , Step : 1000 } ,
} ,
} , {
query : "count_over_time(foo[2m:1s] offset 10s)" , start : 300000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : 165000 , End : 490000 , Func : "count_over_time" , Step : 1000 } ,
{ Start : 165001 , End : 490000 , Func : "count_over_time" , Step : 1000 } ,
} ,
} , {
query : "count_over_time(foo[2m:1s] @ 300)" , start : 200000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : 175000 , End : 300000 , Func : "count_over_time" , Step : 1000 } ,
{ Start : 175001 , End : 300000 , Func : "count_over_time" , Step : 1000 } ,
} ,
} , {
query : "count_over_time(foo[2m:1s] @ 200)" , start : 200000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : 75000 , End : 200000 , Func : "count_over_time" , Step : 1000 } ,
{ Start : 75001 , End : 200000 , Func : "count_over_time" , Step : 1000 } ,
} ,
} , {
query : "count_over_time(foo[2m:1s] @ 100)" , start : 200000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : - 25000 , End : 100000 , Func : "count_over_time" , Step : 1000 } ,
{ Start : - 24999 , End : 100000 , Func : "count_over_time" , Step : 1000 } ,
} ,
} , {
query : "count_over_time((foo offset 10s)[2m:1s] offset 10s)" , start : 300000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : 155000 , End : 480000 , Func : "count_over_time" , Step : 1000 } ,
{ Start : 155001 , End : 480000 , Func : "count_over_time" , Step : 1000 } ,
} ,
} , {
// When the @ is on the vector selector, the enclosing subquery parameters
// don't affect the hint ranges.
query : "count_over_time((foo @ 200 offset 10s)[2m:1s] offset 10s)" , start : 300000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : 185000 , End : 190000 , Func : "count_over_time" , Step : 1000 } ,
{ Start : 185001 , End : 190000 , Func : "count_over_time" , Step : 1000 } ,
} ,
} , {
// When the @ is on the vector selector, the enclosing subquery parameters
// don't affect the hint ranges.
query : "count_over_time((foo @ 200 offset 10s)[2m:1s] @ 100 offset 10s)" , start : 300000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : 185000 , End : 190000 , Func : "count_over_time" , Step : 1000 } ,
{ Start : 185001 , End : 190000 , Func : "count_over_time" , Step : 1000 } ,
} ,
} , {
query : "count_over_time((foo offset 10s)[2m:1s] @ 100 offset 10s)" , start : 300000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : - 45000 , End : 80000 , Func : "count_over_time" , Step : 1000 } ,
{ Start : - 44999 , End : 80000 , Func : "count_over_time" , Step : 1000 } ,
} ,
} , {
query : "sum by (dim1) (foo)" , start : 10000 ,
expected : [ ] * storage . SelectHints {
{ Start : 5000 , End : 10000 , Func : "sum" , By : true , Grouping : [ ] string { "dim1" } } ,
{ Start : 5001 , End : 10000 , Func : "sum" , By : true , Grouping : [ ] string { "dim1" } } ,
} ,
} , {
query : "sum without (dim1) (foo)" , start : 10000 ,
expected : [ ] * storage . SelectHints {
{ Start : 5000 , End : 10000 , Func : "sum" , Grouping : [ ] string { "dim1" } } ,
{ Start : 5001 , End : 10000 , Func : "sum" , Grouping : [ ] string { "dim1" } } ,
} ,
} , {
query : "sum by (dim1) (avg_over_time(foo[1s]))" , start : 10000 ,
expected : [ ] * storage . SelectHints {
{ Start : 9000 , End : 10000 , Func : "avg_over_time" , Range : 1000 } ,
{ Start : 9001 , End : 10000 , Func : "avg_over_time" , Range : 1000 } ,
} ,
} , {
query : "sum by (dim1) (max by (dim2) (foo))" , start : 10000 ,
expected : [ ] * storage . SelectHints {
{ Start : 5000 , End : 10000 , Func : "max" , By : true , Grouping : [ ] string { "dim2" } } ,
{ Start : 5001 , End : 10000 , Func : "max" , By : true , Grouping : [ ] string { "dim2" } } ,
} ,
} , {
query : "(max by (dim1) (foo))[5s:1s]" , start : 10000 ,
expected : [ ] * storage . SelectHints {
{ Start : 0 , End : 10000 , Func : "max" , By : true , Grouping : [ ] string { "dim1" } , Step : 1000 } ,
{ Start : 1 , End : 10000 , Func : "max" , By : true , Grouping : [ ] string { "dim1" } , Step : 1000 } ,
} ,
} , {
query : "(sum(http_requests{group=~\"p.*\"})+max(http_requests{group=~\"c.*\"}))[20s:5s]" , start : 120000 ,
expected : [ ] * storage . SelectHints {
{ Start : 95000 , End : 120000 , Func : "sum" , By : true , Step : 5000 } ,
{ Start : 95000 , End : 120000 , Func : "max" , By : true , Step : 5000 } ,
{ Start : 95001 , End : 120000 , Func : "sum" , By : true , Step : 5000 } ,
{ Start : 95001 , End : 120000 , Func : "max" , By : true , Step : 5000 } ,
} ,
} , {
query : "foo @ 50 + bar @ 250 + baz @ 900" , start : 100000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : 45000 , End : 50000 , Step : 1000 } ,
{ Start : 245000 , End : 250000 , Step : 1000 } ,
{ Start : 895000 , End : 900000 , Step : 1000 } ,
{ Start : 45001 , End : 50000 , Step : 1000 } ,
{ Start : 245001 , End : 250000 , Step : 1000 } ,
{ Start : 895001 , End : 900000 , Step : 1000 } ,
} ,
} , {
query : "foo @ 50 + bar + baz @ 900" , start : 100000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : 45000 , End : 50000 , Step : 1000 } ,
{ Start : 95000 , End : 500000 , Step : 1000 } ,
{ Start : 895000 , End : 900000 , Step : 1000 } ,
{ Start : 45001 , End : 50000 , Step : 1000 } ,
{ Start : 95001 , End : 500000 , Step : 1000 } ,
{ Start : 895001 , End : 900000 , Step : 1000 } ,
} ,
} , {
query : "rate(foo[2s] @ 50) + bar @ 250 + baz @ 900" , start : 100000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : 48000 , End : 50000 , Step : 1000 , Func : "rate" , Range : 2000 } ,
{ Start : 245000 , End : 250000 , Step : 1000 } ,
{ Start : 895000 , End : 900000 , Step : 1000 } ,
{ Start : 48001 , End : 50000 , Step : 1000 , Func : "rate" , Range : 2000 } ,
{ Start : 245001 , End : 250000 , Step : 1000 } ,
{ Start : 895001 , End : 900000 , Step : 1000 } ,
} ,
} , {
query : "rate(foo[2s:1s] @ 50) + bar + baz" , start : 100000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : 43000 , End : 50000 , Step : 1000 , Func : "rate" } ,
{ Start : 95000 , End : 500000 , Step : 1000 } ,
{ Start : 95000 , End : 500000 , Step : 1000 } ,
{ Start : 43001 , End : 50000 , Step : 1000 , Func : "rate" } ,
{ Start : 95001 , End : 500000 , Step : 1000 } ,
{ Start : 95001 , End : 500000 , Step : 1000 } ,
} ,
} , {
query : "rate(foo[2s:1s] @ 50) + bar + rate(baz[2m:1s] @ 900 offset 2m) " , start : 100000 , end : 500000 ,
expected : [ ] * storage . SelectHints {
{ Start : 43000 , End : 50000 , Step : 1000 , Func : "rate" } ,
{ Start : 95000 , End : 500000 , Step : 1000 } ,
{ Start : 655000 , End : 780000 , Step : 1000 , Func : "rate" } ,
{ Start : 43001 , End : 50000 , Step : 1000 , Func : "rate" } ,
{ Start : 95001 , End : 500000 , Step : 1000 } ,
{ Start : 655001 , End : 780000 , Step : 1000 , Func : "rate" } ,
} ,
} , { // Hints are based on the inner most subquery timestamp.
query : ` sum_over_time(sum_over_time(metric { job="1"}[100s])[100s:25s] @ 50)[3s:1s] @ 3000 ` , start : 100000 ,
expected : [ ] * storage . SelectHints {
{ Start : - 150000 , End : 50000 , Range : 100000 , Func : "sum_over_time" , Step : 25000 } ,
{ Start : - 149999 , End : 50000 , Range : 100000 , Func : "sum_over_time" , Step : 25000 } ,
} ,
} , { // Hints are based on the inner most subquery timestamp.
query : ` sum_over_time(sum_over_time(metric { job="1"}[100s])[100s:25s] @ 3000)[3s:1s] @ 50 ` ,
expected : [ ] * storage . SelectHints {
{ Start : 2800000 , End : 3000000 , Range : 100000 , Func : "sum_over_time" , Step : 25000 } ,
{ Start : 2800001 , End : 3000000 , Range : 100000 , Func : "sum_over_time" , Step : 25000 } ,
} ,
} ,
} {
@ -4904,43 +4904,43 @@ metric 0 1 2
} {
{
name : "default lookback delta" ,
ts : lastDatapointTs . Add ( defaultLookbackDelta ) ,
ts : lastDatapointTs . Add ( defaultLookbackDelta - time . Millisecond ) ,
expectSamples : true ,
} ,
{
name : "outside default lookback delta" ,
ts : lastDatapointTs . Add ( defaultLookbackDelta + time . Millisecond ) ,
ts : lastDatapointTs . Add ( defaultLookbackDelta ) ,
expectSamples : false ,
} ,
{
name : "custom engine lookback delta" ,
ts : lastDatapointTs . Add ( 10 * time . Minute ) ,
ts : lastDatapointTs . Add ( 10 * time . Minute - time . Millisecond ) ,
engineLookback : 10 * time . Minute ,
expectSamples : true ,
} ,
{
name : "outside custom engine lookback delta" ,
ts : lastDatapointTs . Add ( 10 * time . Minute + time . Millisecond ) ,
ts : lastDatapointTs . Add ( 10 * time . Minute ) ,
engineLookback : 10 * time . Minute ,
expectSamples : false ,
} ,
{
name : "custom query lookback delta" ,
ts : lastDatapointTs . Add ( 20 * time . Minute ) ,
ts : lastDatapointTs . Add ( 20 * time . Minute - time . Millisecond ) ,
engineLookback : 10 * time . Minute ,
queryLookback : 20 * time . Minute ,
expectSamples : true ,
} ,
{
name : "outside custom query lookback delta" ,
ts : lastDatapointTs . Add ( 20 * time . Minute + time . Millisecond ) ,
ts : lastDatapointTs . Add ( 20 * time . Minute ) ,
engineLookback : 10 * time . Minute ,
queryLookback : 20 * time . Minute ,
expectSamples : false ,
} ,
{
name : "negative custom query lookback delta" ,
ts : lastDatapointTs . Add ( 20 * time . Minute ) ,
ts : lastDatapointTs . Add ( 20 * time . Minute - time . Millisecond ) ,
engineLookback : - 10 * time . Minute ,
queryLookback : 20 * time . Minute ,
expectSamples : true ,