Add ObservationRegistry support to ConfigClientRequestTemplateFactory#3221
Add ObservationRegistry support to ConfigClientRequestTemplateFactory#3221LuccasAps wants to merge 6 commits intospring-cloud:mainfrom
Conversation
Closes spring-cloud#2972 Signed-off-by: Luccas Asaphe <167210535+LuccasAps@users.noreply.github.com>
ryanjbaxter
left a comment
There was a problem hiding this comment.
ConfigServerBootstrapper and ConfigClientRequestTemplateFactory will result in ClassNotFoundExceptions since micrometer is brought in via optional actuator dependencies. We probably want to subclass both of these classes with the observation changes and only create them when ClassUtils.isPresent("io.micrometer.observation.ObservationRegistry", null)
Signed-off-by: Luccas Asaphe <167210535+LuccasAps@users.noreply.github.com>
LuccasAps
left a comment
There was a problem hiding this comment.
Thanks for the review! I've addressed all the feedback:
- Removed the null check for observationRegistry
- Moved ObservationRestTemplateCustomizer instantiation to the constructor
- Translated test comments to English
- Used registry variable directly in the constructor instead of ObservationRegistry.NOOP
- Added integration test for withObservationRegistry
Signed-off-by: Luccas Asaphe <167210535+LuccasAps@users.noreply.github.com>
Sorry! I had already applied the individual file changes before seeing this comment.
|
|
|
||
| private ObservationRegistry observationRegistry; | ||
|
|
||
| static ObservationConfigServerBootstrapper create() { |
There was a problem hiding this comment.
Is there a reason why this is package private but the constructor is public?
There was a problem hiding this comment.
Just following the superclass pattern, happy to change if needed!
There was a problem hiding this comment.
Yes makes sense to be consistent with the visibility (in both places)
There was a problem hiding this comment.
I don't se this addressed
Signed-off-by: Luccas Asaphe <167210535+LuccasAps@users.noreply.github.com>
LuccasAps
left a comment
There was a problem hiding this comment.
Added a check for ObservationRestTemplateCustomizer as well. Thanks for catching that!
ryanjbaxter
left a comment
There was a problem hiding this comment.
I think it would be worth while adding a test that uses @ClassPathExclusions to test when micrometer and restclient are not on the classpath. You can see an example of such a test here https://github.com/spring-cloud/spring-cloud-commons/blob/3a1c2dfc5cf73fcabcf53dc0ba6c2da215454de6/spring-cloud-commons/src/test/java/org/springframework/cloud/client/discovery/ManagementServerPortUtilsTests.java#L30
|
|
||
| private ObservationRegistry observationRegistry; | ||
|
|
||
| static ObservationConfigServerBootstrapper create() { |
There was a problem hiding this comment.
I don't se this addressed
Signed-off-by: Luccas Asaphe <167210535+LuccasAps@users.noreply.github.com>
After investigating the dependency tree, I found that spring-web -> micrometer-observation -> ObservationRegistry This means For now I kept both checks and both exclusions in |
| public class ConfigServerConfigDataWithoutMicrometerTests { | ||
|
|
||
| @Test | ||
| void contextStartsWithoutMicrometer() { |
There was a problem hiding this comment.
Would be good to verify the correct beans are created
| * @author Luccas Asaphe | ||
| * | ||
| */ | ||
| @ClassPathExclusions({ "spring-boot-starter-actuator-*.jar", "spring-boot-restclient-*.jar" }) |
There was a problem hiding this comment.
Excluding actuator is not needed since it is brought in by web
Looks like there is just one check, and that is fine: |
…lasspath Signed-off-by: Luccas Asaphe <167210535+LuccasAps@users.noreply.github.com>
LuccasAps
left a comment
There was a problem hiding this comment.
Updated the test to verify that ConfigClientRequestTemplateFactory (base class) is created when spring-boot-restclient is not on the classpath, and removed the spring-boot-starter-actuator exclusion since it is not needed — only spring-boot-restclient needs to be excluded as it contains ObservationRestTemplateCustomizer.
What this PR does
Closes #2972
The
RestTemplateused inConfigServerConfigDataLoaderwas not instrumentedwith Micrometer observations, making it impossible to monitor the behavior of
the Config Server integration through metrics and traces.
Changes
ConfigClientRequestTemplateFactoryObservationRegistryas an optional fieldObservationRegistryObservationRegistry.NOOPto maintain backward compatibilityObservationRestTemplateCustomizerto the createdRestTemplateConfigServerBootstrapperwithObservationRegistry(ObservationRegistry)hook so developers can provide anObservationRegistryduring the bootstrap phaseConfigServerConfigDataLocationResolverConfigClientRequestTemplateFactoryregistration to pass theObservationRegistryfrom theBootstrapContextwhen available, falling back toObservationRegistry.NOOPUsage
Backward compatibility
No breaking changes. When no
ObservationRegistryis provided,ObservationRegistry.NOOPis used and behavior is identical to before.