Repository navigation
Description
Subissue of EPIC #1669 (Overhaul: Packages). This is the follow-up recorded in the Out of Scope section of #2517.
Goal
Remove the lock type and the MetricCollection field from the public read API of the five statistics repositories. Callers read metrics through a closure that the repository runs while it holds its read lock, and through a read-only metric_collection() accessor on Metrics. The repositories can then change their locking or storage without a breaking release.
Problem
#2517 made each repository's stats: Arc<RwLock<Metrics>> field private, but the read accessors still return the lock's read guard:
| Package | Read accessor | Return type |
|---|---|---|
udp-core |
get_stats() |
RwLockReadGuard<'_, Metrics> |
udp-server |
get_stats() |
RwLockReadGuard<'_, Metrics> |
http-core |
get_stats() |
RwLockReadGuard<'_, Metrics> |
tracker-core |
get_metrics() |
RwLockReadGuard<'_, Metrics> |
swarm-coordination-registry |
get_metrics() |
RwLockReadGuard<'_, Metrics> |
tokio::sync::RwLockReadGuardis part of each crate's public API, so replacing the lock would be a breaking change.- A caller can hold the guard across an
.await, blocking the statistics event listeners that write metrics. - Each
Metricstype has apub metric_collection: MetricCollectionfield, which makes its layout public API too.
None of the five crates is published yet, so this can change without a semver-major bump if it lands before their first publish.
Proposed design
- Replace
get_stats()/get_metrics()withpub async fn read_metrics<R>(&self, read: impl FnOnce(&Metrics) -> R) -> Rin all five repositories. It needs no lock type in its signature, gives consistent multi-value reads from one lock acquisition, clones nothing, and the closure cannot await. - Make
Metrics.metric_collectionpub(crate)and addpub fn metric_collection(&self) -> &MetricCollection.
Scope
- The five repositories and their
Metricstypes. - Callers:
rest-api-runtime-adapter, the only production caller outside the crates;- the debug logging in the
udp-core,udp-server, andhttp-coreevent handlers, which must stay lazy so that disableddebuglogging takes no lock; - the tracker-core repository's own counter reads;
- tests in other crates.
- Doctests that pin the private field and show the new reads, and an update to the Make the statistics repositories' metrics lock private #2517 doctests that call the removed accessors.
Out of scope: the write methods, the lock type itself, the Metrics value methods, unifying the repositories, and the stats field name.
Specification
The full specification, with acceptance criteria and the verification plan, is added to docs/issues/open/ by its spec-only PR.
Activity
docs(issues): [torrust#2536] record non-blocking read closures as a c…
docs(issues): [torrust#2536] require the per-increment test-design re…
docs(issues): [torrust#2536] keep the debug-log example's output unch…
docs(issues): [torrust#2536] list the in-crate unit-test callers
docs(issues): [torrust#2536] name the stored M1 outputs and their nor…
docs(issues): [torrust#2536] name the sibling specs that overlap the …
docs(issues): [torrust#2536] make the AC1 call grep give an exact result
docs(issues): [torrust#2536] cover the rustdoc links to the removed a…
docs(issues): [torrust#2536] add the helper-boundary check to the tes…
docs(issues): [torrust#2536] hold T7's commit until the maintainer re…
41 remaining items
refactor(tracker-core): [#2536] hide the statistics read lock and met…
docs(adrs): [#2536] record closure-based reads for the statistics rep…
refactor(swarm-coordination-registry): [#2536] hide the statistics re…
docs(issues): [#2536] record manual verification and final spec status
Merge torrust#2545: refactor(statistics): [torrust#2536] hide the sta…
docs(issues): [torrust#2536] correct two checkpoint ticks in the arch…
docs(pr-reviews): [torrust#2536] record the PR torrust#2554 review audit
docs(issues): [torrust#2536] count both commits without a log entry a…
docs(pr-reviews): [torrust#2536] record the second review round of PR t…
chore(issues): archive closed issue #2536 spec to docs/issues/closed
Merge #2554: chore(issues): archive closed issue #2536 spec to docs/i…
docs(issues): [#1349] record http core coverage baseline and inventory
Merge #2558: docs(issues): [#1349] add the http-core coverage invento…
Merge #2587: chore(issues): archive closed issue #2414 spec to docs/i…
Merge #2615: chore(issues): archive closed issue #2518 spec to docs/i…