Skip to content

Commit

Permalink
Add flag to optionally disable adding Thanos params when querying met…
Browse files Browse the repository at this point in the history
…rics (#6560)

* Add flag to optionally disable adding Thanos params when querying metrics.

Signed-off-by: Anas <anas-aso@users.noreply.github.com>

* make the flag hidden and use a better helper.

Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Anas <anas-aso@users.noreply.github.com>

* Add entry in the Changelog.

Signed-off-by: Anas <anas-aso@users.noreply.github.com>

---------

Signed-off-by: Anas <anas-aso@users.noreply.github.com>
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
  • Loading branch information
anas-aso and bwplotka authored Jul 27, 2023
1 parent a817dbf commit 2790de4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#6466](https://github.com/thanos-io/thanos/pull/6466) Mixin (Receive): add limits alerting for configuration reload and meta-monitoring.
- [#6467](https://github.com/thanos-io/thanos/pull/6467) Mixin (Receive): add alert for tenant reaching head series limit.
- [#6528](https://github.com/thanos-io/thanos/pull/6528) Index Cache: Add histogram metric `thanos_store_index_cache_stored_data_size_bytes` for item size.
- [#6560](https://github.com/thanos-io/thanos/pull/6560) Thanos ruler: add flag to optionally disable adding Thanos params when querying metrics

### Fixed
- [#6503](https://github.com/thanos-io/thanos/pull/6503) *: Change the engine behind `ContentPathReloader` to be completely independent of any filesystem concept. This effectively fixes this configuration reload when used with Kubernetes ConfigMaps, Secrets, or other volume mounts.
Expand Down
19 changes: 11 additions & 8 deletions cmd/thanos/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,15 @@ func (wc *webConfig) registerFlag(cmd extkingpin.FlagClause) *webConfig {
}

type queryConfig struct {
addrs []string
sdFiles []string
sdInterval time.Duration
configPath *extflag.PathOrContent
dnsSDInterval time.Duration
httpMethod string
dnsSDResolver string
step time.Duration
addrs []string
sdFiles []string
sdInterval time.Duration
configPath *extflag.PathOrContent
dnsSDInterval time.Duration
httpMethod string
dnsSDResolver string
step time.Duration
doNotAddThanosParams bool
}

func (qc *queryConfig) registerFlag(cmd extkingpin.FlagClause) *queryConfig {
Expand All @@ -206,6 +207,8 @@ func (qc *queryConfig) registerFlag(cmd extkingpin.FlagClause) *queryConfig {
Default("miekgdns").Hidden().StringVar(&qc.dnsSDResolver)
cmd.Flag("query.default-step", "Default range query step to use. This is only used in stateless Ruler and alert state restoration.").
Default("1s").DurationVar(&qc.step)
cmd.Flag("query.only-prometheus-params", "Disable adding Thanos parameters (e.g dedup, partial_response) when querying metrics. Some non-Thanos systems have strict API validation.").Hidden().
Default("false").BoolVar(&qc.doNotAddThanosParams)
return qc
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/thanos/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ func runRule(
OutageTolerance: conf.outageTolerance,
ForGracePeriod: conf.forGracePeriod,
},
queryFuncCreator(logger, queryClients, promClients, metrics.duplicatedQuery, metrics.ruleEvalWarnings, conf.query.httpMethod),
queryFuncCreator(logger, queryClients, promClients, metrics.duplicatedQuery, metrics.ruleEvalWarnings, conf.query.httpMethod, conf.query.doNotAddThanosParams),
conf.lset,
// In our case the querying URL is the external URL because in Prometheus
// --web.external-url points to it i.e. it points at something where the user
Expand Down Expand Up @@ -808,6 +808,7 @@ func queryFuncCreator(
duplicatedQuery prometheus.Counter,
ruleEvalWarnings *prometheus.CounterVec,
httpMethod string,
doNotAddThanosParams bool,
) func(partialResponseStrategy storepb.PartialResponseStrategy) rules.QueryFunc {

// queryFunc returns query function that hits the HTTP query API of query peers in randomized order until we get a result
Expand Down Expand Up @@ -835,6 +836,7 @@ func queryFuncCreator(
Deduplicate: true,
PartialResponseStrategy: partialResponseStrategy,
Method: httpMethod,
DoNotAddThanosParams: doNotAddThanosParams,
})
span.Finish()

Expand Down
13 changes: 9 additions & 4 deletions pkg/promclient/promclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ func (c *Client) Snapshot(ctx context.Context, base *url.URL, skipHead bool) (st
}

type QueryOptions struct {
DoNotAddThanosParams bool
Deduplicate bool
PartialResponseStrategy storepb.PartialResponseStrategy
Method string
Expand Down Expand Up @@ -402,8 +403,10 @@ func (c *Client) QueryInstant(ctx context.Context, base *url.URL, query string,
}
params.Add("query", query)
params.Add("time", t.Format(time.RFC3339Nano))
if err := opts.AddTo(params); err != nil {
return nil, nil, nil, errors.Wrap(err, "add thanos opts query params")
if !opts.DoNotAddThanosParams {
if err := opts.AddTo(params); err != nil {
return nil, nil, nil, errors.Wrap(err, "add thanos opts query params")
}
}

u := *base
Expand Down Expand Up @@ -511,8 +514,10 @@ func (c *Client) QueryRange(ctx context.Context, base *url.URL, query string, st
params.Add("start", formatTime(timestamp.Time(startTime)))
params.Add("end", formatTime(timestamp.Time(endTime)))
params.Add("step", strconv.FormatInt(step, 10))
if err := opts.AddTo(params); err != nil {
return nil, nil, nil, errors.Wrap(err, "add thanos opts query params")
if !opts.DoNotAddThanosParams {
if err := opts.AddTo(params); err != nil {
return nil, nil, nil, errors.Wrap(err, "add thanos opts query params")
}
}

u := *base
Expand Down

0 comments on commit 2790de4

Please sign in to comment.