feat(metrics): expose forkd_branches_in_flight + cap (follow-up to #177)#183
Merged
Conversation
…ency_cap Follow-up to #179 — surfaces the in-flight BRANCH count and the configured cap on /metrics, so operators can size FORKD_BRANCH_CONCURRENCY empirically against their real workload (per @cortsdine's suggestion in #177). New gauges: - forkd_branches_in_flight (Mutex<HashSet<String>>.len() of BRANCHes currently writing memory.bin) - forkd_branch_concurrency_cap (the value the Semaphore was constructed with; not exposed by tokio::Semaphore, so cached on AppState in a new branch_concurrency_cap field that mirrors the value from DaemonConfig::branch_concurrency) The pair lets a Grafana panel show "5 / 16 in-flight" without external knowledge of the cap. Tests: - Existing metrics_emits_prometheus_text extended to assert both new gauges appear with the default cap value. - New metrics_branches_in_flight_tracks_slot_acquisitions verifies the in-flight gauge moves with BranchSlot acquire/drop — the actual Drop-recovery semantics @henliveira praised in #178, now visible to operators.
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.
Follow-up to #179, fulfilling the metrics suggestion @cortsdine raised in #177:
Adding both the in-flight count and the configured cap, so a Grafana panel can render "5 / 16 in-flight" without external knowledge of `FORKD_BRANCH_CONCURRENCY`.
New gauges on `/metrics`
`tokio::Semaphore` doesn't expose its initial permit count, so the cap is cached on `AppState` in a new `branch_concurrency_cap: usize` field that mirrors the value from `DaemonConfig::branch_concurrency`. Threading change touches only the constructor — the rest of `AppState` is unchanged.
Tests
BranchSlotRAII guard is a really clean pattern #178; now externally observable.Local on the dev box:
```
$ cargo fmt --all -- --check # clean
$ cargo check --all-targets # ok (12.4s)
$ cargo test -p forkd-controller --lib metrics
test http::tests::metrics_emits_prometheus_text ... ok
test http::tests::metrics_branches_in_flight_tracks_slot_acquisitions ... ok
test result: ok. 2 passed; 0 failed
```
Out of scope
The CHANGELOG is left to the maintainer (per the project convention). No CLI flag added — the cap is already configurable from #179.