-
Notifications
You must be signed in to change notification settings - Fork 224
improve: Make MicrometerMetrics extendable #2912
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
Closed
Donnerbart
wants to merge
1
commit into
operator-framework:main
from
Donnerbart:improvement/2884-make-micrometermetrics-extendable
+194
−21
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...t/src/test/java/io/javaoperatorsdk/operator/monitoring/micrometer/CleanerBuilderTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package io.javaoperatorsdk.operator.monitoring.micrometer; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.javaoperatorsdk.operator.monitoring.micrometer.MicrometerMetrics.CleanerBuilder; | ||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class CleanerBuilderTest { | ||
|
||
private final SimpleMeterRegistry registry = new SimpleMeterRegistry(); | ||
|
||
@Test | ||
void test_defaultsToNoopCleaner() { | ||
final var cleaner = new CleanerBuilder(registry).build(); | ||
assertThat(cleaner).isSameAs(MicrometerMetrics.Cleaner.NOOP); | ||
} | ||
|
||
@Test | ||
void test_withCleaningThreadNumber() { | ||
final var cleaner = new CleanerBuilder(registry).withCleaningThreadNumber(42).build(); | ||
assertThat(cleaner).isInstanceOf(MicrometerMetrics.DelayedCleaner.class); | ||
if (cleaner instanceof MicrometerMetrics.DelayedCleaner delayedCleaner) { | ||
assertThat(delayedCleaner.getCleanUpDelayInSeconds()).isEqualTo(0); | ||
} | ||
} | ||
|
||
@Test | ||
void test_withCleaningThreadNumber_whenNegative_thenApplyDefault() { | ||
final var cleaner = new CleanerBuilder(registry).withCleaningThreadNumber(42).build(); | ||
assertThat(cleaner).isInstanceOf(MicrometerMetrics.DelayedCleaner.class); | ||
if (cleaner instanceof MicrometerMetrics.DelayedCleaner delayedCleaner) { | ||
assertThat(delayedCleaner.getCleanUpDelayInSeconds()).isEqualTo(0); | ||
} | ||
} | ||
|
||
@Test | ||
void test_withCleaningThreadNumber_whenZero_thenApplyDefault() { | ||
final var cleaner = new CleanerBuilder(registry).withCleaningThreadNumber(0).build(); | ||
assertThat(cleaner).isInstanceOf(MicrometerMetrics.DelayedCleaner.class); | ||
if (cleaner instanceof MicrometerMetrics.DelayedCleaner delayedCleaner) { | ||
assertThat(delayedCleaner.getCleanUpDelayInSeconds()).isEqualTo(0); | ||
} | ||
} | ||
|
||
@Test | ||
void test_withCleanUpDelayInSeconds() { | ||
final var cleaner = new CleanerBuilder(registry).withCleanUpDelayInSeconds(23).build(); | ||
assertThat(cleaner).isInstanceOf(MicrometerMetrics.DelayedCleaner.class); | ||
if (cleaner instanceof MicrometerMetrics.DelayedCleaner delayedCleaner) { | ||
assertThat(delayedCleaner.getCleanUpDelayInSeconds()).isEqualTo(23); | ||
} | ||
} | ||
|
||
@Test | ||
void test_withCleanUpDelayInSeconds_whenNegative_thenApplyDefault() { | ||
final var cleaner = new CleanerBuilder(registry).withCleanUpDelayInSeconds(-23).build(); | ||
assertThat(cleaner).isInstanceOf(MicrometerMetrics.DelayedCleaner.class); | ||
if (cleaner instanceof MicrometerMetrics.DelayedCleaner delayedCleaner) { | ||
assertThat(delayedCleaner.getCleanUpDelayInSeconds()).isEqualTo(1); | ||
} | ||
} | ||
|
||
@Test | ||
void test_withCleanUpDelayInSeconds_whenZero_thenApplyDefault() { | ||
final var cleaner = new CleanerBuilder(registry).withCleanUpDelayInSeconds(0).build(); | ||
assertThat(cleaner).isInstanceOf(MicrometerMetrics.DelayedCleaner.class); | ||
if (cleaner instanceof MicrometerMetrics.DelayedCleaner delayedCleaner) { | ||
assertThat(delayedCleaner.getCleanUpDelayInSeconds()).isEqualTo(1); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...operatorsdk/operator/monitoring/micrometer/DefaultBehaviorWithCustomImplementationIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.javaoperatorsdk.operator.monitoring.micrometer; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
|
||
public class DefaultBehaviorWithCustomImplementationIT extends DefaultBehaviorIT { | ||
|
||
@Override | ||
protected MicrometerMetrics getMetrics() { | ||
return new TestMetrics(registry); | ||
} | ||
|
||
private static class TestMetrics extends MicrometerMetrics { | ||
|
||
private TestMetrics(MeterRegistry registry) { | ||
super(registry, new CleanerBuilder(registry).build(), true); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...rator/monitoring/micrometer/DelayedMetricsCleaningOnDeleteWithCustomImplementationIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.javaoperatorsdk.operator.monitoring.micrometer; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
|
||
public class DelayedMetricsCleaningOnDeleteWithCustomImplementationIT | ||
extends DelayedMetricsCleaningOnDeleteIT { | ||
|
||
@Override | ||
protected MicrometerMetrics getMetrics() { | ||
return new TestMetrics(registry); | ||
} | ||
|
||
private static class TestMetrics extends MicrometerMetrics { | ||
|
||
private TestMetrics(MeterRegistry registry) { | ||
super( | ||
registry, | ||
new CleanerBuilder(registry) | ||
.withCleanUpDelayInSeconds(testDelay) | ||
.withCleaningThreadNumber(2) | ||
.build(), | ||
true); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...sdk/operator/monitoring/micrometer/NoPerResourceCollectionWithCustomImplementationIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.javaoperatorsdk.operator.monitoring.micrometer; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
|
||
public class NoPerResourceCollectionWithCustomImplementationIT extends NoPerResourceCollectionIT { | ||
|
||
@Override | ||
protected MicrometerMetrics getMetrics() { | ||
return new TestMetrics(registry); | ||
} | ||
|
||
private static class TestMetrics extends MicrometerMetrics { | ||
|
||
private TestMetrics(MeterRegistry registry) { | ||
super(registry, new CleanerBuilder(registry).build(), false); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be exposed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that the constructor needs a
Cleaner
implementation:So how can we re-use the existing implementations (beside the static
Cleaner.NOOP
)?I didn't want to make them all public, so I tried to hide them behind that new
CleanerBuilder
.