Skip to content

Conversation

@josecelano
Copy link
Member

@josecelano josecelano commented Jun 5, 2025

Add metadata describing the metric to the Prometheus export format. For example:

# HELP udp_tracker_server_requests_received_total Total number of UDP requests received
# TYPE udp_tracker_server_requests_received_total counter
udp_tracker_server_requests_received_total{server_binding_ip="0.0.0.0",server_binding_port="6868",server_binding_protocol="udp"} 36661

Subtasks

  • Rename kind JSON field to type to use the same name in JSON and Prometheus export formats.
  • Change ensure_metric_exists to pass the whole metric, not only the name.
  • Add metadata fields to generic metric: opt_unit: Option<Unit> and opt_description: Option<&MetricDescription> to Metric<T>
  • Change JSON serialization to include the metric description (description).
  • Change Prometheus serialization to include the metric type (TYPE) and description (HELP).
  • Review test coverage.

"kind" has been renamed to "type" to follow Prometheus name.

```json
{
  "type": "counter",
  "name": "http_tracker_core_requests_received_total",
  "samples": []
}
```
@josecelano josecelano requested a review from da2ce7 June 5, 2025 11:13
@josecelano josecelano self-assigned this Jun 5, 2025
@josecelano josecelano linked an issue Jun 5, 2025 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Jun 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.95%. Comparing base (33e69ff) to head (bb2392d).
Report is 13 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1559      +/-   ##
===========================================
+ Coverage    83.40%   83.95%   +0.55%     
===========================================
  Files          282      282              
  Lines        19868    20250     +382     
  Branches     19868    20250     +382     
===========================================
+ Hits         16570    17001     +431     
+ Misses        3003     2954      -49     
  Partials       295      295              

☔ View full report in Codecov by Sentry.
📢 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.

It's also shown in the JSON export format.

```json
{
  "metrics": [
    {
      "type": "counter",
      "name": "torrent_repository_torrents_downloads_total",
      "unit": "count",
      "description": "The total number of torrent downloads.",
      "samples": []
    }
}
```

todo: show them in the Prometheus export format.
@josecelano
Copy link
Member Author

josecelano commented Jun 6, 2025

I've finished the implementation, and I'm going to review the tests coverage:

image

…c name

Format for each metric sample:

<metric_name>{label_set} <value>

Exmaple:

```
udp_tracker_server_requests_received_total{server_binding_ip="0.0.0.0",server_binding_port="6868",server_binding_protocol="udp"} 36661
```

See https://prometheus.io/docs/instrumenting/exposition_formats/#comments-help-text-and-type-information
…e same metrin name

It was not possible to merge counters or gauges if the metric names was
duplicate but possible when the metric name was duplciate across types.

For example, the target collection (the one is mutated) contains a counter with a name that is being used in the source collection (the wan we get metric from) for a gauge metric.
@josecelano
Copy link
Member Author

New test coverage report:

image

@josecelano
Copy link
Member Author

ACK bb2392d

@josecelano josecelano marked this pull request as ready for review June 6, 2025 17:04
@josecelano josecelano added Enhancement / Feature Request Something New - Admin - Enjoyable to Install and Setup our Software labels Jun 6, 2025
@josecelano josecelano merged commit 0e3a305 into torrust:develop Jun 6, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

- Admin - Enjoyable to Install and Setup our Software Enhancement / Feature Request Something New

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overhaul stats: add TYPE and HELP to Prometheus export

1 participant