Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Metrics] Prometheus exporter reports instrumentation library name instead of instrument name #1370

Closed
marcalff opened this issue May 4, 2022 · 5 comments · Fixed by #1378
Assignees
Labels
bug Something isn't working metrics priority:p1 Issues that are blocking

Comments

@marcalff
Copy link
Member

marcalff commented May 4, 2022

Greetings,

I am attempting to export to Prometheus from an application based on the Prometheus example.
WITH_METRICS_PREVIEW is undefined.

Running the example binary appears to work, and reports a metric named prometheus_metric_example, type counter,
for an instrument named prometheus_metric_example_counter in the C++ code.

Running my application,
No matter how instruments or views are named, the data exported to Prometheus always reports the same metric name,
which is the name given as instrumentation library when calling GetMeter().

Should the prometheus export code use metric_data.instrument_descriptor.name_ instead of instrumentation_info.instrumentation_library_->GetName() ?

Also, there is no HELP exported to Prometheus.

The following change helps to go further ...

Regards.

diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc
index 39131e2..0b7a26f 100644
--- a/exporters/prometheus/src/exporter_utils.cc
+++ b/exporters/prometheus/src/exporter_utils.cc
@@ -82,11 +82,17 @@ void PrometheusExporterUtils::SetMetricFamilyByAggregator(
 {
   for (const auto &instrumentation_info : data.instrumentation_info_metric_data_)
   {
+#ifdef NEVER
     auto origin_name    = instrumentation_info.instrumentation_library_->GetName();
     auto sanitized      = SanitizeNames(origin_name);
     metric_family->name = sanitized;
+#endif
     for (const auto &metric_data : instrumentation_info.metric_data_)
     {
+      auto origin_name    = metric_data.instrument_descriptor.name_;
+      auto sanitized      = SanitizeNames(origin_name);
+      metric_family->name = sanitized;
+      metric_family->help = metric_data.instrument_descriptor.description_;
       auto time = metric_data.start_ts.time_since_epoch();
       for (const auto &point_data_attr : metric_data.point_data_attr_)
       {
@marcalff marcalff added the bug Something isn't working label May 4, 2022
@esigo esigo self-assigned this May 4, 2022
@bsarden
Copy link
Contributor

bsarden commented May 4, 2022

+1: I just hit this same issue (I think) when trying to spin-up the prometheus example. I see the counter / histogram values being read out by the corresponding counter_example and histogram_example functions and am expecting a prometheus_metric_example_counter and prometheus_metric_example_histogram to exist, but instead I just have a prometheus_metric_example of TYPE counter and the only thing I can query is this:

Screen Shot 2022-05-04 at 1 42 05 PM

I'm assuming this is related because it does also seem like a metric aliasing issue, but maybe I'm down the wrong path.

@esigo
Copy link
Member

esigo commented May 4, 2022

Hi @marcalff and @bsarden, thanks for reaching out to us and also thanks for testing.
In addition to @marcalff's suggestion, we need to have a fix in meter.cc as well. I will raise a PR after running some tests.

@lalitb
Copy link
Member

lalitb commented May 5, 2022

In addition to @marcalff's suggestion, we need to have a fix in meter.cc as well. I will raise a PR after running some tests.

Just curious, what fix is required here. Based on the metrics specs, the metrics stream should use the name and description from the View if configured.

@marcalff
Copy link
Member Author

marcalff commented May 5, 2022

The spec says:

The name of the View (optional). If not provided, the Instrument name MUST be used by default. This will be used as the name of the metrics stream.

and likewise for the description.

If I understand correctly, @esigo meant something like this:

diff --git a/sdk/src/metrics/meter.cc b/sdk/src/metrics/meter.cc
index c0b0ce7..af8390b 100644
--- a/sdk/src/metrics/meter.cc
+++ b/sdk/src/metrics/meter.cc
@@ -190,7 +190,13 @@ std::unique_ptr<WritableMetricStorage> Meter::RegisterMetricStorage(
       [this, &instrument_descriptor, &storages](const View &view) {
         auto view_instr_desc         = instrument_descriptor;
         view_instr_desc.name_        = view.GetName();
+        if (view_instr_desc.name_.size() == 0) {
+          view_instr_desc.name_ = instrument_descriptor.name_;
+        }
         view_instr_desc.description_ = view.GetDescription();
+        if (view_instr_desc.description_.size() == 0) {
+          view_instr_desc.description_ = instrument_descriptor.description_;
+        }
         auto storage                 = std::shared_ptr<SyncMetricStorage>(new SyncMetricStorage(
             view_instr_desc, view.GetAggregationType(), &view.GetAttributesProcessor(),
             NoExemplarReservoir::GetNoExemplarReservoir()));

Without it, views with an empty name end up exposing metrics with empty names to Prometheus, which fails to scrap.

@lalitb
Copy link
Member

lalitb commented May 5, 2022

Without it, views with an empty name end up exposing metrics with empty names to Prometheus, which fails to scrap.

Good point. Thanks for clarifying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working metrics priority:p1 Issues that are blocking
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants