refactor: share the metrics helpers, error type, and prefetch observation - #5
Open
ctxswitch wants to merge 1 commit into
Open
refactor: share the metrics helpers, error type, and prefetch observation#5ctxswitch wants to merge 1 commit into
ctxswitch wants to merge 1 commit into
Conversation
…tion The agent kept its own copy of the telemetry registration helpers: agent_register /agent_counter/agent_gauge/agent_histogram had the same bodies as their telemetry counterparts, transfer_buckets was character-identical, saturating_i64 differed only in its integer type, and both encode methods were the same line. The telemetry helpers are now pub(crate) and the copies are gone, with full metric names passed at the call site instead of formatting a flywheel_agent_ prefix nineteen times at startup. AgentMetrics::new is a struct literal, flywheel_requests_total goes through int_counter rather than being hand-rolled, and a new int_counter_vec helper covers the two IntCounterVecs. ChannelStoreError differed from MetadataError only by IncompatibleStore versus AlreadyExists, which forced four duplicated helper pairs in rocksdb.rs. MetadataError gains AlreadyExists and ChannelStoreError is deleted along with its re-export and the four channel_* helpers. The agent and shard prefetch observations are now one PrefetchObservation parameterized by its recorder. complete takes &mut self, which removes the Option from the unfold state and both expects from the per-chunk path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fourth of six phases, split in two to keep the diff reviewable. This is 4a, based on
cleanup/phase-3-deletions(#4). 4b follows with the axum extractor, the negotiatormerge, and a list of smaller consolidations. Net −167 lines.
Three duplications that had already drifted:
Metrics plumbing. The agent kept its own copy of the telemetry registration
helpers —
agent_register/agent_counter/agent_gauge/agent_histogramhad thesame bodies as their telemetry counterparts,
transfer_bucketswascharacter-identical,
saturating_i64differed only inusizevsu64, and bothencodemethods were the same line. The telemetry helpers are nowpub(crate)andthe copies are gone. Full metric names are passed at the call site instead of
formatting a
flywheel_agent_prefix nineteen times at startup,AgentMetrics::newis a struct literal,
flywheel_requests_totalgoes throughint_counterinstead ofbeing hand-rolled, and a new
int_counter_vechelper covers the twoIntCounterVecs.ChannelStoreError→MetadataError. The two enums differed only byIncompatibleStorevsAlreadyExists, which forced four duplicated helper pairs inrocksdb.rs.MetadataErrorgainsAlreadyExists;ChannelStoreError, itsre-export, and the four
channel_*helpers are deleted.Prefetch observation. The agent's and the shard's are now one
PrefetchObservation<R: PrefetchRecorder>parameterized by its recorder, withobserve_prefetch_body— the one genuinely byte-for-byte duplicate — shared.completetakes&mut self, which removes theOptionfrom the unfold state andboth
expects from the per-chunk path.Verification
make ciclean, includingclippy --all-targets -- -D warnings; 138 tests across thelib and 8 integration binaries.
The exported metric surface is byte-identical.
AgentMetrics::encode(3,1)and apopulated
Metrics::encode()were dumped before and after the change anddiffedclean — every metric name, help string, bucket boundary, and label set. No
docs/operations.mdfollow-up is needed. That harness was temporary and removedrather than left behind, since as a test it would only re-assert its own constants.
The error merge is compiler-checked, with
tests/integration/channels.rs(13 tests,both route forms, protected and open access, every data route) and the end-to-end
prefetch path in
tests/integration/build_cache.rscovering runtime behaviour.make ciOperational impact
No metric name, help text, bucket, or label changed — verified by the scrape diff
above.
flywheel_requests_totalis retained as a documented operator contract.Two error display strings changed, an unavoidable consequence of the approved merge,
since the surviving variants keep the metadata wording:
"channel registry failed: {0}"→"metadata store failed: {0}", and"channel registry task failed: {0}"→"metadata task failed: {0}"."channel already exists"is preserved verbatim.Nothing in
src/,tests/, ordocs/asserts or documents these strings, but theyare operator-visible in logs.
Two agent debug log lines lose their
agentprefix ("agent prefetch request started/finished"→"prefetch request started/finished") and gain an emptyroutefield. The agent's request span already carries
component = "agent"and the agentand shard are separate processes, so nothing becomes ambiguous — flagged only in case
log-line greps exist outside this repo.
Review notes
The two prefetch observations were not actually identical, contrary to the plan.
Three real divergences, all preserved rather than papered over:
route: String; the agent's has none. The shared type takesOption<String>and the agent passesNone— it forwards by ring position andnever matches a route.
set_statusalso records thehit/miss/unavailablelabel. Theagent has no equivalent because it classifies prefetch outcomes at the forwarding
site, where it can also see the empty-ring and send-failure cases that produce no
response at all. Folding that into the observation would have changed counts — a
degraded 404 from an empty ring would be recorded as
missinstead ofunavailable. SoAgentMetrics::prefetch_responseis a deliberate no-op with acomment saying why. This is the one wart in the PR: a trait method that does
nothing for one of its two impls. The alternative was changing what the counters
mean, which seemed clearly worse.
Dropbodies differed — labeled vec counters on the shard, separateprefetch_completed/prefetch_cancelledcounters on the agent. That is what thetrait method absorbs.
Deliberately left alone:
Metrics::newstill uses sequentialletbindings ratherthan a struct literal, because
foreground_limitis registered,.set()immediately,and never stored as a field — forcing the literal would read worse.
rocksdb.rsnowhas three
impl RocksMetadatablocks that could be one, the third having existed onlyto group the channel methods behind the removed error type; cosmetic, left for
whoever wants it.