-
Notifications
You must be signed in to change notification settings - Fork 512
Description
Greetings
This is a follow up on:
[Metrics] Prometheus exporter reports instrumentation library name instead of instrument name #1370
In method PrometheusExporterUtils::SetMetricFamilyByAggregator(), the code contains an outer loop:
for (const auto &instrumentation_info : data.instrumentation_info_metric_data_)
This loop is executed once per Meter, per method MetricCollector::Collect(),
so when exporting data for multiple meters, all the data will be written to the same
prometheus_client::MetricFamily *metric_family
output, which seems incorrect.
Also, even when considering a single Meter,
the next loop:
for (const auto &metric_data : instrumentation_info.metric_data_)
considers all the instruments exported by a Meter.
Again, this loop is executed once per instrument, resulting in all metrics data exported to the same metric_family object,
which seems incorrect.
A prometheus prometheus_client::MetricFamily object has only one name and description, so it should map to one otel metric, not N (in my understanding).
Multiple metrics from the same meter will be mixed together in the output.
When testing, indeed, with a Meter with N instruments, the prometheus exporter only exposes 1 instrument (the last one considered).
I did not inspect the measurements values exported, but suspects this is a union of all the measurements seen.
I would like to suggest the following changes, to evaluate and discuss (I don't know the code well enough yet):
- add a method to compute the number of
prometheus_client::MetricFamilyto export - use it from
PrometheusExporterUtils::TranslateToPrometheusto size the output correctly - abandon the
prometheus_client::MetricFamily *metric_familyparameter fromPrometheusExporterUtils::SetMetricFamily()andPrometheusExporterUtils::SetMetricFamilyByAggregator() - instead, pass the whole
std::vector<prometheus_client::MetricFamily>output as parameter - In
PrometheusExporterUtils::SetMetricFamilyByAggregator, let the code append more metric_family in the output vector as the code sees fit. - Minor renaming, as "SetMetricFamillyxxx" no longer makes sense without a metric family output parameter.
Regards.