Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@Donnerbart
Copy link
Contributor

Partiallyfixes#2884

As mentioned in the issue:

I think implementing a custom metrics interface, or extending the current implementation with micrometer, should do the job

The latter is not possible due to the private constructor and private Cleaner implementations. This is an attempt to make theMicrometerMetrics class extendable without exposing allCleaner implementations.

CopilotAI review requested due to automatic review settingsAugust 26, 2025 12:34
@DonnerbartDonnerbartforce-pushed theimprovement/2884-make-micrometermetrics-extendable branch frome03b214 toae1d074CompareAugust 26, 2025 12:34
Copy link

CopilotAI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Pull Request Overview

This PR makes theMicrometerMetrics class extendable by exposing previously private constructor and cleaner implementations. It introduces a builder pattern for cleaners and allows custom implementations to extend the base functionality.

  • Exposes theMicrometerMetrics constructor as protected instead of private
  • Introduces publicCleanerBuilder andCleanerType enum for configurable cleaner creation
  • Refactors existing builder classes to use the newCleanerBuilder internally

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
MicrometerMetrics.javaMain implementation changes - exposes constructor, adds CleanerBuilder and CleanerType enum, refactors existing builders
CleanerBuilderTest.javaNew test file for the CleanerBuilder functionality
*WithCustomImplementationIT.javaNew test files demonstrating custom extension capability
AbstractMicrometerMetricsTestFixture.javaChanged TestSimpleMeterRegistry visibility to protected
DelayedMetricsCleaningOnDeleteIT.javaChanged testDelay field visibility to protected
DefaultBehaviorIT.java, NoPerResourceCollectionIT.javaAdded blank lines for formatting

Tip: Customize your code reviews with copilot-instructions.md.Create the file orlearn how to get started.

@DonnerbartDonnerbartforce-pushed theimprovement/2884-make-micrometermetrics-extendable branch 3 times, most recently from221faa7 to6dbd417CompareAugust 26, 2025 12:44
}
}

publicstaticclassCleanerBuilder {
Copy link
Collaborator

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?

Copy link
ContributorAuthor

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 aCleaner implementation:

protectedMicrometerMetrics(MeterRegistryregistry,Cleanercleaner,booleancollectingPerResourceMetrics) {

So how can we re-use the existing implementations (beside the staticCleaner.NOOP)?

I didn't want to make them all public, so I tried to hide them behind that newCleanerBuilder.

* @param cleanerType the type of cleaner to use, defaults to {@link CleanerType#NOOP} if not
* specified
*/
publicCleanerBuilderwithCleanerType(CleanerTypecleanerType) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I would rather not expose the type if possible but rather switch the type internally based on whether the user sets the number of cleaning threads or the delay, which would switch the implementation rather than throwing an exception if the type is not amenable to set these values.

Copy link
ContributorAuthor

@DonnerbartDonnerbartAug 27, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

That might actually work, yes! With that we might not need the types at all. Thebuild() method could just check if a delay parameter is set, otherwise use Cleaner.NOOP. TheDefaultCleaner is actually not directly used and exposed right now at all, so no need to change that.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I've updated the PR to get rid of the CleanerType and derive the type dynamically from the set builder parameters.

@Donnerbart
Copy link
ContributorAuthor

My main motivation to extend theMicrometerMetrics class is to avoid using a delegate pattern. This is how we've implemented this right now:

publicclassCustomResourceMetricsimplementsMetrics {privatefinal@NotNullMetricsdelegate;@OverridepublicvoidcontrollerRegistered(final@NotNullController<?extendsHasMetadata>controller) {delegate.controllerRegistered(controller);    ...  }@OverridepublicvoidreconcileCustomResource(final@NotNullHasMetadataresource,final@NotNullRetryInforetryInfo,final@NotNullMap<String,Object>metadata) {delegate.reconcileCustomResource(resource,retryInfo,metadata);  }}

This works fine, but we need to implement all methods ofMetrics to preserve the JOSDK provided metrics. And if there would ever be a new default method inMetrics that is implemented inMicrometerMetrics, it would silently break something.

An alternative approach would be to allow multipleMetrics implementations. Then we could just configure theMicrometerMetrics as they are and our custom metrics together. But this might actually break public APIs, especially the getter signatures:

publicclassConfigurationServiceOverrider {privateList<Metrics>metrics;publicConfigurationServiceOverriderwithMetrics(Metricsmetrics) {returnwithMetrics(List.of(metrics));  }publicConfigurationServiceOverriderwithMetrics(List<Metrics>metrics) {this.metrics =metrics;returnthis;  }publicConfigurationServicebuild() {returnnewBaseConfigurationService(original.getVersion(),cloner,client) {@OverridepublicList<Metrics>getMetrics() {returnmetrics !=null ?metrics :original.getMetrics();      }   }}
publicinterfaceConfigurationService {defaultList<Metrics>getMetrics() {returnList.of(Metrics.NOOP);  }}

@metacosm
Copy link
Collaborator

metacosm commentedAug 27, 2025
edited
Loading

An alternative approach would be to allow multipleMetrics implementations. Then we could just configure theMicrometerMetrics as they are and our custom metrics together. But this might actually break public APIs, especially the getter signatures:

publicclassConfigurationServiceOverrider {privateList<Metrics>metrics;publicConfigurationServiceOverriderwithMetrics(Metricsmetrics) {returnwithMetrics(List.of(metrics));  }publicConfigurationServiceOverriderwithMetrics(List<Metrics>metrics) {this.metrics =metrics;returnthis;  }publicConfigurationServicebuild() {returnnewBaseConfigurationService(original.getVersion(),cloner,client) {@OverridepublicList<Metrics>getMetrics() {returnmetrics !=null ?metrics :original.getMetrics();      }   }}
publicinterfaceConfigurationService {defaultList<Metrics>getMetrics() {returnList.of(Metrics.NOOP);  }}

Alternatively, one could implement an aggregateMetrics implementation that would allow to register multipleMetrics implementations and would then dispatch to all registered implementations for each method call. This would be similar to the delegate pattern I guess but a little bit more flexible.

For that matter, such an aggregate implementation could even be provided by JOSDK.

@DonnerbartDonnerbartforce-pushed theimprovement/2884-make-micrometermetrics-extendable branch from6dbd417 tod9223b4CompareAugust 27, 2025 15:32
Signed-off-by: David Sondermann <david.sondermann@hivemq.com>
@DonnerbartDonnerbartforce-pushed theimprovement/2884-make-micrometermetrics-extendable branch fromd9223b4 to8211d3fCompareAugust 27, 2025 15:35
@Donnerbart
Copy link
ContributorAuthor

Alternatively, one could implement an aggregateMetrics implementation that would allow to register multipleMetrics implementations and would then dispatch to all registered implementations for each method call. This would be similar to the delegate pattern I guess but a little bit more flexible.

I think that might actually be the smartest approach with the least impact to the existing classes and APIs! I'm happy to rewrite this PR or create an alternative one with that approach.

@metacosm
Copy link
Collaborator

Alternatively, one could implement an aggregateMetrics implementation that would allow to register multipleMetrics implementations and would then dispatch to all registered implementations for each method call. This would be similar to the delegate pattern I guess but a little bit more flexible.

I think that might actually be the smartest approach with the least impact to the existing classes and APIs! I'm happy to rewrite this PR or create an alternative one with that approach.

Whatever you think is more appropriate but I do think that this approach would be better, indeed. What do you think@csviri,@xstefank?

xstefank reacted with thumbs up emoji

@DonnerbartDonnerbart deleted the improvement/2884-make-micrometermetrics-extendable branchAugust 28, 2025 09:05
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

@metacosmmetacosmmetacosm requested changes

@csviricsviriAwaiting requested review from csviri

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Custom bootstrap and CR lifecycle management

2 participants

@Donnerbart@metacosm

[8]ページ先頭

©2009-2025 Movatter.jp