-
Notifications
You must be signed in to change notification settings - Fork 979
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
Add "createNotStarted" method that lazily creates context #3401
Merged
marcingrzejszczak
merged 1 commit into
micrometer-metrics:main
from
ttddyy:create-not-started
Sep 12, 2022
Merged
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 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 |
---|---|---|
|
@@ -19,11 +19,13 @@ | |
import io.micrometer.common.lang.NonNull; | ||
import io.micrometer.common.lang.Nullable; | ||
import io.micrometer.observation.Observation; | ||
import io.micrometer.observation.ObservationPredicate; | ||
import io.micrometer.observation.ObservationRegistry; | ||
import io.micrometer.observation.GlobalObservationConvention; | ||
import io.micrometer.observation.ObservationConvention; | ||
|
||
import java.util.Objects; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* In order to describe your samples via e.g. enums instead of Strings you can use this | ||
|
@@ -187,6 +189,32 @@ default <T extends Observation.Context> Observation observation(@Nullable Observ | |
return observation; | ||
} | ||
|
||
/** | ||
* Creates an {@link Observation} for the given {@link ObservationConvention}. You | ||
* need to manually start it. When the {@link ObservationRegistry} is a no-op, this | ||
* method fast returns a no-op {@link Observation} and skips the creation of the | ||
* {@link Observation.Context}. This quick check avoids unnecessary | ||
* {@link Observation.Context} creations. More detailed check, such as | ||
* {@link ObservationPredicate}, is performed at the later stage after | ||
* {@link Observation.Context} creation. | ||
* @param customConvention convention that (if not {@code null}) will override any | ||
* pre-configured conventions | ||
* @param defaultConvention default convention that will be picked if there was | ||
* neither custom convention nor a pre-configured one via | ||
* {@link ObservationRegistry.ObservationConfig#observationConvention(GlobalObservationConvention[])} | ||
* @param contextSupplier observation context supplier | ||
* @param registry observation registry | ||
* @return observation | ||
*/ | ||
default <T extends Observation.Context> Observation createNotStarted( | ||
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. I think we should call these methods I think either we call all of them |
||
@Nullable ObservationConvention<T> customConvention, @NonNull ObservationConvention<T> defaultConvention, | ||
@NonNull Supplier<T> contextSupplier, @NonNull ObservationRegistry registry) { | ||
if (registry.isNoop()) { | ||
return Observation.NOOP; | ||
} | ||
return observation(customConvention, defaultConvention, contextSupplier.get(), registry); | ||
} | ||
|
||
/** | ||
* Creates and starts an {@link Observation}. | ||
* @param registry observation registry | ||
|
This file contains 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
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.
Can we also add a null check since the
registry
is@Nullable
? See:micrometer/micrometer-observation/src/main/java/io/micrometer/observation/Observation.java
Lines 102 to 105 in da7c9f3
Also, should not we do this in the
Observation
too?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.
registry
is non-null on this method, so don't need null check here.I'll add documentation that this no-op registry check is a quick check and further decision(
ObservationPredicate
) would happen after context is created.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.
I'll go to an eye doctor. :D