Skip to content

Commit

Permalink
e2e/query_frontend: add tests for explain/analyze (#7160)
Browse files Browse the repository at this point in the history
Adding tests for explain/analyze with QFE. Will add fixes as separate
PR.

Signed-off-by: Giedrius Statkevičius <[email protected]>
  • Loading branch information
GiedriusS authored Feb 23, 2024
1 parent ed44e01 commit 508d82e
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions test/e2e/query_frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import (
"context"
"crypto/sha256"
"fmt"
"io"
"net/http"
"net/http/httptest"
"reflect"
"regexp"
"sort"
"strings"
"testing"
"time"

Expand All @@ -25,6 +28,7 @@ import (
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/timestamp"
"github.com/prometheus/prometheus/prompb"
"github.com/stretchr/testify/require"

"github.com/thanos-io/thanos/pkg/cacheutil"
"github.com/thanos-io/thanos/pkg/promclient"
Expand Down Expand Up @@ -1139,3 +1143,62 @@ func TestTenantQFEHTTPMetrics(t *testing.T) {
e2emon.WaitMissingMetrics(),
))
}

func TestQueryFrontendExplain(t *testing.T) {
t.Parallel()

e, err := e2e.NewDockerEnvironment("qfe-explain")
testutil.Ok(t, err)
t.Cleanup(e2ethanos.CleanScenario(t, e))

q := e2ethanos.NewQuerierBuilder(e, "1").Init()
testutil.Ok(t, e2e.StartAndWaitReady(q))

qfe := e2ethanos.NewQueryFrontend(e, "1", "http://"+q.InternalEndpoint("http"), queryfrontend.Config{}, queryfrontend.CacheProviderConfig{
Type: queryfrontend.INMEMORY,
})
testutil.Ok(t, e2e.StartAndWaitReady(qfe))

resp, err := http.Get(fmt.Sprintf("http://%s/api/v1/query_explain?query=time()&engine=thanos", qfe.Endpoint("http")))
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, resp.Body.Close()) })

body, err := io.ReadAll(resp.Body)
require.NoError(t, err)

require.Equal(t, http.StatusOK, resp.StatusCode)
require.Equal(t, `{"status":"success","data":{"name":"[noArgFunction] time()"}}`, strings.TrimSpace(string(body)))
}

func TestQueryFrontendAnalyze(t *testing.T) {
t.Parallel()

e, err := e2e.NewDockerEnvironment("qfe-analyze")
testutil.Ok(t, err)
t.Cleanup(e2ethanos.CleanScenario(t, e))

q := e2ethanos.NewQuerierBuilder(e, "1").Init()
testutil.Ok(t, e2e.StartAndWaitReady(q))

qfe := e2ethanos.NewQueryFrontend(e, "1", "http://"+q.InternalEndpoint("http"), queryfrontend.Config{}, queryfrontend.CacheProviderConfig{
Type: queryfrontend.INMEMORY,
})
testutil.Ok(t, e2e.StartAndWaitReady(qfe))

resp, err := http.Get(fmt.Sprintf("http://%s/api/v1/query?query=time()&engine=thanos&analyze=true", qfe.Endpoint("http")))
require.NoError(t, err)
t.Cleanup(func() { require.NoError(t, resp.Body.Close()) })

body, err := io.ReadAll(resp.Body)
require.NoError(t, err)

require.Equal(t, http.StatusOK, resp.StatusCode)

r := regexp.MustCompile(
`{"status":"success","data":{"resultType":"scalar","result":\[.+,".+"\],"analysis":{"name":"\[duplicateLabelCheck\]","executionTime":".+"}}}`,
)
t.Log(strings.TrimSpace(string(body)))

// TODO(Giedrius): fix.
require.NotEqual(t, true, r.MatchString(strings.TrimSpace(string(body))))
}

0 comments on commit 508d82e

Please sign in to comment.