Skip to content

fix(metrics): expose completed download retention - #2127

Merged
josecelano merged 4 commits into
torrust:developfrom
josecelano:2122-expose-unambiguous-download-counter-semantics
Sep 1, 2026
Merged

josecelano merged 4 commits into
torrust:developfrom
josecelano:2122-expose-unambiguous-download-counter-semantics

Conversation

@josecelano

Copy link
Copy Markdown
Member

Summary

Expose explicit in_session and persisted completed-download counters while retaining the legacy v1 REST field and Prometheus metric as deprecated compatibility views.

  • Add additive v1 completed_in_session, completed_persisted, and completed_persisted_enabled fields with backward-compatible deserialization.
  • Omit the persisted Prometheus metric when persistent completed statistics are disabled; preserve a zero-valued sample when enabled.
  • Add a repository-wide ADR, tracker-core/REST contract regressions, and local SQLite manual-verification evidence.

Verification

  • Mandatory pre-commit gate passed.
  • Full pre-push suite passed: nightly format/check/docs and all stable workspace tests.
  • M1-M3 completed locally using persistence-free and SQLite configurations.

Closes #2122

Copilot AI lite review requested due to automatic review settings September 1, 2026 12:21
@josecelano josecelano self-assigned this Sep 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses #2122 by making completed-download retention semantics explicit across tracker-core metrics and the REST API v1 stats response, while keeping the legacy v1 completed field and legacy Prometheus metric as deprecated compatibility views.

Changes:

  • Split tracker-core completed-download counters into explicit in_session and persisted views, and make the persisted Prometheus series capability-aware (omitted when disabled).
  • Extend REST API v1 stats with additive completed_in_session, completed_persisted, and completed_persisted_enabled fields (including backward-compatible deserialization).
  • Add/extend contract and integration regressions, plus ADR + issue evidence updates documenting the retention naming/behavior.

Reviewed changes

Copilot reviewed 21 out of 22 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/bootstrap/jobs/tracker_core.rs Wires the stats repository into the persistent completed-statistics listener job.
packages/tracker-core/tests/integration.rs Adds regressions proving in-session reset and persisted totals across restart scenarios.
packages/tracker-core/tests/common/test_env.rs Allows persistence-free composition in the test harness and gates persisted-metric loading.
packages/tracker-core/src/statistics/repository.rs Adds explicit getters and config-driven metric description for in-session vs persisted counters.
packages/tracker-core/src/statistics/persisted/mod.rs Loads both legacy and persisted counters from DB on startup when enabled.
packages/tracker-core/src/statistics/mod.rs Defines new metric identifiers, updates descriptions, and introduces deterministic zero initialization.
packages/tracker-core/src/statistics/event/listener.rs Passes the stats repository into the persistent listener dispatch path.
packages/tracker-core/src/statistics/event/handler.rs Increments in-session on in-memory completion; increments persisted only after successful DB update.
packages/tracker-core/src/container.rs Constructs the stats repository with validated capability flags from config.
packages/rest-api-runtime-adapter/src/v1/adapters/stats.rs Maps tracker-core counters into v1 DTO fields and injects persisted-availability boolean.
packages/rest-api-protocol/src/v1/context/stats/resources/stats.rs Adds the new v1 fields with serde defaults + legacy-deserialization regression.
packages/rest-api-protocol/Cargo.toml Adds serde_json dev-dependency for protocol deserialization tests.
packages/axum-rest-api-server/tests/server/v1/contract/context/stats.rs Extends v1 contract tests to cover fields and Prometheus export presence/omission.
packages/axum-rest-api-server/src/v1/routes.rs Derives completed_persisted_enabled from validated tracker-core config during composition.
packages/axum-rest-api-server/src/v1/context/stats/responses.rs Adds the new fields to the deprecated v1 “stats-as-prometheus” text response.
packages/axum-rest-api-server/src/v1/context/stats/mod.rs Updates v1 stats context docs to describe deprecation + new fields.
packages/axum-rest-api-server/src/testing/environment.rs Aligns test env composition error messaging with broader “valid composition” expectation.
docs/issues/open/2122-expose-unambiguous-download-counter-semantics/manual-verification.md Records local evidence runs for disabled/enabled persistence scenarios.
docs/issues/open/2122-expose-unambiguous-download-counter-semantics/ISSUE.md Marks tasks/ACs as DONE and records evidence/ADR references.
docs/adrs/index.md Indexes the new repository-wide ADR.
docs/adrs/20260901113500_define_completed_download_metric_retention_names.md Defines the retention naming contract and the v1 additive migration bridge.
Cargo.lock Locks the new serde_json dev dependency for rest-api-protocol tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.77612% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.15%. Comparing base (68fc2ec) to head (1899d73).

Files with missing lines Patch % Lines
...-rest-api-server/src/v1/context/stats/responses.rs 0.00% 3 Missing ⚠️
packages/tracker-core/src/statistics/mod.rs 97.05% 0 Missing and 1 partial ⚠️
...kages/tracker-core/src/statistics/persisted/mod.rs 87.50% 0 Missing and 1 partial ⚠️
packages/tracker-core/src/statistics/repository.rs 97.67% 1 Missing ⚠️
src/bootstrap/jobs/tracker_core.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2127      +/-   ##
===========================================
+ Coverage    84.04%   84.15%   +0.11%     
===========================================
  Files          349      350       +1     
  Lines        27376    27498     +122     
  Branches     27376    27498     +122     
===========================================
+ Hits         23007    23140     +133     
+ Misses        4022     4011      -11     
  Partials       347      347              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@josecelano

Copy link
Copy Markdown
Member Author

ACK 1899d73

@josecelano
josecelano merged commit bf81226 into torrust:develop Sep 1, 2026
27 checks passed

This branch was previously deployed

1 inactive deployment
coverage — 1899d730 Deployed Sep 1, 2026 by josecelano via Generate Coverage Report #1878
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose unambiguous download counter semantics

2 participants