micrometer
micrometer copied to clipboard
`TimeWindowMax` throws `ArithmeticException` with a rotateFrequency of 0
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.
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.
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.
I'm reopening this to improve the validation.
This PR should fix things