From 470c9f44f0a4c3b182b87c06ce851ce887f43234 Mon Sep 17 00:00:00 2001 From: Owen Diehl Date: Thu, 6 Aug 2020 12:07:04 -0400 Subject: [PATCH] series endpoint uses normal splits --- pkg/querier/queryrange/roundtrip.go | 25 ++++++++++++++++++++---- pkg/querier/queryrange/roundtrip_test.go | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/pkg/querier/queryrange/roundtrip.go b/pkg/querier/queryrange/roundtrip.go index b87eef9f519c..9bea8507bdb7 100644 --- a/pkg/querier/queryrange/roundtrip.go +++ b/pkg/querier/queryrange/roundtrip.go @@ -262,8 +262,8 @@ func NewSeriesTripperware( if cfg.SplitQueriesByInterval != 0 { queryRangeMiddleware = append(queryRangeMiddleware, queryrange.InstrumentMiddleware("split_by_interval", instrumentMetrics), - // Force a 24 hours split by for series API, this will be more efficient with our static daily bucket storage. - SplitByIntervalMiddleware(WithSplitByLimits(limits, 24*time.Hour), codec, splitByMetrics), + // The Series API needs to pull one chunk per series to extract the label set, which is much cheaper than iterating through all matching chunks. + SplitByIntervalMiddleware(WithSplitByLimits(limits, cfg.SplitQueriesByInterval), codec, splitByMetrics), ) } if cfg.MaxRetries > 0 { @@ -288,8 +288,25 @@ func NewLabelsTripperware( retryMiddlewareMetrics *queryrange.RetryMiddlewareMetrics, splitByMetrics *SplitByMetrics, ) (frontend.Tripperware, error) { - // for now we'll use the same config as for the Series API. - return NewSeriesTripperware(cfg, log, limits, codec, instrumentMetrics, retryMiddlewareMetrics, splitByMetrics) + queryRangeMiddleware := []queryrange.Middleware{} + if cfg.SplitQueriesByInterval != 0 { + queryRangeMiddleware = append(queryRangeMiddleware, + queryrange.InstrumentMiddleware("split_by_interval", instrumentMetrics), + // Force a 24 hours split by for labels API, this will be more efficient with our static daily bucket storage. + // This is because the labels API is an index-only operation. + SplitByIntervalMiddleware(WithSplitByLimits(limits, 24*time.Hour), codec, splitByMetrics), + ) + } + if cfg.MaxRetries > 0 { + queryRangeMiddleware = append(queryRangeMiddleware, queryrange.InstrumentMiddleware("retry", instrumentMetrics), queryrange.NewRetryMiddleware(log, cfg.MaxRetries, retryMiddlewareMetrics)) + } + + return func(next http.RoundTripper) http.RoundTripper { + if len(queryRangeMiddleware) > 0 { + return queryrange.NewRoundTripper(next, codec, queryRangeMiddleware...) + } + return next + }, nil } // NewMetricTripperware creates a new frontend tripperware responsible for handling metric queries diff --git a/pkg/querier/queryrange/roundtrip_test.go b/pkg/querier/queryrange/roundtrip_test.go index e93e5c6eb825..6d2c67b4a777 100644 --- a/pkg/querier/queryrange/roundtrip_test.go +++ b/pkg/querier/queryrange/roundtrip_test.go @@ -216,7 +216,7 @@ func TestSeriesTripperware(t *testing.T) { lreq := &LokiSeriesRequest{ Match: []string{`{job="varlogs"}`}, - StartTs: testTime.Add(-25 * time.Hour), // bigger than the limit + StartTs: testTime.Add(-5 * time.Hour), // bigger than the limit EndTs: testTime, Path: "/loki/api/v1/series", }