Skip to content

Querier: log requests handled by the internal querier router in single binary mode - #7940

Open
yuminn-k wants to merge 2 commits into
cortexproject:masterfrom
yuminn-k:fix-2694-querier-log
Open

yuminn-k wants to merge 2 commits into
cortexproject:masterfrom
yuminn-k:fix-2694-querier-log

Conversation

@yuminn-k

Copy link
Copy Markdown
Contributor

What this PR does:

When the querier runs in the same process as the query-frontend or query-scheduler (including -target=all), requests served through the internal querier router were not logged. A standalone querier gets the request log from the HTTP server's default middleware chain, but the internal router only got the tracing, auth and header middlewares.

This PR moves those middlewares into Cortex.wrapInternalQuerierRouter and adds the request log middleware (middleware.NewLogMiddleware), built from the same -server.log-request-headers, -server.log-request-at-info-level and -server.log-request-headers-exclude-list settings as the server's. It is wrapped inside the auth middleware so the log lines carry the tenant ID.

A new test, TestWrapInternalQuerierRouter_LogsRequests, fails on master (no log output) and passes with this change.

Note: in single binary mode the query-frontend already logs the external request, so each request the querier receives from the frontend is now logged as well. This follows from the code path; I did not measure the log volume of a running -target=all instance.

AI disclosure (per GENAI_POLICY.md): this change was prepared with an AI coding assistant (Claude Code).

Which issue(s) this PR fixes:
Fixes #2694

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]
  • docs/configuration/v1-guarantees.md updated if this PR introduces experimental flags

@yuminn-k
yuminn-k requested a review from a team as a code owner November 16, 2026 17:06
@yuminn-k
yuminn-k force-pushed the fix-2694-querier-log branch 2 times, most recently from f03dcd0 to 24ee47a Compare November 18, 2026 21:33
Comment thread pkg/cortex/modules.go
// auth middleware, so that the log lines carry the tenant ID.
logMiddleware := middleware.NewLogMiddleware(logging.GoKit(util_log.Logger), t.Cfg.Server.LogRequestHeaders, t.Cfg.Server.LogRequestAtInfoLevel, nil, strings.Split(t.Cfg.Server.LogRequestExcludeHeadersList, ","))
logMiddleware.DisableRequestSuccessLog = t.Cfg.Server.DisableRequestSuccessLog
router = logMiddleware.Wrap(router)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can tracing run before the logger? Otherwise this log can miss the query's trace ID.

@pull-request-size pull-request-size Bot added size/L and removed size/M labels Nov 19, 2026
@yuminn-k
yuminn-k force-pushed the fix-2694-querier-log branch from f63bbd5 to 975cb5b Compare November 20, 2026 00:34

@sandy2008 sandy2008 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new order works (auth, tracing, then the request log), and the trace ID test fails with the old order. The arm64 failure in TestGettingStartedWithGossipedRing looks unrelated. CHANGELOG.md needs a rebase. LGTM.

…outer

The log middleware reads the trace ID from the request context, so it has
to be wrapped inside the tracing middleware, as in the external HTTP server.

Signed-off-by: YuMin Kim <[email protected]>
@yuminn-k
yuminn-k force-pushed the fix-2694-querier-log branch from 975cb5b to 1502524 Compare November 30, 2026 18:27

This branch has not been deployed

No deployments
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.

Re-add Querier logging in Single Binary

2 participants