Skip to content

Stamp caller attribution (rillUserEmail, rillServiceToken) on the Druid query context - #9755

Open
mpasa wants to merge 1 commit into
rilldata:mainfrom
mpasa:miguel/druid-query-context-attribution
Open

Stamp caller attribution (rillUserEmail, rillServiceToken) on the Druid query context#9755
mpasa wants to merge 1 commit into
rilldata:mainfrom
mpasa:miguel/druid-query-context-attribution

Conversation

@mpasa

@mpasa mpasa commented Jul 28, 2026

Copy link
Copy Markdown

Stamps caller attribution on the query context of Druid SQL requests, similar to Imply Pivot's implyUserEmail/implyViewTitle, so queries can be attributed to users in Druid's query logs.

  • The Druid driver now forwards two well-known keys from Statement.QueryAttributes to the query context: user_emailrillUserEmail and service_tokenrillServiceToken.
  • Both are optional and omitted from the request when unset; they do not affect query execution.
  • Projects opt in via the metrics view's query_attributes, e.g.:
    query_attributes:
      user_email: '{{ if .user.email }}{{ .user.email }}{{ end }}'
      service_token: '{{ if and (not .user.email) .user.name }}{{ .user.name }}{{ end }}'
  • Adds unit tests for the driver's query context serialization (the druidsqldriver package previously had none).

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

Developed in collaboration with Claude Code

Forward the calling user's email and service name from the metrics view's
query_attributes to Druid's query context (as rillUserEmail/rillServiceToken),
so they appear in Druid's query logs for attribution, similar to Imply Pivot's
implyUserEmail.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@nishantmonu51
nishantmonu51 requested a review from pjain1 July 29, 2026 14:33
@nishantmonu51

Copy link
Copy Markdown
Collaborator

@codex: review

@nishantmonu51

Copy link
Copy Markdown
Collaborator

@pjain1 : Can you help review this one ?

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: b91a148f56

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +461 to +462
UserEmail string `json:"rillUserEmail,omitempty"`
ServiceToken string `json:"rillServiceToken,omitempty"`

@pjain1 pjain1 Jul 29, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of adding custom keys here, I would rather pass in key/values from stmt.QueryAttributes as it is so any arbitrary attributes you define in metrics view will be passed as it in Druid context. But this would either need a custom marshaller for DruidQueryContext or changing the struct to just a map.

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

Labels

Area:Druid Size:M Medium change: 100-499 lines Type:Improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants