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

For long task timers fixes the percentiles above interpolatable line #4511

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

marcingrzejszczak
Copy link
Contributor

without this change for the provided test one of the histogram buckets gets removed and an ArrayIndexOutOfBoundsException is thrown with this change the exception is not thrown anymore

fixes gh-3877

SimpleMeterRegistry simpleMeterRegistry = new SimpleMeterRegistry();

LongTaskTimer timer = LongTaskTimer.builder("jobrunr.jobs")
.publishPercentiles(0.25, 0.5, 0.75, 0.8, 0.9, 0.95)
Copy link
Member

Choose a reason for hiding this comment

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

The test fails if this is changed to the other example given in the issue: 0.11, 0.22, 0.33, 0.44. I'm not sure why it makes a difference to be honest but the following change makes both cases pass without the change to DefaultLongTaskTimer.

Index: micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/HistogramGauges.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/HistogramGauges.java b/micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/HistogramGauges.java
--- a/micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/HistogramGauges.java	(revision e38f5e87dac6566e7909628afa7aa4f7fde6f170)
+++ b/micrometer-core/src/main/java/io/micrometer/core/instrument/distribution/HistogramGauges.java	(date 1705478240207)
@@ -116,7 +116,7 @@
             ToDoubleFunction<HistogramSupport> percentileValueFunction = m -> {
                 snapshotIfNecessary();
                 polledGaugesLatch.countDown();
-                return percentileValue.apply(snapshot.percentileValues()[index]);
+                return percentileValue.apply(valueAtPercentiles[index]);
             };
 
             Gauge.builder(percentileName.apply(valueAtPercentiles[i]), meter, percentileValueFunction)

Copy link
Member

@shakuzen shakuzen Mar 5, 2024

Choose a reason for hiding this comment

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

My suggested change is not correct. We definitely need more tests in this area of the code to be confident the behavior is correct. I'll take a closer look tomorrow soon.

without this change for the provided test one of the histogram buckets gets removed and an ArrayIndexOutOfBoundsException is thrown
with this change the exception is not thrown anymore

fixes gh-3877
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.

ArrayIndexOutOfBoundsException when using LongTaskTimer
2 participants