micrometer icon indicating copy to clipboard operation
micrometer copied to clipboard

`TimeWindowMax` throws `ArithmeticException` with a rotateFrequency of 0

Open Noodle-Head opened this issue 2 years ago • 3 comments

Describe the bug We are experiencing a bug caused by a modulus operation introduced in the TimeWindowMax.java class. java.lang.ArithmeticException: / by zero is thrown when running our application tests.

Environment When running integration tests locally and as a part of gitlab build

  • Micrometer version [1.8.1] (it works on [1.6.4])
  • Micrometer registry [Prometheus]
  • OS: [Windows/Linux]
  • Java version: ["11.0.12" 2021-07-20 LTS]

To Reproduce How to reproduce the bug: I am not sure how to minimalistic reproduction of the bug. Our application was working fine on Micrometer version 1.6.4. It fails when upgrading to version 1.8.1, see details below:

The bug is caused by line 139 in the TimeWindowMax.java class.

lastRotateTimestampMillis = wallTime - timeSinceLastRotateMillis % durationBetweenRotatesMillis;

This line will throw java.lang.ArithmeticException: / by zero whenever durationBetweenRoatesMillis is 0. I assume this is a bug that should be fixed.

Expected behavior I expect the calculation to work even though durationBetweenRotatesMillis is set to 0.

Noodle-Head avatar Mar 11 '22 08:03 Noodle-Head

I just ran into this one when someone set the step size for a registry to 0 as a way of "disabling" metrics reporting. Surprising error that came from SimpleMeterRegistry passing the step size forward through DistributionStatisticConfig.

        DistributionStatisticConfig merged = distributionStatisticConfig
                .merge(DistributionStatisticConfig.builder().expiry(config.step()).build());

Maybe a simple validation check somewhere along this flow would be warranted.

twicksell avatar May 28 '22 18:05 twicksell

I am closing this issue as the cause was an errendous mock of the PromotheusConfig in the test-environment.

Validation could be considered to provide better feedback when the issue is presented.

Noodle-Head avatar Jun 01 '22 10:06 Noodle-Head

I'm reopening this to improve the validation.

shakuzen avatar Jun 02 '22 05:06 shakuzen

This PR should fix things

marcingrzejszczak avatar Dec 22 '23 14:12 marcingrzejszczak