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

Add flag to optionally disable adding Thanos params when querying metrics #6560

Merged
merged 4 commits into from Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 11 additions & 8 deletions cmd/thanos/config.go
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.do-not-add-thanos-params", "Disable adding Thanos parameters (e.g dedup, partial_response) when querying for metrics.").
anas-aso marked this conversation as resolved.
Show resolved Hide resolved
Default("false").BoolVar(&qc.doNotAddThanosParams)
return qc
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/thanos/rule.go
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
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