-
Notifications
You must be signed in to change notification settings - Fork 784
Description
Describe the bug
ActuatorSkipPatternProviderConfig fails to compile actuator endpoint values defined with reference to other properties.
If I try to override the health actuator endpoint with following value, application fails to start with spring-cloud-starter-sleuth version 2.2.3.RELEASE.
spring.cloud.discovery.health-check-url: /health${spring.application.instance_id}
Notice how it references other Spring property in order to generate unique health endpoint for each micro-service instance. This is just an example, the endpoint property value can reference other properties too.
The error stack trace is as follows.
Failed to load ApplicationContext
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sleuthSkipPatternProvider' defined in class path resource [org/springframework/cloud/sleuth/instrument/web/TraceWebAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.sleuth.instrument.web.SkipPatternProvider]: Factory method 'sleuthSkipPatternProvider' threw exception; nested exception is java.util.regex.PatternSyntaxException: Illegal repetition near index 8
/(health${spring.application.instance_id}|health${spring.application.instance_id}/.*|info|info/.*)
^
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:655)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:483)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
at
...
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.sleuth.instrument.web.SkipPatternProvider]: Factory method 'sleuthSkipPatternProvider' threw exception; nested exception is java.util.regex.PatternSyntaxException: Illegal repetition near index 8
/(health${spring.application.instance_id}|health${spring.application.instance_id}/.*|info|info/.*)
^
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650)
... 71 more
Caused by: java.util.regex.PatternSyntaxException: Illegal repetition near index 8
/(health${spring.application.instance_id}|health${spring.application.instance_id}/.*|info|info/.*)
^
at java.util.regex.Pattern.error(Pattern.java:1957)
at java.util.regex.Pattern.closure(Pattern.java:3159)
at java.util.regex.Pattern.sequence(Pattern.java:2136)
at java.util.regex.Pattern.expr(Pattern.java:1998)
at java.util.regex.Pattern.group0(Pattern.java:2907)
at java.util.regex.Pattern.sequence(Pattern.java:2053)
at java.util.regex.Pattern.expr(Pattern.java:1998)
at java.util.regex.Pattern.compile(Pattern.java:1698)
at java.util.regex.Pattern.<init>(Pattern.java:1351)
at java.util.regex.Pattern.compile(Pattern.java:1028)
at org.springframework.cloud.sleuth.instrument.web.TraceWebAutoConfiguration$ActuatorSkipPatternProviderConfig.getEndpointsPatterns(TraceWebAutoConfiguration.java:144)
at org.springframework.cloud.sleuth.instrument.web.TraceWebAutoConfiguration$ActuatorSkipPatternProviderConfig.lambda$skipPatternForActuatorEndpointsSamePort$0(TraceWebAutoConfiguration.java:193)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at org.springframework.cloud.sleuth.instrument.web.TraceWebAutoConfiguration.sleuthSkipPatternProvider(TraceWebAutoConfiguration.java:78)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 72 more
Referencing other Spring properties in actuator/management endpoints is not uncommon so, I recommend enhancing regex compile / processing to support such values too.
Sample
Override health-check-url to something else that references other Spring property and start the application.
For example,
spring.cloud.discovery.health-check-url: /health${spring.application.instance_id}
Workaround
As a workaround, I set ignoreAutoConfiguredSkipPatterns=true. Which is ok for now, but I want to skip all other actuator and management endpoints so eventually I would like to revert it (set ignoreAutoConfiguredSkipPatterns to false).