-
Notifications
You must be signed in to change notification settings - Fork 543
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
/active_series
: generate correct request shards for incoming GET
…
…requests, handle gRPC errors (#7133) * codes.Canceled is not an error either * add test for GET-request based shards * generate shard requests correctly * read response body only if it's not nil * add test for context propagation * add org id to generated requests * use wrapped grpc error * add integration test * add license header and build tag * remove stray parens
- Loading branch information
Showing
8 changed files
with
359 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
//go:build requires_docker | ||
|
||
package integration | ||
|
||
import ( | ||
"net/http" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
"github.com/grafana/e2e" | ||
e2ecache "github.com/grafana/e2e/cache" | ||
e2edb "github.com/grafana/e2e/db" | ||
"github.com/prometheus/prometheus/model/labels" | ||
"github.com/prometheus/prometheus/prompb" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/grafana/mimir/integration/e2emimir" | ||
) | ||
|
||
func TestActiveSeriesWithQueryShardingHTTP(t *testing.T) { | ||
config := queryFrontendTestConfig{ | ||
queryStatsEnabled: true, | ||
querySchedulerEnabled: true, | ||
querySchedulerDiscoveryMode: "ring", | ||
setup: func(t *testing.T, s *e2e.Scenario) (string, map[string]string) { | ||
flags := mergeFlags(BlocksStorageFlags(), BlocksStorageS3Flags()) | ||
minio := e2edb.NewMinio(9000, flags["-blocks-storage.s3.bucket-name"]) | ||
require.NoError(t, s.StartAndWaitReady(minio)) | ||
|
||
return "", flags | ||
}, | ||
} | ||
|
||
runTestActiveSeriesWithQueryShardingHTTPTest(t, config) | ||
} | ||
|
||
func runTestActiveSeriesWithQueryShardingHTTPTest(t *testing.T, cfg queryFrontendTestConfig) { | ||
s, err := e2e.NewScenario(networkName) | ||
require.NoError(t, err) | ||
defer s.Close() | ||
|
||
memcached := e2ecache.NewMemcached() | ||
consul := e2edb.NewConsul() | ||
require.NoError(t, s.StartAndWaitReady(consul, memcached)) | ||
|
||
configFile, flags := cfg.setup(t, s) | ||
|
||
flags = mergeFlags(flags, map[string]string{ | ||
"-query-frontend.cache-results": "true", | ||
"-query-frontend.results-cache.backend": "memcached", | ||
"-query-frontend.results-cache.memcached.addresses": "dns+" + memcached.NetworkEndpoint(e2ecache.MemcachedPort), | ||
"-query-frontend.query-stats-enabled": strconv.FormatBool(cfg.queryStatsEnabled), | ||
"-query-frontend.query-sharding-total-shards": "32", | ||
"-query-frontend.query-sharding-max-sharded-queries": "128", | ||
"-query-frontend.shard-active-series-queries": "true", | ||
"-querier.cardinality-analysis-enabled": "true", | ||
}) | ||
|
||
// Start the query-scheduler if enabled. | ||
var queryScheduler *e2emimir.MimirService | ||
if cfg.querySchedulerEnabled && cfg.querySchedulerDiscoveryMode == "dns" { | ||
queryScheduler = e2emimir.NewQueryScheduler("query-scheduler", flags) | ||
require.NoError(t, s.StartAndWaitReady(queryScheduler)) | ||
flags["-query-frontend.scheduler-address"] = queryScheduler.NetworkGRPCEndpoint() | ||
flags["-querier.scheduler-address"] = queryScheduler.NetworkGRPCEndpoint() | ||
} else if cfg.querySchedulerEnabled && cfg.querySchedulerDiscoveryMode == "ring" { | ||
flags["-query-scheduler.service-discovery-mode"] = "ring" | ||
flags["-query-scheduler.ring.store"] = "consul" | ||
flags["-query-scheduler.ring.consul.hostname"] = consul.NetworkHTTPEndpoint() | ||
|
||
queryScheduler = e2emimir.NewQueryScheduler("query-scheduler", flags) | ||
require.NoError(t, s.StartAndWaitReady(queryScheduler)) | ||
} | ||
|
||
// Start the query-frontend. | ||
queryFrontend := e2emimir.NewQueryFrontend("query-frontend", flags, e2emimir.WithConfigFile(configFile)) | ||
require.NoError(t, s.Start(queryFrontend)) | ||
|
||
if !cfg.querySchedulerEnabled { | ||
flags["-querier.frontend-address"] = queryFrontend.NetworkGRPCEndpoint() | ||
} | ||
|
||
// Start all other services. | ||
ingester := e2emimir.NewIngester("ingester", consul.NetworkHTTPEndpoint(), flags, e2emimir.WithConfigFile(configFile)) | ||
distributor := e2emimir.NewDistributor("distributor", consul.NetworkHTTPEndpoint(), flags, e2emimir.WithConfigFile(configFile)) | ||
querier := e2emimir.NewQuerier("querier", consul.NetworkHTTPEndpoint(), flags, e2emimir.WithConfigFile(configFile)) | ||
|
||
require.NoError(t, s.StartAndWaitReady(querier, ingester, distributor)) | ||
require.NoError(t, s.WaitReady(queryFrontend)) | ||
|
||
// Check if we're discovering memcached or not. | ||
require.NoError(t, queryFrontend.WaitSumMetrics(e2e.Equals(1), "thanos_cache_dns_provider_results")) | ||
require.NoError(t, queryFrontend.WaitSumMetrics(e2e.Greater(0), "thanos_cache_dns_lookups_total")) | ||
|
||
// Wait until distributor and querier have updated the ingesters ring. | ||
require.NoError(t, distributor.WaitSumMetricsWithOptions(e2e.Equals(1), []string{"cortex_ring_members"}, e2e.WithLabelMatchers( | ||
labels.MustNewMatcher(labels.MatchEqual, "name", "ingester"), | ||
labels.MustNewMatcher(labels.MatchEqual, "state", "ACTIVE")))) | ||
|
||
require.NoError(t, querier.WaitSumMetricsWithOptions(e2e.Equals(1), []string{"cortex_ring_members"}, e2e.WithLabelMatchers( | ||
labels.MustNewMatcher(labels.MatchEqual, "name", "ingester"), | ||
labels.MustNewMatcher(labels.MatchEqual, "state", "ACTIVE")))) | ||
|
||
// Push series for the test user to Mimir. | ||
c, err := e2emimir.NewClient(distributor.HTTPEndpoint(), queryFrontend.HTTPEndpoint(), "", "", userID) | ||
require.NoError(t, err) | ||
numSeries := 100 | ||
metricName := "test_metric" | ||
now := time.Now() | ||
series := make([]prompb.TimeSeries, numSeries) | ||
for i := 0; i < numSeries; i++ { | ||
ts, _, _ := e2e.GenerateSeries(metricName, now, prompb.Label{Name: "index", Value: strconv.Itoa(i)}) | ||
series[i] = ts[0] | ||
} | ||
res, err := c.Push(series) | ||
require.NoError(t, err) | ||
require.Equal(t, http.StatusOK, res.StatusCode) | ||
|
||
// Query active series. | ||
for _, options := range [][]e2emimir.ActiveSeriesOption{ | ||
{e2emimir.WithRequestMethod(http.MethodGet)}, | ||
{e2emimir.WithRequestMethod(http.MethodPost)}, | ||
{e2emimir.WithRequestMethod(http.MethodGet), e2emimir.WithEnableCompression()}, | ||
{e2emimir.WithRequestMethod(http.MethodPost), e2emimir.WithEnableCompression()}, | ||
{e2emimir.WithQueryShards(1)}, | ||
{e2emimir.WithQueryShards(12)}, | ||
} { | ||
response, err := c.ActiveSeries(metricName, options...) | ||
require.NoError(t, err) | ||
require.Equal(t, http.StatusOK, res.StatusCode) | ||
require.Len(t, response.Data, numSeries) | ||
} | ||
|
||
_, err = c.ActiveSeries(metricName, e2emimir.WithQueryShards(512)) | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), "shard count 512 exceeds allowed maximum (128)") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.