Skip to content

metering: MetricsSender.Send reads identity from the context - #980

Merged
GabrielCartier merged 1 commit into
streamingfast:developfrom
matthewdarwin:metering-send-reads-auth
Oct 13, 2026
Merged

GabrielCartier merged 1 commit into
streamingfast:developfrom
matthewdarwin:metering-send-reads-auth

Conversation

@matthewdarwin

Copy link
Copy Markdown
Contributor

Alternative to #979; only one of the two is needed.

Both callers of MetricsSender.Send repeat the same block: dauth.FromContext, then organization id, api key id, meta and ip, passed as four string arguments. The callers are tier1's Blocks response handler and tier2's end-of-ProcessRange in pipeline/terminate.go. tier1 also copies these values once per stream; the copy dates from the tier split in #238, when trusted headers could not change during a stream.

This PR changes Send(ctx, organizationID, apiKeyID, ip, userMeta, outputModuleHash, endpoint) to Send(ctx, outputModuleHash, endpoint). Send reads the identity from dauth.FromContext(ctx) on every call.

  • Removes the duplicated identity handling from both callers.
  • Every event uses the current headers. That is what grpc: refresh trusted headers from continuous auth responses dauth#19 needs, since it lets continuous authentication refresh a stream's trusted headers.
  • A context without trusted headers emits empty identity fields, as callers passing empty strings did before.

Send is exported. A GitHub code search finds no callers outside this repo.

#979 makes the minimal fix: tier1 reads the headers per response and leaves Send's signature alone. This PR fixes the same thing by removing the duplication. Happy to close whichever one isn't wanted.

Tests

  • TestSend puts identity on the context through dauth.WithTrustedHeaders and checks the emitted fields. TestSend_noTrustedHeaders covers the empty case.
  • go test ./metering/ ./pipeline/ ./service/ ./test/ passes, and go test -race ./metering/ passes.
  • go test -race ./test/ reports data races both with and without this change. They come from responseCollector.Collect appending to its slices from several pipeline goroutines (test/collector_test.go:93), not from this change.

🤖 Generated with Claude Code

Both callers of MetricsSender.Send (tier1's Blocks response handler and
tier2's end-of-ProcessRange in pipeline/terminate.go) repeated the same
block: dauth.FromContext, then organization id, api key id, meta and ip
passed as four string arguments. tier1 also copied them once per stream.

Send now takes only the output module hash and endpoint and reads the
identity from the trusted headers in ctx on each call. This removes the
duplication, and every event uses the current headers, so headers
refreshed during a stream by dauth continuous authentication apply to
the next event.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@matthewdarwin
matthewdarwin force-pushed the metering-send-reads-auth branch from 7a0f4a5 to 79d9a00 Compare October 9, 2026 22:03

@GabrielCartier GabrielCartier 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.

Logic checks out: respContext derives from the auth middleware ctx and nothing re-wraps WithTrustedHeaders, so the per-call read in Send will see dauth#19's refreshed holder. Builds and tests green against both current dauth and the dauth#19 branch, merges clean onto develop.

One case neither this nor #979 covers, fine as a follow-up: LiveBackFiller.Start (service/live_back_filler.go:145) snapshots ToOutgoingGRPCContext once, and every live-backfill ProcessRange reuses it, so tier2 bills those jobs with the stream-start identity for the whole live stream. That is the hours-long case dauth#19 describes. Moving the ToOutgoingGRPCContext call into requestBackProcessing, as worker.go:348 already does per job, would close it.

@GabrielCartier
GabrielCartier merged commit 5678ff8 into streamingfast:develop Oct 13, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants