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

feat: add support for Otlp exponential histograms #38

Merged
merged 5 commits into from
Mar 20, 2024

Conversation

tylerburdsall
Copy link
Contributor

Adds support for Otlp exponential histograms. This is more or less the JVM implementation
of the goodmetrics_rs feature.

Unit tests were grabbed from the latest main of the Rust implementation's unit tests,
so this helped ensure development was correct. That being said, it is entirely
possible I have missed something in the actual conversion to Otlp protocol.

I also added a new sealed interface called DistributionMode so consumers can explicitly set which aggregation mode they would
like to use. Considering exponential histograms are a "newer" technology, the default is set to Histogram so this new version
is not a breaking change.

Unit tests all pass and indicate that this behavior is correct.

The key difference here is that I opted not to use a LongAdder for the buckets out of simplicity.
If that needs to change, I am more than happy to change that.

Copy link
Owner

@kvc0 kvc0 left a comment

Choose a reason for hiding this comment

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

This change looks great - I think it's a good port of the rust feature. I have but one concern:

Metrics are emit()ted on multiple threads. Today, normal histograms account for that with ConcurrentHashMap and LongAdder. But the exponential histogram strategy involves changing multiple things in one shot atomically. If multiple threads emit metrics at the same time this will result in unsound metrics. I think you need to lock the critical section of the ExponentialHistogram implementation to make this thread safe - i.e., LongAdders will not get you there.

@tylerburdsall tylerburdsall requested a review from kvc0 March 20, 2024 15:00

// Verify multi-threaded access is indeed safe
@Test
fun testExponentialHistogramMultiThreadedAccess() = runBlocking {
Copy link
Owner

Choose a reason for hiding this comment

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

This runs the test on 1 thread with 2 coroutines. This does not exercise multi-threaded access. I'd recommend using simple thread spawn apis and have each of 8 threads accumulate 10000 times each with no delays or sleeps. Join the 8 threads then assert that the accumulation is as you expect it to be.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah that sounds good, I'll try it with that, thank you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tylerburdsall tylerburdsall requested a review from kvc0 March 20, 2024 18:01
Copy link
Owner

@kvc0 kvc0 left a comment

Choose a reason for hiding this comment

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

looks good. Thanks for the feature.

@kvc0 kvc0 merged commit 81b1520 into kvc0:main Mar 20, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants