]> 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 Development Team <asteriskteam@digium.com>
Thu, 9 May 2024 13:47:40 +0000 (13:47 +0000)
commit2b69cb3e1c76d463b8ccb66a461ccd3011a14ecf
tree21313b4c924a2d10a7be8f129fd8bb7641cb297d
parent9a3c6177e611730b65f52715bf78b6b544cb46b4
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

(cherry picked from commit 7b1807413df00169639169853b1b0543520a8767)
res/prometheus/bridges.c
tests/test_res_prometheus.c