backend/feat: add forks_started_total and forks_finished_total counters - #1514
Conversation
Count forked threads created through Forkable (FlowR r) with two counters labelled by sanitized fork tag, fork type and version. Active forks per pod is started minus finished. The finished counter is bumped via bracket_ so it also fires when the thread errors or is killed. The tag label replaces UUIDs with ":id", is truncated to 32 chars and is capped at 300 distinct values per process (overflow recorded as "other"). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WyZ8n4mSmpcmEnPfX7GVb5
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. WalkthroughThe change adds fork lifecycle counters with bounded, sanitized labels. ChangesFork lifecycle metrics
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant FlowR
participant Metrics
participant Counters
FlowR->>Metrics: start fork with tag and fork type
Metrics->>Counters: increment forks_started_total
Metrics->>FlowR: execute fork action
Metrics->>Counters: increment forks_finished_total
Suggested reviewers: Merge Risk: ⚪ Minimal · up to The fork metrics implementation registers bounded labels and instruments all described FlowR fork paths without an identified merge-blocking risk. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. A rabbit reads each line, Comment |
What
Adds two Prometheus counters that track forked threads created through
Forkable (FlowR r)(fork,awaitableFork,forkMultiple):forks_started_totaltag,fork_type,versionforks_finished_totaltag,fork_type,versionfork_type∈fork/awaitable_fork/fork_multiple. Thepodlabel is added by vmagent at scrape time.Active forks per pod at any instant:
Which fork is piling up:
How
CoreMetricsmethodwithForkCounters :: Text -> Text -> m a -> m a. TheFlowRimplementation wraps the forked body inbracket_, soforks_finished_totalincrements on success, on error, and when the thread is killed by an async exception. euler-hs'sGeneralBracketinterprets to the real IOgeneralBracket.MockMand the testIOinstance are no-ops. There are noCoreMetricsinstances in nammayatri, so consumers only need a flake bump.Tag label cardinality
47 call sites append ids to the fork tag, e.g.
"cancelBooking:" <> bookingId. Prod logs confirm values likecancelBooking:0baf1774-afb8-…. To keep the label bounded, the tag is sanitised before use::id(for tags of 36+ chars; the regex is compiled once).other.Worst case this adds 600 series per pod (~1% on driver-bpp, ~3% on rider-app at today's per-pod series counts).
The forks-started and forks-finished counters for the same raw tag always resolve to the same label, because sanitisation is deterministic and the known-label set only grows.
Testing
cabal build mobility-core:lib:mobility-corepasses;cabal test mobility-core:testspasses.🤖 Generated with Claude Code
https://claude.ai/code/session_01WyZ8n4mSmpcmEnPfX7GVb5
Summary by CodeRabbit