thanos-io/thanos · error

--query/--query.sd-files/--grpc-query-endpoint and…

Error message

--query/--query.sd-files/--grpc-query-endpoint and --query.config* parameters cannot be defined at the same time

What it means

Thanos rule forbids mixing the static flag set (--query, --query.sd-files, --grpc-query-endpoint) with the file-based --query.config/--query.config-file. errors.New raises this when both styles are supplied at once, because endpoints must come from exactly one mechanism to avoid ambiguous configuration.

Solutions

  1. Remove the --query/--query.sd-files/--grpc-query-endpoint flags and keep only --query.config-file (or vice versa).
  2. Move all endpoints from the static flags into the query config YAML endpoints list.
  3. Audit startup scripts/Helm extraArgs for leftovers from a migration.
  4. Restart and confirm only one style of query configuration is present (print the full command line).

Example fix

// before
thanos rule --query=qa:9090 --query.config-file=queries.yaml
// after
thanos rule --query.config-file=queries.yaml   # all endpoints inside queries.yaml
Defensive patterns

Strategy: validation

Validate before calling

def check_query_flags_mutually_exclusive(args):
    static = {"--query", "--query.sd-files", "--grpc-query-endpoint"}
    filebased = {"--query.config", "--query.config-file"}
    given = {a.split("=")[0] for a in args if a.startswith("--")}
    if given & static and given & filebased:
        raise SystemExit("use either --query/--query.sd-files/--grpc-query-endpoint OR --query.config*, not both")

Type guard

def query_flags_valid(args):
    static = any(a.split("=")[0] in {"--query", "--query.sd-files", "--grpc-query-endpoint"} for a in args)
    filebased = any(a.split("=")[0] in {"--query.config", "--query.config-file"} for a in args)
    return not (static and filebased)

Prevention

When it happens

Trigger: Setup detects (len(sdFiles)!=0 || len(addrs)!=0 || len(grpcQueryEndpoints)!=0) && len(queryConfigYAML)!=0 and aborts, e.g. --query=qa:9090 together with --query.config-file=queries.yaml.

Common situations: Migrating from static flags to query config files but leaving old --query flags in the unit file; Helm chart default args plus user-supplied extraArgs containing --query.config; wrapper scripts appending both.

Understand the failure class

Background: "mutually exclusive" flag errors: what "can't supply both nx and xx", "--raw is not compatible with -i" and "cannot be used with" mean, and how to fix them — this error's family across 29 libraries.

Related errors


AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07). Data as JSON: /api/errors/72204ad495161bad. Report an issue: GitHub.

Appendix: source

Thrown at cmd/thanos/rule.go:231

		lookupQueries := map[string]struct{}{}
		for _, q := range conf.query.addrs {
			if _, ok := lookupQueries[q]; ok {
				return errors.Errorf("Address %s is duplicated for --query flag.", q)
			}

			lookupQueries[q] = struct{}{}
		}

		conf.queryConfigYAML, err = conf.query.configPath.Content()
		if err != nil {
			return err
		}

		if len(conf.query.sdFiles) == 0 && len(conf.query.addrs) == 0 && len(conf.queryConfigYAML) == 0 && len(conf.grpcQueryEndpoints) == 0 {
			return errors.New("no query configuration parameter was given")
		}
		if (len(conf.query.sdFiles) != 0 || len(conf.query.addrs) != 0 || len(conf.grpcQueryEndpoints) != 0) && len(conf.queryConfigYAML) != 0 {
			return errors.New("--query/--query.sd-files/--grpc-query-endpoint and --query.config* parameters cannot be defined at the same time")
		}

		// Parse and check alerting configuration.
		conf.alertmgrsConfigYAML, err = conf.alertmgr.configPath.Content()
		if err != nil {
			return err
		}
		if len(conf.alertmgrsConfigYAML) != 0 && len(conf.alertmgr.alertmgrURLs) != 0 {
			return errors.New("--alertmanagers.url and --alertmanagers.config* parameters cannot be defined at the same time")
		}

		conf.alertRelabelConfigYAML, err = conf.alertmgr.alertRelabelConfigPath.Content()
		if err != nil {
			return err
		}

		httpLogOpts, err := logging.ParseHTTPOptions(reqLogConfig)
		if err != nil {

View on GitHub (pinned to 35b8b99117)