]> git.ipfire.org Git - thirdparty/asterisk.git/commit
res_prometheus: Fix duplicate output of metric and help text
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>
Sat, 24 Feb 2024 09:32:19 +0000 (17:32 +0800)
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>
Thu, 21 Mar 2024 18:55:16 +0000 (18:55 +0000)
commit7b1807413df00169639169853b1b0543520a8767
tree35b133ea079887978b023a951a060995c75afb61
parent6f5ca2cb5118d5a09b9c79d743fe22caff7b699b
res_prometheus: Fix duplicate output of metric and help text

The prometheus exposition format requires each line to be unique[1].
This is handled by struct prometheus_metric having a list of children
that is managed when registering a metric. In case the scrape callback
is used, it is the responsibility of the implementation to handle this
correctly.

Originally the bridge callback didn't handle NULL snapshots, the crash
fix lead to NULL metrics, and fixing that lead to duplicates.

The original code assumed that snapshots are not NULL and then relied on
"if (i > 0)" to establish the parent/children relationship between
metrics of the same class. This is not workerable as the first bridge
might be invisible/lacks a snapshot.

Fix this by keeping a separate array of the first metric by class.
Instead of relying on the index of the bridge, check whether the array
has an entry. Use that array for the output.

Add a test case that verifies that the help text is not duplicated.

Resolves: #642

[1] https://prometheus.io/docs/instrumenting/exposition_formats/#grouping-and-sorting
res/prometheus/bridges.c
tests/test_res_prometheus.c