Skip to content

ArrayIndexOutOfBoundsException when using LongTaskTimer #3877

@rdehuyss

Description

@rdehuyss

Describe the bug / it may be a question
I'm seeing ArrayIndexOutOfBoundsException in my logs when using LongTaskTimer.

Environment

  • Micrometer version 1.11.0
  • Micrometer registry: SimpleMeterRegistry
  • OS: macOS
  • Java version: openjdk version "17.0.1" 2021-10-19

To Reproduce

    @Test
    void reproduceIssue() throws InterruptedException {
        SimpleMeterRegistry simpleMeterRegistry = new SimpleMeterRegistry();

        LongTaskTimer timer = LongTaskTimer.builder("jobrunr.jobs")
                .publishPercentiles(0.25, 0.5, 0.75, 0.8, 0.9, 0.95)
                .publishPercentileHistogram()
                .register(simpleMeterRegistry);
        LongTaskTimer.Sample start = timer.start();
        Thread.sleep(3640);
        System.out.println(simpleMeterRegistry.getMetersAsString());
        Thread.sleep(2640);
        System.out.println(start.stop());

        System.out.println(simpleMeterRegistry.getMetersAsString());
    }

This results in the following output:

08:46:23.327 [Test worker] WARN  i.m.c.i.internal.DefaultGauge - Failed to apply the value function for the gauge 'jobrunr.jobs.percentile'. Note that subsequent logs will be logged at debug level.
java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5
	at io.micrometer.core.instrument.distribution.HistogramGauges.lambda$new$9(HistogramGauges.java:119)
	at io.micrometer.core.instrument.internal.DefaultGauge.value(DefaultGauge.java:53)
	at io.micrometer.core.instrument.Measurement.getValue(Measurement.java:54)
	at io.micrometer.core.instrument.simple.SimpleMeterRegistry.toString(SimpleMeterRegistry.java:206)
	at io.micrometer.core.instrument.simple.SimpleMeterRegistry.lambda$toString$1(SimpleMeterRegistry.java:195)
jobrunr.jobs(LONG_TASK_TIMER)[]; active_tasks=1.0, duration=3.651603291 seconds
jobrunr.jobs.percentile(GAUGE)[phi='0.25']; value=3.653785708 seconds
jobrunr.jobs.percentile(GAUGE)[phi='0.9']; value=3.653818208 seconds
jobrunr.jobs.percentile(GAUGE)[phi='0.8']; value=3.653818208 seconds
jobrunr.jobs.percentile(GAUGE)[phi='0.5']; value=3.653818208 seconds
jobrunr.jobs.percentile(GAUGE)[phi='0.95']; value=NaN seconds
jobrunr.jobs.percentile(GAUGE)[phi='0.75']; value=3.653818208 seconds
6322804041
jobrunr.jobs(LONG_TASK_TIMER)[]; active_tasks=0.0, duration=0.0 seconds
jobrunr.jobs.percentile(GAUGE)[phi='0.25']; value=0.0 seconds
jobrunr.jobs.percentile(GAUGE)[phi='0.9']; value=0.0 seconds
jobrunr.jobs.percentile(GAUGE)[phi='0.8']; value=0.0 seconds
jobrunr.jobs.percentile(GAUGE)[phi='0.5']; value=0.0 seconds
jobrunr.jobs.percentile(GAUGE)[phi='0.95']; value=0.0 seconds
jobrunr.jobs.percentile(GAUGE)[phi='0.75']; value=0.0 seconds

Expected behavior
No ArrayIndexOutOfBoundsException should happen.

Additional context
NA

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA general bugmodule: micrometer-coreAn issue that is related to our core module

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions