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

Added check on rotate frequency #4509

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public TimeWindowMax(Clock clock, DistributionStatisticConfig config) {

public TimeWindowMax(Clock clock, long rotateFrequencyMillis, int bufferLength) {
this.clock = clock;
this.durationBetweenRotatesMillis = rotateFrequencyMillis;
this.durationBetweenRotatesMillis = checkPositive(rotateFrequencyMillis);
this.lastRotateTimestampMillis = clock.wallTime();
this.currentBucket = 0;

Expand All @@ -64,6 +64,13 @@ public TimeWindowMax(Clock clock, long rotateFrequencyMillis, int bufferLength)
}
}

private static long checkPositive(long rotateFrequencyMillis) {
if (rotateFrequencyMillis <= 0) {
throw new IllegalArgumentException("Rotate frequency must be a positive number");
}
return rotateFrequencyMillis;
}

/**
* For use by timer implementations.
* @param sample The value to record.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.micrometer.core.instrument.distribution;

import io.micrometer.core.instrument.MockClock;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

import java.time.Duration;
Expand Down Expand Up @@ -68,4 +69,11 @@ void testLongPeriodOfInactivity() {
assertThat(timeWindowMax.poll()).isEqualTo(100500); // 666 | 500 | 100500
}

@Test
void throwsExceptionWhenRotateFrequency0() {
Assertions.assertThatThrownBy(() -> new TimeWindowMax(clock, 0, 3))
.isInstanceOf(IllegalArgumentException.class)
.withFailMessage("Rotate frequency must be a positive number");
}

}