-
Notifications
You must be signed in to change notification settings - Fork 0
MeterRegistry implements ObservationRegistry, static factory methods #2
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,60 +31,12 @@ public interface ObservationRegistry { | |
|
|
||
| void setCurrentObservation(@Nullable Observation current); | ||
|
|
||
| /** | ||
| * !!!!!!!!!!!!!!!!!!!! THIS IS NOT STARTED !!!!!!!!!!!!!!!!!!!! | ||
| * !!!!!!!!!!!!!!!!!!!! REMEMBER TO CALL START() OTHERWISE YOU WILL FILE ISSUES THAT STUFF IS NOT WORKING !!!!!!!!!!!!!!!!!!!! | ||
| * @param name observation name | ||
| * @return this | ||
| */ | ||
| default Observation observation(String name) { | ||
| if (config().isObservationEnabled(name, null)) { | ||
| return new SimpleObservation(name, this, new Observation.Context()); | ||
| } | ||
| return NoopObservation.INSTANCE; | ||
| } | ||
|
|
||
| /** | ||
| * !!!!!!!!!!!!!!!!!!!! THIS IS NOT STARTED !!!!!!!!!!!!!!!!!!!! | ||
| * !!!!!!!!!!!!!!!!!!!! REMEMBER TO CALL START() OTHERWISE YOU WILL FILE ISSUES THAT STUFF IS NOT WORKING !!!!!!!!!!!!!!!!!!!! | ||
| * @param name observation name | ||
| * @param context context | ||
| * @return this | ||
| */ | ||
| default Observation observation(String name, Observation.Context context) { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should not we leave these so that you can do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. I was mirroring the API after |
||
| if (config().isObservationEnabled(name, context)) { | ||
| return new SimpleObservation(name, this, context); | ||
| } | ||
| return NoopObservation.INSTANCE; | ||
| } | ||
|
|
||
| /** | ||
| * Started observation. | ||
| * | ||
| * @param name observation name | ||
| * @return this | ||
| */ | ||
| default Observation start(String name) { | ||
| return observation(name).start(); | ||
| } | ||
|
|
||
| /** | ||
| * Started observation. | ||
| * | ||
| * @param name observation name | ||
| * @param context context | ||
| * @return this | ||
| */ | ||
| default Observation start(String name, Observation.Context context) { | ||
| return observation(name, context).start(); | ||
| } | ||
|
|
||
| Config config(); | ||
| ObservationConfig observationConfig(); | ||
|
|
||
| /** | ||
| * Access to configuration options for this registry. | ||
| */ | ||
| class Config { | ||
| class ObservationConfig { | ||
|
|
||
| private List<ObservationHandler<?>> observationHandlers = new CopyOnWriteArrayList<>(); | ||
|
|
||
|
|
@@ -95,9 +47,8 @@ class Config { | |
| * | ||
| * @param handler handler to add to the current configuration | ||
| * @return This configuration instance | ||
| * @since 2.0.0 | ||
| */ | ||
| public ObservationRegistry.Config observationHandler(ObservationHandler<?> handler) { | ||
| public ObservationConfig observationHandler(ObservationHandler<?> handler) { | ||
| this.observationHandlers.add(handler); | ||
| return this; | ||
| } | ||
|
|
@@ -108,9 +59,8 @@ public ObservationRegistry.Config observationHandler(ObservationHandler<?> handl | |
| * | ||
| * @param predicate predicate | ||
| * @return This configuration instance | ||
| * @since 2.0.0 | ||
| */ | ||
| public ObservationRegistry.Config observationPredicate(BiPredicate<String, Observation.Context> predicate) { | ||
| public ObservationConfig observationPredicate(BiPredicate<String, Observation.Context> predicate) { | ||
| this.observationPredicates.add(predicate); | ||
| return this; | ||
| } | ||
|
|
||
This file was deleted.
This file was deleted.
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.
Shouldn't this return
ObservationConfigso that you can do this: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.
Ideally, yes. That was my intention, but I didn't see a practical way to do that without making it a method on
ObservationConfig, which shouldn't directly know aboutTimer. I couldn't think of a way to add that only inMeterRegistry. We should definitely think of something better than what's there now. It was temporary since it was late and I was out of ideas but just wanted to demonstrate the general intention.Uh oh!
There was an error while loading. Please reload this page.
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.
To achieve what you mentioned, it works well enough to just return
observationConfigafter the current logic, but what I meant was that ideally the method itself would be nested underMeterRegistry#observationConfig()instead of a top-level method onMeterRegistry, I think. But that doesn't feel possible. So the question is perhaps are we okay with this (awkwardly) being a top-level method on MeterRegistry that returns theObservationConfig? Another option is to put it under Config, but then that would be weird to return ObservationConfig from there.