Skip to content

query: fix exemplar proxy stripping external label matchers in multi-tier topologies#8752

Merged
GiedriusS merged 4 commits intothanos-io:mainfrom
Krishnachaitanyakc:implement/query-exemplar-proxy-strips-external-label-matcher
Apr 21, 2026
Merged

query: fix exemplar proxy stripping external label matchers in multi-tier topologies#8752
GiedriusS merged 4 commits intothanos-io:mainfrom
Krishnachaitanyakc:implement/query-exemplar-proxy-strips-external-label-matcher

Conversation

@Krishnachaitanyakc
Copy link
Copy Markdown
Contributor

Changes

In multi-tier Query topologies (Query A → Query B → Sidecars), the exemplar proxy unconditionally strips matchers that match external labels before forwarding to all downstream stores. This stripping is correct for Sidecars (Prometheus cannot handle external labels), but breaks Query → Query → Sidecar setups because the intermediate Query node needs those matchers for its own store routing.

For example, when Query A receives {cluster="A", namespace="foo"}, it strips cluster="A" before forwarding to Query B. Query B then receives {namespace="foo"} and fans out to all sidecars, returning exemplars from every cluster instead of just cluster A.

This was introduced by #4123 (fix for #4116).

What this PR does

  • Adds a SupportsExternalLabels field to ExemplarStore that indicates whether a downstream store can handle external label matchers.
  • In GetExemplarsStores(), sets SupportsExternalLabels: true for component.Query endpoints, since Query nodes can handle external labels for their own routing.
  • In the proxy fanout loop, only strips external label matchers for stores that do not support them (Sidecars), preserving them for stores that do (Query nodes).

Verification

  • Added TestProxyExternalLabelsPreservedForQueryStores: verifies that a downstream Query node receives the full matchers including external labels, while a non-matching Sidecar is correctly excluded.
  • Added TestProxyExternalLabelsStrippedForSidecarStores: verifies backward compatibility — Sidecars still receive queries with external label matchers stripped.
  • All existing tests continue to pass (backward compatible — SupportsExternalLabels defaults to false).
$ go test ./pkg/exemplars/... -run "TestProxyExternalLabels" -v -count=1
=== RUN   TestProxyExternalLabelsPreservedForQueryStores
--- PASS: TestProxyExternalLabelsPreservedForQueryStores (0.00s)
=== RUN   TestProxyExternalLabelsStrippedForSidecarStores
--- PASS: TestProxyExternalLabelsStrippedForSidecarStores (0.00s)
PASS

$ go test -tags slicelabels ./pkg/query/... -run "TestEndpoint" -v -count=1
--- PASS: TestEndpointSetUpdate (1.01s)
--- PASS: TestEndpointSetUpdate_AtomicEndpointAdditions (3.00s)
--- PASS: TestEndpoint_Update_QuerierStrict (6.01s)
--- PASS: TestEndpointSetUpdate_AvailabilityScenarios (8.01s)
PASS

Fixes #8702


Changes have a CHANGELOG entry: yes

@Krishnachaitanyakc Krishnachaitanyakc force-pushed the implement/query-exemplar-proxy-strips-external-label-matcher branch 2 times, most recently from fc019dc to 01ed452 Compare April 7, 2026 06:15
@Krishnachaitanyakc
Copy link
Copy Markdown
Contributor Author

Krishnachaitanyakc commented Apr 11, 2026

Added an ignore rule in .mdox.validate.yaml for two sets of broken external links that are causing the Documentation check CI to fail on all open PRs (not just this one)

@Krishnachaitanyakc Krishnachaitanyakc force-pushed the implement/query-exemplar-proxy-strips-external-label-matcher branch from e6f9265 to 8388bdf Compare April 11, 2026 08:35
Copy link
Copy Markdown
Member

@GiedriusS GiedriusS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, let's see if anyone else has any comments.

@Krishnachaitanyakc
Copy link
Copy Markdown
Contributor Author

@saswatamcode @fpetkovski can you please review this?

Kc Balusu and others added 4 commits April 14, 2026 18:35
… exemplar proxy

In multi-tier Query topologies (Query A → Query B → Sidecars), the exemplar
proxy was stripping external label matchers before forwarding to all downstream
stores. This stripping is necessary for Sidecars (Prometheus cannot handle
external labels), but breaks Query-to-Query forwarding because the intermediate
Query node needs the matchers for its own store routing.

Add a SupportsExternalLabels field to ExemplarStore that indicates whether a
downstream store can handle external label matchers. When constructing exemplar
stores from endpoints, set this to true for Query component types. In the proxy
fanout loop, only strip external label matchers for stores that do not support
them.

Fixes thanos-io#8702

Signed-off-by: Kc Balusu <kcbalusu@gmail.com>
Signed-off-by: Kc Balusu <kcbalusu@meta.com>
Add ignore rules for Grafana promtail docs (removed after EOL in
March 2026) and db.cs.cmu.edu (DNS/timeout issues from CI).

Signed-off-by: Kc Balusu <kcbalusu@meta.com>
Update the sed range in docs/components/receive.md from '1068,1078p'
to '1067,1078p' to match the current line numbers in handler.go after
upstream changes shifted the writeQuorum function.

Signed-off-by: Kc Balusu <kcbalusu@meta.com>
@Krishnachaitanyakc Krishnachaitanyakc force-pushed the implement/query-exemplar-proxy-strips-external-label-matcher branch from 8388bdf to 7b851b7 Compare April 15, 2026 01:36
@SergeyKanzhelev
Copy link
Copy Markdown

@SergeyKanzhelev @liggitt @rytswd can you please review this?

Can you comment how am I related to this? I might, I just do not know how.

@Krishnachaitanyakc
Copy link
Copy Markdown
Contributor Author

@SergeyKanzhelev @liggitt @rytswd can you please review this?

Can you comment how am I related to this? I might, I just do not know how.

my bad, I tagged you on a different PR in a different repo and it got copy pasted into this. Apologies

@Krishnachaitanyakc
Copy link
Copy Markdown
Contributor Author

@saswatamcode @GiedriusS can you please help me getting this reviewed?

@GiedriusS GiedriusS merged commit 2aedfa5 into thanos-io:main Apr 21, 2026
20 of 22 checks passed
@GiedriusS
Copy link
Copy Markdown
Member

Thank you 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query: exemplar proxy strips external label matchers in multi-tier query topologies

3 participants