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 auto-configuration for Micrometer 2.0 Observation API #29666
Comments
|
I've only taken a first pass through this so my thoughts probably aren't yet complete. Things I've spotted thus far:
If we want Boot's auto-configuration to be able to find the predicates as beans and inject them into the config, I think a dedicated interface would be better. For example, it makes it easier to identify the beans the should be injected without having to worry about generics. With regards to the composite observation handlers, what should Boot do with the 3 that it creates? I am guessing that they need to be registered with Micrometer but I didn't see that mentioned above. Apologies if I missed it. Also, what should happen with the normal, non-composite handler beans? Do they also need to be registered or should it only be the composites that are registered with Micrometer?
Generally speaking, we try to avoid having properties to disable features. I wonder if the classpath could be used as a signal instead but that would depend on the structure of the code in Micrometer. With regards to the tracing bridges, do you have a feel for the dependency management implications? I imagine that we'll want to manage the version of the Brave and OTel dependencies. Are their release schedules and approach to maintenance amenable to that? |
Makes sense micrometer-metrics/micrometer#3003
I've forgotten to put it there - I've updated the description. Yes, they will need to be registered in
That should happen for sure. The thing is that people might state that e.g. tracing is lowering performance and they want to disable just that at runtime. |
|
This is blocked for the same reasons as #29753. |
|
Hey @marcingrzejszczak, got a question about the grouping logic:
Why is this necessary? Handlers added via I imagine our code for registration something like this: private void registerHandlers(List<ObservationHandler<?>> observationHandlers, ObservationRegistry observationRegistry) {
// API is forcing us to use raw types - need to create an issue for that
List<ObservationHandler> meterHandlers = new ArrayList<>();
List<ObservationHandler> tracingHandlers = new ArrayList<>();
for (ObservationHandler<?> observationHandler : observationHandlers) {
if (observationHandler instanceof MeterObservationHandler) {
meterHandlers.add(observationHandler);
} else if (observationHandler instanceof TracingObservationHandler) {
tracingHandlers.add(observationHandler);
} else {
observationRegistry.observationConfig().observationHandler(observationHandler);
}
}
if (!meterHandlers.isEmpty()) {
observationRegistry.observationConfig().observationHandler(new FirstMatchingCompositeObservationHandler(meterHandlers));
}
if (!tracingHandlers.isEmpty()) {
observationRegistry.observationConfig().observationHandler(new FirstMatchingCompositeObservationHandler(tracingHandlers));
}
}Does that work or am I'm missing something? |
|
I edited your ticket and moved the changes for Micrometer Tracing in a separate issue, #30156 |
|
Yes, that's OK (I've forgotten to update the ticket with that suggestion). |
|
Thanks for confirmation. I opened an issue regarding the use of raw types (micrometer-metrics/micrometer#3064) |
- Enables timer creation for observations by calling withTimerObservationHandler on the MeterRegistry - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandler: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
|
I see one problem actually. Tracing might not be in the classpath. That means that if it's not then accessing the Tracing handler will lead to class not found exception |
|
Yes, we will handle that with some |
- Enables timer creation for observations by calling withTimerObservationHandler on the MeterRegistry - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandler: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
|
Hey @marcingrzejszczak, regarding the option to disable metrics and just leave tracing: Ideally, Micrometer's modules would be structured such that we can figure this out just from what's on the classpath. We don't really like having configuration options if we can avoid it. So if a user wants tracing, they include |
|
For further discussions on the implementation, let's please use #30186 - this makes it easier to have them in one place and I can mark them as resolved. Thanks! |
|
If I add |
|
We'll delay the merge until the 3.0.0-M2 release is done, as this depends on micrometer snapshots. |
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
|
3.0.0-M2 is released, no longer blocking the merge. |
|
Build for the PR is currently broken, as Spring Boot uses Micrometer |
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
|
Spring Batch now builds against micrometer |
|
We need to wait until all the projects in the release train build against micrometer |
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
- Adds a ObservationRegistry bean - Add support for ObservationRegistryCustomizers - Enables timer creation for observations if micrometer-core is on the classpath - Registers ObservationPredicate, GlobalTagsProvider and ObservationHandler on the MeterRegistry - Applies grouping to the ObservationHandlers: MeterObservationHandler are added to a FirstMatchingCompositeObservationHandler - If micrometer-tracing is on the classpath, the TracingObservationHandler are added to a FirstMatchingCompositeObservationHandler See spring-projectsgh-29666
Micrometer 2.0.0 changes
Micrometer 2.0.0 comes with the following changes
Observation API
The most notable change is adding the
ObservationRegistryinterface.MeterRegistryimplements it so there wouldn't be any change there. The thing that does change is thatMeterRegistrynow has aobservationConfigconfiguration that allows to plug inObservationHandlers.Required by Boot AutoConfiguration
To create an
Observationone has to call factory methods onObservation(startorcreateNotStarted). TheMeterRegistry#ObservationConfigcan have a list ofObservationPredicateinjected to define whether for given Observation name and metadata an Observation should be created or a NoOp observation should be returned. Example use case isAutoTimerin Spring Boot. NowAutoTimeris an inbuilt feature of the Observation API.ObservationHandlerAn
ObservationHandlerallows plugging in into the lifecycle of an Observation. That means that we can react to events such as observation was started, stopped, there was an error etc.Micrometer comes with an interface
MeterObservationHandlerwhose default implementation isTimerObservationHandler. That in turn will create aTimerwhen an Observation was started and will stop it when the Observation was finished.MeterRegistrycomes with a methodwithTimerObservationHandlerthat will by default create this handler. Theoretically there might be case that someone adds Micrometer but doesn't want to create aTimerwhen an Observation is created.Micrometer Tracing comes with an interface
TracingObservationHandlerthat contains additional logic for tracing related handlers.Micrometer comes with 2 additional interfaces that group
ObservationHandlers. First isObservationHandler.FirstMatchingCompositeObservationHandler. It will groupObservationHandlers and pick the first one whosesupportsContextmethod returnstrue.Second is
ObservationHandler.AllMatchingCompositeObservationHandler. It will groupObservationHandlers and pick all whosesupportsContextmethod returnstrue.After having grouped the handlers they have to be injected to the
ObservationRegistryvia theObservationRegistry#observationConfig()#observationHandlermethod.Required by Boot AutoConfiguration
The following rules of handler groupings should take place:
MeterObservationHandlerimplementations should be automatically grouped in aObservationHandler.FirstMatchingCompositeObservationHandler.TracingObservationHandlerimplementations should be automatically grouped inObservationHandler.FirstMatchingCompositeObservationHandler.ObservationHandlerimplementations should be grouped inObservationHandler.AllMatchingCompositeObservationHandler(without duplicates)Example:
MeterObservationHandlerbean calledMetercoming from the frameworkTracingObservationHandlerbean calledTracingcoming from the frameworkObservationHandlerbean calledHandlercoming from the frameworkFirstMatchingCompositeObservationHandlerbean calledFirstcoming from the frameworkAllMatchingCompositeObservationHandlerbean calledAllcoming from the frameworkFirstMatchingCompositeObservationHandlerbean calledFirst from the usercoming from the userAllMatchingCompositeObservationHandlerbean calledAll from the usercoming from the userMeterObservationHandlerbean calledMeter from the usercoming from the userTracingObservationHandlerbean calledTracing from the usercoming from the userObservationHandlerbean calledHandler from the usercoming from the userWe should have the following setup of beans by Boot
FirstMatchingCompositeObservationHandlercreated by Boot that groups all meter related handlersMeterObservationHandlercalledMeterMeterObservationHandlercaledMeter from the user(order can vary depending onOrdered)FirstMatchingCompositeObservationHandlercreated by Boot that groups all tracing related handlersTracingObservationHandlercalledTracingTracingObservationHandlercaledTracing from the user(order can vary depending onOrdered)ObservationHandlerbean calledHandler(order can vary depending onOrdered)ObservationHandlerbean calledHandler from the user(order can vary depending onOrdered)FirstMatchingCompositeObservationHandlerbean calledFirst(order can vary depending onOrdered)FirstMatchingCompositeObservationHandlerbean calledFirst from the user(order can vary depending onOrdered)AllMatchingCompositeObservationHandlerbean calledAll(order can vary depending onOrdered)AllMatchingCompositeObservationHandlerbean calledAll from the user(order can vary depending onOrdered)ObservationRegistry.observationConfig().observationHandler()will be called to register the beans presented above.Following conditionals have to be applicable
FirstMatchingCompositeObservationHandlercreated by Boot that groups all meter related handlerssupportsContextshould returnfalsewhen a property to disable metrics is turned on (Micrometer on the classpath / a property for metrics enabling is explicitly disabled) - we can toggle this on and off at runtimeFirstMatchingCompositeObservationHandlercreated by Boot that groups all tracing related handlerssupportsContextshould returnfalsewhen a property to disable tracing is turned on (Micrometer & Micrometer Tracing on the classpath / a property for tracing enabling is explicitly disabled) - we can toggle this on and off at runtimeGlobalTagsProvider
A user can provide a
GlobalTagsProviderthat can be applied to all observations. We would need Boot to autowire a list ofGlobalTagsProviderand put them on theObservationRegistryvia theObservationRegistry.tagsProvider(...)method.The text was updated successfully, but these errors were encountered: