Skip to content

Commit

Permalink
range query histogram
Browse files Browse the repository at this point in the history
Adds a range query histogram that tracks the distribution
of range queries. This can be useful for determining storage
retention requirements.

Signed-off-by: Thor <[email protected]>
  • Loading branch information
thorfour committed Apr 4, 2021
1 parent 2dab5ce commit 3f2c2de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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",
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
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

0 comments on commit 3f2c2de

Please sign in to comment.