Repository navigation
metering: MetricsSender.Send reads identity from the context - #980
Conversation
56de75a to
7a0f4a5
Compare
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>
7a0f4a5 to
79d9a00
Compare
There was a problem hiding this comment.
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.
Alternative to #979; only one of the two is needed.
Both callers of
MetricsSender.Sendrepeat 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-ProcessRangeinpipeline/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)toSend(ctx, outputModuleHash, endpoint).Sendreads the identity fromdauth.FromContext(ctx)on every call.Sendis 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
TestSendputs identity on the context throughdauth.WithTrustedHeadersand checks the emitted fields.TestSend_noTrustedHeaderscovers the empty case.go test ./metering/ ./pipeline/ ./service/ ./test/passes, andgo test -race ./metering/passes.go test -race ./test/reports data races both with and without this change. They come fromresponseCollector.Collectappending to its slices from several pipeline goroutines (test/collector_test.go:93), not from this change.🤖 Generated with Claude Code