Skip to content

Commit

Permalink
Add E2E test for query frontend
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Ye <[email protected]>
  • Loading branch information
yeya24 committed Aug 6, 2020
1 parent cfd07d0 commit 49842f5
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cmd/thanos/query-frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package main

import (
"github.com/prometheus/common/model"
"github.com/go-kit/kit/log/level"
"time"

"github.com/cortexproject/cortex/pkg/querier/frontend"
Expand All @@ -14,6 +14,7 @@ import (
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/prometheus/common/route"
"gopkg.in/alecthomas/kingpin.v2"

Expand Down Expand Up @@ -177,5 +178,7 @@ func runQueryFrontend(
})
}

level.Info(logger).Log("msg", "starting query frontend")
statusProber.Ready()
return nil
}
22 changes: 22 additions & 0 deletions test/e2e/e2ethanos/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,25 @@ func NewCompactor(sharedDir string, name string, bucketConfig client.BucketConfi

return compactor, nil
}

func NewQueryFrontend(sharedDir string, name string, downstreamURL string) (*e2e.HTTPService, error) {
args := e2e.BuildArgs(map[string]string{
"--debug.name": fmt.Sprintf("query-frontend-%s", name),
"--http-address": ":8080",
"--query-frontend.downstream-url": downstreamURL,
"--query-range.cache-results": "",
"--log.level": logLevel,
})

queryFrontend := e2e.NewHTTPService(
fmt.Sprintf("query-frontend-%s", name),
DefaultImage(),
e2e.NewCommand("query-frontend", args...),
e2e.NewHTTPReadinessProbe(8080, "/-/ready", 200, 200),
8080,
)
queryFrontend.SetUser(strconv.Itoa(os.Getuid()))
queryFrontend.SetBackoff(defaultBackoffConfig)

return queryFrontend, nil
}
55 changes: 55 additions & 0 deletions test/e2e/query_frontend_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package e2e_test

import (
"context"
"testing"
"time"

"github.com/cortexproject/cortex/integration/e2e"
"github.com/prometheus/common/model"

"github.com/thanos-io/thanos/pkg/promclient"
"github.com/thanos-io/thanos/pkg/testutil"
"github.com/thanos-io/thanos/test/e2e/e2ethanos"
)

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

s, err := e2e.NewScenario("e2e_test_query_frontend")
testutil.Ok(t, err)
t.Cleanup(e2ethanos.CleanScenario(t, s))

prom, sidecar, err := e2ethanos.NewPrometheusWithSidecar(s.SharedDir(), s.NetworkName(), "0", defaultPromConfig("0", 0, "", ""), e2ethanos.DefaultPrometheusImage())
testutil.Ok(t, err)
testutil.Ok(t, s.StartAndWaitReady(prom, sidecar))

q, err := e2ethanos.NewQuerier(s.SharedDir(), "0", []string{sidecar.GRPCNetworkEndpoint()}, nil, nil, "", "")
testutil.Ok(t, err)
testutil.Ok(t, s.StartAndWaitReady(q))

queryFrontend, err := e2ethanos.NewQueryFrontend(s.SharedDir(), "0", "http://"+q.NetworkHTTPEndpoint())
testutil.Ok(t, err)
testutil.Ok(t, s.StartAndWaitReady(queryFrontend))

ctx, cancel := context.WithTimeout(context.Background(), 100*time.Minute)
t.Cleanup(cancel)

testutil.Ok(t, q.WaitSumMetrics(e2e.Equals(1), "thanos_store_nodes_grpc_connections"))

queryAndAssertSeries(t, ctx, queryFrontend.HTTPEndpoint(), queryUpWithoutInstance, promclient.QueryOptions{
Deduplicate: false,
}, []model.Metric{
{
"job": "myself",
"prometheus": "0",
"replica": "0",
},
})

// Have one instant query
testutil.Ok(t, q.WaitForMetricWithLabels(e2e.EqualsSingle(1),
"thanos_query_frontend_queries_total", map[string]string{"op": "query"}))

// TODO(yeya24): Add Query Range API to promclient so we can send range queries to query frontend.
}

0 comments on commit 49842f5

Please sign in to comment.