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] UInt64Histogram does not honour custom boundaries #1865

Closed
sam-leitch-oxb opened this issue Dec 14, 2022 · 1 comment
Closed

[Metrics] UInt64Histogram does not honour custom boundaries #1865

sam-leitch-oxb opened this issue Dec 14, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@sam-leitch-oxb
Copy link

If you CreateUInt64Histogram and add custom boundaries using a view, the counts output doesn't match the expected output.
Note CreateDoubleHistogram works as expected

This unit test can demonstrate the problem and expected output.

TEST(MeterProvider, UInt64HistogramBuckets)
{
  MeterProvider mp;
  auto m = mp.GetMeter("meter1", "version1", "schema1");

  std::unique_ptr<MockMetricExporter> exporter(new MockMetricExporter());
  std::shared_ptr<MetricReader> reader{new MockMetricReader(std::move(exporter))};
  mp.AddMetricReader(reader);

  std::shared_ptr<HistogramAggregationConfig> config(new HistogramAggregationConfig());
  config->boundaries_ = {10, 20, 30, 40};
  std::unique_ptr<View> view{new View("view1", "view1_description", AggregationType::kHistogram, config)};
  std::unique_ptr<InstrumentSelector> instrument_selector{
      new InstrumentSelector(InstrumentType::kHistogram, "histogram1")};
  std::unique_ptr<MeterSelector> meter_selector{new MeterSelector("meter1", "version1", "schema1")};
  mp.AddView(std::move(instrument_selector), std::move(meter_selector), std::move(view));

  auto h = m->CreateUInt64Histogram("histogram1", "histogram1_description", "histogram1_unit");

  h->Record(10, {});
  h->Record(20, {});
  h->Record(30, {});
  h->Record(40, {});
  h->Record(50, {});

  std::list<double> actual_boundaries;
  std::vector<uint64_t> actual_counts;
  reader->Collect([&](ResourceMetrics &rm) {
    for(const ScopeMetrics& smd : rm.scope_metric_data_) {
      for(const MetricData& md : smd.metric_data_) {
        for(const PointDataAttributes& dp : md.point_data_attr_) {
          auto data = opentelemetry::nostd::get<HistogramPointData>(dp.point_data);
          actual_boundaries = data.boundaries_;
          actual_counts = data.counts_;
        }
      }
    }
    return true;
  });
  ASSERT_EQ(std::list<double>({10, 20, 30, 40}), actual_boundaries);
  ASSERT_EQ(std::vector<uint64_t>({1, 1, 1, 1, 1}), actual_counts);
}

The output of this test is:

Expected equality of these values:
  std::vector<uint64_t>({1, 1, 1, 1, 1})
    Which is: { 1, 1, 1, 1, 1 }
  actual_counts
    Which is: { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }

The boundaries_ values are correct, but the counts_ are wrong
16 count values is the expected size for the default set of boundaries, but the counts don't match default boundaries.

This has been tested against release 1.7.0, 1.8.1 and commit e7579ed

@lalitb
Copy link
Member

lalitb commented Jan 13, 2023

#1869 fixes this.

@lalitb lalitb closed this as completed Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants