Skip to content

Commit

Permalink
Add tests for case where range vector selectors and subqueries have 0…
Browse files Browse the repository at this point in the history
… range
  • Loading branch information
charleskorn committed Feb 5, 2025
1 parent 2a3642d commit 87c8b4d
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions pkg/streamingpromql/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func TestRangeVectorSelectors(t *testing.T) {
expected *promql.Result
ts time.Time
}{
"matches series with points in range": {
"floats: matches series with points in range": {
expr: "some_metric[1m1s]",
ts: baseT.Add(2 * time.Minute),
expected: &promql.Result{
Expand All @@ -419,21 +419,21 @@ func TestRangeVectorSelectors(t *testing.T) {
},
},
},
"matches no series": {
"floats: matches no series": {
expr: "some_nonexistent_metric[1m]",
ts: baseT,
expected: &promql.Result{
Value: promql.Matrix{},
},
},
"no samples in range": {
"floats: no samples in range": {
expr: "some_metric[1m]",
ts: baseT.Add(20 * time.Minute),
expected: &promql.Result{
Value: promql.Matrix{},
},
},
"does not return points outside range if last selected point does not align to end of range": {
"floats: does not return points outside range if last selected point does not align to end of range": {
expr: "some_metric_with_gaps[1m1s]",
ts: baseT.Add(2 * time.Minute),
expected: &promql.Result{
Expand All @@ -447,7 +447,7 @@ func TestRangeVectorSelectors(t *testing.T) {
},
},
},
"metric with stale marker": {
"floats: metric with stale marker": {
expr: "some_metric_with_stale_marker[3m1s]",
ts: baseT.Add(3 * time.Minute),
expected: &promql.Result{
Expand All @@ -463,7 +463,14 @@ func TestRangeVectorSelectors(t *testing.T) {
},
},
},
"histogram: matches series with points in range": {
"floats: 0 length range": {
expr: "some_metric[0]",
ts: baseT.Add(2 * time.Minute),
expected: &promql.Result{
Value: promql.Matrix{},
},
},
"histograms: matches series with points in range": {
expr: "incr_histogram[1m1s]",
ts: baseT.Add(2 * time.Minute),
expected: &promql.Result{
Expand Down Expand Up @@ -549,14 +556,14 @@ func TestRangeVectorSelectors(t *testing.T) {
},
},
},
"histogram: no samples in range": {
"histograms: no samples in range": {
expr: "incr_histogram[1m]",
ts: baseT.Add(20 * time.Minute),
expected: &promql.Result{
Value: promql.Matrix{},
},
},
"histogram: does not return points outside range if last selected point does not align to end of range": {
"histograms: does not return points outside range if last selected point does not align to end of range": {
expr: "histogram_with_gaps[1m1s]",
ts: baseT.Add(2 * time.Minute),
expected: &promql.Result{
Expand Down Expand Up @@ -586,7 +593,7 @@ func TestRangeVectorSelectors(t *testing.T) {
},
},
},
"histogram: metric with stale marker": {
"histograms: metric with stale marker": {
expr: "histogram_with_stale_marker[3m1s]",
ts: baseT.Add(3 * time.Minute),
expected: &promql.Result{
Expand Down Expand Up @@ -650,6 +657,13 @@ func TestRangeVectorSelectors(t *testing.T) {
},
},
},
"histograms: 0 length range": {
expr: "incr_histogram[0]",
ts: baseT.Add(2 * time.Minute),
expected: &promql.Result{
Value: promql.Matrix{},
},
},
"mixed series with histograms and floats": {
expr: "mixed_metric[4m]",
ts: baseT.Add(4 * time.Minute),
Expand Down Expand Up @@ -1086,6 +1100,13 @@ func TestSubqueries(t *testing.T) {
},
Start: time.Unix(35, 0),
},
{
Query: "metric[0:5s]",
Result: promql.Result{
Value: promql.Matrix{},
},
Start: time.Unix(10, 0),
},
{ // Normal selector.
Query: `http_requests{group=~"pro.*",instance="0"}[30s:10s]`,
Result: promql.Result{
Expand Down

0 comments on commit 87c8b4d

Please sign in to comment.