]> 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)
committerasterisk-org-access-app[bot] <120671045+asterisk-org-access-app[bot]@users.noreply.github.com>
Thu, 21 Mar 2024 18:55:23 +0000 (18:55 +0000)
commit688095c6cb7139b71bd82dc6dbf3cdf8e934ddbd
tree0514e956e82e8595342f3228d230776b279952ae
parentef7788e0e4f49e742f7025ffe923995e75e9608a
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