Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling Scalar Tests #122

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 38 additions & 34 deletions engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package engine_test

import (
"context"
"encoding/json"
"fmt"
"math"
"runtime"
Expand Down Expand Up @@ -820,15 +821,13 @@ func TestQueriesAgainstOldEngine(t *testing.T) {
+ on() group_left()
sum(http_requests_total{ns="nginx"})`,
},
// Result is correct but this likely fails due to https://github.com/golang/go/issues/12025.
// TODO(saswatamcode): Test NaN cases separately. https://github.com/thanos-community/promql-engine/issues/88
// {
// name: "scalar func with NaN",
// load: `load 30s
// http_requests_total{pod="nginx-1"} 1+1x15
// http_requests_total{pod="nginx-2"} 1+2x18`,
// query: `scalar(http_requests_total)`,
// },
{
name: "scalar func with NaN",
load: `load 30s
http_requests_total{pod="nginx-1"} 1+1x15
http_requests_total{pod="nginx-2"} 1+2x18`,
query: `scalar(http_requests_total)`,
},
{
name: "scalar func with aggr",
load: `load 30s
Expand Down Expand Up @@ -933,20 +932,19 @@ func TestQueriesAgainstOldEngine(t *testing.T) {
http_requests_total{pod="nginx-2", le="+Inf"} 4+1x10`,
query: `histogram_quantile(0.9, sum by (pod, le) (http_requests_total))`,
},
// TODO(fpetkovski): Uncomment once support for testing NaNs is added.
//{
// name: "histogram quantile with scalar operator",
// load: `load 30s
// quantile{pod="nginx-1", le="1"} 1+1x2
// http_requests_total{pod="nginx-1", le="1"} 1+3x10
// http_requests_total{pod="nginx-2", le="1"} 2+3x10
// http_requests_total{pod="nginx-1", le="2"} 1+2x10
// http_requests_total{pod="nginx-2", le="2"} 2+2x10
// http_requests_total{pod="nginx-2", le="5"} 3+2x10
// http_requests_total{pod="nginx-1", le="+Inf"} 1+1x10
// http_requests_total{pod="nginx-2", le="+Inf"} 4+1x10`,
// query: `histogram_quantile(scalar(max(quantile)), http_requests_total)`,
//},
{
name: "histogram quantile with scalar operator",
load: `load 30s
quantile{pod="nginx-1", le="1"} 1+1x2
http_requests_total{pod="nginx-1", le="1"} 1+3x10
http_requests_total{pod="nginx-2", le="1"} 2+3x10
http_requests_total{pod="nginx-1", le="2"} 1+2x10
http_requests_total{pod="nginx-2", le="2"} 2+2x10
http_requests_total{pod="nginx-2", le="5"} 3+2x10
http_requests_total{pod="nginx-1", le="+Inf"} 1+1x10
http_requests_total{pod="nginx-2", le="+Inf"} 4+1x10`,
query: `histogram_quantile(scalar(max(quantile)), http_requests_total)`,
},
}

disableOptimizerOpts := []bool{true, false}
Expand Down Expand Up @@ -990,7 +988,7 @@ func TestQueriesAgainstOldEngine(t *testing.T) {
oldResult := q2.Exec(context.Background())
testutil.Ok(t, oldResult.Err)

testutil.Equals(t, oldResult, newResult)
jsonEqual(t, oldResult, newResult)
})
}
})
Expand Down Expand Up @@ -1526,15 +1524,13 @@ func TestInstantQuery(t *testing.T) {
http_requests_total{pod="nginx-2"} 1+2x18`,
query: "sum_over_time(http_requests_total[5m] @ 180 offset 2m)",
},
// Result is correct but this likely fails due to https://github.com/golang/go/issues/12025.
// TODO(saswatamcode): Test NaN cases separately. https://github.com/thanos-community/promql-engine/issues/88
// {
// name: "scalar func with NaN",
// load: `load 30s
// http_requests_total{pod="nginx-1"} 1+1x15
// http_requests_total{pod="nginx-2"} 1+2x18`,
// query: `scalar(http_requests_total)`,
// },
{
name: "scalar func with NaN",
load: `load 30s
http_requests_total{pod="nginx-1"} 1+1x15
http_requests_total{pod="nginx-2"} 1+2x18`,
query: `scalar(http_requests_total)`,
},
{
name: "scalar func with aggr",
load: `load 30s
Expand Down Expand Up @@ -1644,7 +1640,7 @@ func TestInstantQuery(t *testing.T) {
oldResult := q2.Exec(context.Background())
testutil.Ok(t, oldResult.Err)

testutil.Equals(t, oldResult, newResult)
jsonEqual(t, oldResult, newResult)
})
}
})
Expand Down Expand Up @@ -2132,3 +2128,11 @@ func TestEngineRecoversFromPanic(t *testing.T) {
})

}

func jsonEqual(t *testing.T, expected interface{}, actual interface{}) {
e, err := json.Marshal(expected)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could lead to more problems while checking equality. JSON doesn't support NaN or Inf (golang/go#3480). There's also stuff with ordering (golang/go#6244) that could end up as confusing bugs, as labels are marshaled as a map.

Maybe not handling all those complications here and just comparing structs recursively would be better? I raised efficientgo/core#3 a few days ago to add support for NaN. I'll ping @bwplotka for review, and maybe that can be used here instead? WDYT? 🙂

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are blocked by that PR, maybe there's a way to add these cases in a separate test and use a custom comparison function?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup! We can do that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that efficientgo/core#3 is merged, can we enable the tests for NaN values?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldnt we just compare oldResult.String() and newResult.String() for string equality?

testutil.Ok(t, err)
a, err := json.Marshal(actual)
testutil.Ok(t, err)
testutil.Equals(t, e, a)
}