mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-20 08:40:16 +00:00
res_prometheus: Do not generate broken metrics
In8d6fdf9c3ainvisible bridges were skipped but that lead to producing metrics with no name and no help. Keep track of the number of metrics configured and then only emit these. Add a basic testcase that verifies that there is no '(NULL)' in the output. ASTERISK-30474 (cherry picked from commita10de8bc72)
This commit is contained in:
committed by
Asterisk Development Team
parent
e05f51a8ae
commit
986c71953c
@@ -83,7 +83,7 @@ static void bridges_scrape_cb(struct ast_str **response)
|
||||
struct ast_bridge *bridge;
|
||||
struct prometheus_metric *bridge_metrics;
|
||||
char eid_str[32];
|
||||
int i, j, num_bridges;
|
||||
int i, j, num_bridges, num_outputs = 0;
|
||||
struct prometheus_metric bridge_count = PROMETHEUS_METRIC_STATIC_INITIALIZATION(
|
||||
PROMETHEUS_METRIC_GAUGE,
|
||||
"asterisk_bridges_count",
|
||||
@@ -138,7 +138,7 @@ static void bridges_scrape_cb(struct ast_str **response)
|
||||
}
|
||||
|
||||
for (j = 0; j < ARRAY_LEN(bridge_metric_defs); j++) {
|
||||
int index = i * ARRAY_LEN(bridge_metric_defs) + j;
|
||||
int index = num_outputs++;
|
||||
|
||||
bridge_metrics[index].type = PROMETHEUS_METRIC_GAUGE;
|
||||
ast_copy_string(bridge_metrics[index].name, bridge_metric_defs[j].name, sizeof(bridge_metrics[index].name));
|
||||
@@ -159,7 +159,7 @@ static void bridges_scrape_cb(struct ast_str **response)
|
||||
}
|
||||
ao2_iterator_destroy(&it_bridges);
|
||||
|
||||
for (j = 0; j < ARRAY_LEN(bridge_metric_defs); j++) {
|
||||
for (j = 0; j < num_outputs; j++) {
|
||||
prometheus_metric_to_string(&bridge_metrics[j], response);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user