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

Query: range query histogram #4019

Merged
merged 5 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ We use _breaking :warning:_ to mark changes that are not backward compatible (re

## Unreleased

- [#4019](https://github.com/thanos-io/thanos/pull/4019) Query: Adds query range histogram.
- [#3350](https://github.com/thanos-io/thanos/pull/3350) Query/Sidecar: Added targets API support. You can now configure you Querier to fetch Prometheus targets from leaf Prometheus-es!

### Added
Expand Down
1 change: 1 addition & 0 deletions cmd/thanos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ func runQuery(
extprom.WrapRegistererWithPrefix("thanos_query_concurrent_", reg),
maxConcurrentQueries,
),
reg,
)

api.Register(router.WithPrefix("/api/v1"), tracer, logger, ins, logMiddleware)
Expand Down
14 changes: 14 additions & 0 deletions pkg/api/query/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
"github.com/go-kit/kit/log"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/common/model"
"github.com/prometheus/common/route"
"github.com/prometheus/prometheus/pkg/labels"
Expand Down Expand Up @@ -95,6 +97,8 @@ type QueryAPI struct {
defaultRangeQueryStep time.Duration
defaultInstantQueryMaxSourceResolution time.Duration
defaultMetadataTimeRange time.Duration

queryRangeHist prometheus.Histogram
}

// NewQueryAPI returns an initialized QueryAPI type.
Expand All @@ -119,6 +123,7 @@ func NewQueryAPI(
defaultMetadataTimeRange time.Duration,
disableCORS bool,
gate gate.Gate,
reg *prometheus.Registry,
) *QueryAPI {
return &QueryAPI{
baseAPI: api.NewBaseAPI(logger, disableCORS, flagsMap),
Expand All @@ -142,6 +147,12 @@ func NewQueryAPI(
defaultInstantQueryMaxSourceResolution: defaultInstantQueryMaxSourceResolution,
defaultMetadataTimeRange: defaultMetadataTimeRange,
disableCORS: disableCORS,

queryRangeHist: promauto.With(reg).NewHistogram(prometheus.HistogramOpts{
Name: "query_range_duration_seconds",
thorfour marked this conversation as resolved.
Show resolved Hide resolved
Help: "A histogram of the query range window in seconds",
Buckets: prometheus.ExponentialBuckets(15*60, 2, 12),
}),
}
}

Expand Down Expand Up @@ -430,6 +441,9 @@ func (qapi *QueryAPI) queryRange(r *http.Request) (interface{}, []error, *api.Ap

qe := qapi.queryEngine(maxSourceResolution)

// Record the query range requested
thorfour marked this conversation as resolved.
Show resolved Hide resolved
qapi.queryRangeHist.Observe(end.Sub(start).Seconds())

// We are starting promQL tracing span here, because we have no control over promQL code.
span, ctx := tracing.StartSpan(ctx, "promql_range_query")
defer span.Finish()
Expand Down
17 changes: 17 additions & 0 deletions pkg/api/query/v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
"time"

"github.com/go-kit/kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/common/route"
promgate "github.com/prometheus/prometheus/pkg/gate"
"github.com/prometheus/prometheus/pkg/labels"
Expand Down Expand Up @@ -186,6 +188,9 @@ func TestQueryEndpoints(t *testing.T) {
},
gate: gate.New(nil, 4),
defaultRangeQueryStep: time.Second,
queryRangeHist: promauto.With(prometheus.NewRegistry()).NewHistogram(prometheus.HistogramOpts{
Name: "query_range_hist",
}),
}

start := time.Unix(0, 0)
Expand Down Expand Up @@ -695,6 +700,9 @@ func TestMetadataEndpoints(t *testing.T) {
return qe
},
gate: gate.New(nil, 4),
queryRangeHist: promauto.With(prometheus.NewRegistry()).NewHistogram(prometheus.HistogramOpts{
Name: "query_range_hist",
}),
}
apiWithLabelLookback := &QueryAPI{
baseAPI: &baseAPI.BaseAPI{
Expand All @@ -706,6 +714,9 @@ func TestMetadataEndpoints(t *testing.T) {
},
gate: gate.New(nil, 4),
defaultMetadataTimeRange: apiLookbackDelta,
queryRangeHist: promauto.With(prometheus.NewRegistry()).NewHistogram(prometheus.HistogramOpts{
Name: "query_range_hist",
}),
}

var tests = []endpointTestCase{
Expand Down Expand Up @@ -1326,6 +1337,9 @@ func TestParseDownsamplingParamMillis(t *testing.T) {
api := QueryAPI{
enableAutodownsampling: test.enableAutodownsampling,
gate: gate.New(nil, 4),
queryRangeHist: promauto.With(prometheus.NewRegistry()).NewHistogram(prometheus.HistogramOpts{
Name: "query_range_hist",
}),
}
v := url.Values{}
v.Set(MaxSourceResolutionParam, test.maxSourceResolutionParam)
Expand Down Expand Up @@ -1374,6 +1388,9 @@ func TestParseStoreDebugMatchersParam(t *testing.T) {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
api := QueryAPI{
gate: promgate.New(4),
queryRangeHist: promauto.With(prometheus.NewRegistry()).NewHistogram(prometheus.HistogramOpts{
Name: "query_range_hist",
}),
}
v := url.Values{}
v.Set(StoreMatcherParam, tc.storeMatchers)
Expand Down