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

Console exporter display exponential histogram buckets #4344

Closed

Conversation

alanwest
Copy link
Member

Uses same format as the collector. For sake of comparison, I've included the output from our exporter and the collector's exporter using the following code.

Code

var histogram = meter.CreateHistogram<double>("histogram");
histogram.Record(-1000.01);
histogram.Record(-1000);
histogram.Record(0);
histogram.Record(1000);
histogram.Record(1000.01);

.NET console exporter

Export histogram, Meter: TestMeter
(2023-03-29T19:21:36.9011200Z, 2023-03-29T19:21:36.9130980Z] ExponentialHistogram
Value: Sum: 0 Count: 5 Min: -1000.01 Max: 1000.01 
Bucket [-1000.009769, -1000.010430), Count: 1
Bucket [-1000.009108, -1000.009769), Count: 0
Bucket [-1000.008447, -1000.009108), Count: 0
Bucket [-1000.007786, -1000.008447), Count: 0
Bucket [-1000.007125, -1000.007786), Count: 0
Bucket [-1000.006464, -1000.007125), Count: 0
Bucket [-1000.005803, -1000.006464), Count: 0
Bucket [-1000.005142, -1000.005803), Count: 0
Bucket [-1000.004480, -1000.005142), Count: 0
Bucket [-1000.003819, -1000.004480), Count: 0
Bucket [-1000.003158, -1000.003819), Count: 0
Bucket [-1000.002497, -1000.003158), Count: 0
Bucket [-1000.001836, -1000.002497), Count: 0
Bucket [-1000.001175, -1000.001836), Count: 0
Bucket [-1000.000514, -1000.001175), Count: 0
Bucket [-999.999853, -1000.000514), Count: 1
Bucket [0, 0], Count: 1
Bucket (999.999853, 1000.000514], Count: 1
Bucket (1000.000514, 1000.001175], Count: 0
Bucket (1000.001175, 1000.001836], Count: 0
Bucket (1000.001836, 1000.002497], Count: 0
Bucket (1000.002497, 1000.003158], Count: 0
Bucket (1000.003158, 1000.003819], Count: 0
Bucket (1000.003819, 1000.004480], Count: 0
Bucket (1000.004480, 1000.005142], Count: 0
Bucket (1000.005142, 1000.005803], Count: 0
Bucket (1000.005803, 1000.006464], Count: 0
Bucket (1000.006464, 1000.007125], Count: 0
Bucket (1000.007125, 1000.007786], Count: 0
Bucket (1000.007786, 1000.008447], Count: 0
Bucket (1000.008447, 1000.009108], Count: 0
Bucket (1000.009108, 1000.009769], Count: 0
Bucket (1000.009769, 1000.010430], Count: 1

Collector logging exporter

2023-03-29T19:24:40.614Z	info	ResourceMetrics #0
Resource SchemaURL: 
Resource attributes:
     -> service.name: Str(myservice)
     -> service.instance.id: Str(7a1a598d-ed31-410d-ae57-864a652e3433)
ScopeMetrics #0
ScopeMetrics SchemaURL: 
InstrumentationScope TestMeter 
Metric #0
Descriptor:
     -> Name: histogram
     -> Description: 
     -> Unit: 
     -> DataType: ExponentialHistogram
     -> AggregationTemporality: Cumulative
ExponentialHistogramDataPoints #0
StartTimestamp: 2023-03-29 19:24:40.525425 +0000 UTC
Timestamp: 2023-03-29 19:24:40.612426 +0000 UTC
Count: 5
Sum: 0.000000
Min: -1000.010000
Max: 1000.010000
Bucket (-1000.010430, -1000.009769], Count: 1
Bucket (-1000.009769, -1000.009108], Count: 0
Bucket (-1000.009108, -1000.008447], Count: 0
Bucket (-1000.008447, -1000.007786], Count: 0
Bucket (-1000.007786, -1000.007125], Count: 0
Bucket (-1000.007125, -1000.006464], Count: 0
Bucket (-1000.006464, -1000.005803], Count: 0
Bucket (-1000.005803, -1000.005142], Count: 0
Bucket (-1000.005142, -1000.004480], Count: 0
Bucket (-1000.004480, -1000.003819], Count: 0
Bucket (-1000.003819, -1000.003158], Count: 0
Bucket (-1000.003158, -1000.002497], Count: 0
Bucket (-1000.002497, -1000.001836], Count: 0
Bucket (-1000.001836, -1000.001175], Count: 0
Bucket (-1000.001175, -1000.000514], Count: 0
Bucket (-1000.000514, -999.999853], Count: 1
Bucket [0, 0], Count: 1
Bucket [999.999853, 1000.000514), Count: 1
Bucket [1000.000514, 1000.001175), Count: 0
Bucket [1000.001175, 1000.001836), Count: 0
Bucket [1000.001836, 1000.002497), Count: 0
Bucket [1000.002497, 1000.003158), Count: 0
Bucket [1000.003158, 1000.003819), Count: 0
Bucket [1000.003819, 1000.004480), Count: 0
Bucket [1000.004480, 1000.005142), Count: 0
Bucket [1000.005142, 1000.005803), Count: 0
Bucket [1000.005803, 1000.006464), Count: 0
Bucket [1000.006464, 1000.007125), Count: 0
Bucket [1000.007125, 1000.007786), Count: 0
Bucket [1000.007786, 1000.008447), Count: 0
Bucket [1000.008447, 1000.009108), Count: 0
Bucket [1000.009108, 1000.009769), Count: 0
Bucket [1000.009769, 1000.010430), Count: 1

@alanwest alanwest requested a review from a team March 29, 2023 19:35
@codecov
Copy link

codecov bot commented Mar 29, 2023

Codecov Report

Merging #4344 (7508b9c) into main (533513f) will decrease coverage by 0.07%.
The diff coverage is 0.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4344      +/-   ##
==========================================
- Coverage   84.66%   84.59%   -0.07%     
==========================================
  Files         298      298              
  Lines       11971    11990      +19     
==========================================
+ Hits        10135    10143       +8     
- Misses       1836     1847      +11     
Impacted Files Coverage Δ
...elemetry.Exporter.Console/ConsoleMetricExporter.cs 0.00% <0.00%> (ø)

... and 1 file with indirect coverage changes

negativeBucketCounts = new List<string>();
}

var lowerBound = Math.Exp(offset * factor).ToString("F6", CultureInfo.InvariantCulture);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, where is this F6 coming from, does it provide a good precision (rather than having two different buckets printed out the same thing)?


if (exponentialHistogramData.ZeroCount != 0)
{
bucketsBuilder.AppendLine($"Bucket [0, 0], Count: {exponentialHistogramData.ZeroCount}");
Copy link
Member

@reyang reyang Mar 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess ZeroCount is for [0, IEEE754 epsilon / 2].

Assert.Equal(-1075, histogram.MapToIndex(IEEE754Double.FromString("0 00000000000 0000000000000000000000000000000000000000000000000001"))); // ~4.9406564584124654E-324 (minimum subnormal positive, double.Epsilon, 2 ^ -1074)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a learning perspective, I think the output helps folk derive an intuition for exponential histograms. I'm not opposed to getting more technical and surfacing up details of the underlying IEEE 754 representation of things, but I wonder if it's helpful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'll be really bad if we have the wrong math here.
I suggest that either we use the right math, or don't use math (e.g. instead of saying [0, 0], use English - zero bucket)

https://github.com/open-telemetry/opentelemetry-proto/blob/7aa439cb0ba78afbd009d83f32fdda6c128e0342/opentelemetry/proto/metrics/v1/metrics.proto#L515-L519

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English works for me.

}

var lowerBound = Math.Exp(offset * factor).ToString("F6", CultureInfo.InvariantCulture);
var upperBound = Math.Exp(++offset * factor).ToString("F6", CultureInfo.InvariantCulture);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to give the accurate IEEE 754 representation or there will be drifts due to precision losses or we don't know?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty confident this is absolutely imprecise 😆. I guess we need to consider the audience and use case we're trying to serve.

To me this verbose format is mainly for learning, debugging, non-production kind of use cases.

F6 truncates things to 6 decimal places so that the width of the output is somewhat fixed and easier to read. I chose 6 simply because that's what the collector seems to display (might just be default formatting in Go).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I essentially implemented the LowerBoundary reverse mapping method here

https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/data-model.md#all-scales-use-the-logarithm-function.

My understanding is that this is valid for both positive and negative scales. There is a note about the possibility that the maximum index is incorrectly computed as +Inf. I can verify.

@utpilla
Copy link
Contributor

utpilla commented Mar 29, 2023

Is this discrepancy in the outputs expected?

ConsoleExporter

Bucket [-1000.009769, -1000.010430), Count: 1
Bucket [-999.999853, -1000.000514), Count: 1

Collector

Bucket (-1000.010430, -1000.009769], Count: 1
Bucket (-1000.000514, -999.999853], Count: 1

@alanwest
Copy link
Member Author

Is this discrepancy in the outputs expected?

Good eye. Had the bounds reversed. Fixed. You might have also noticed the difference in the interval notation. This is a bug in the collector. I fixed it yesterday open-telemetry/opentelemetry-collector#7445

@github-actions
Copy link
Contributor

github-actions bot commented Apr 6, 2023

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day.

@github-actions github-actions bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label Apr 6, 2023
@github-actions
Copy link
Contributor

Closed as inactive. Feel free to reopen if this PR is still being worked on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale Issues and pull requests which have been flagged for closing due to inactivity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants