Skip to content
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

Spring Boot Client worked on Spring Boot 2.0.0.M3 but fails on 2.0.0.M4 #299

Closed
nickstolwijk opened this issue Oct 6, 2017 · 19 comments
Closed

Comments

@nickstolwijk
Copy link

I just tried to upgrade my Spring Boot from 2.0.0.M3 to M4, but the Prometheus Client failed with a ClassNotFoundException. It worked fine on M3. Was that by coincidence or is it tested?

Stacktrace:
nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class io.prometheus.client.spring.boot.PrometheusEndpointConfiguration
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:620)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:300)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:166)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:316)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:271)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:693)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:138)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
... 62 common frames omitted
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class io.prometheus.client.spring.boot.PrometheusEndpointConfiguration
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:169)
at org.springframework.context.annotation.ConfigurationClassParser.retrieveBeanMethodMetadata(ConfigurationClassParser.java:390)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:315)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245)
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:610)
... 78 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/actuate/endpoint/AbstractEndpoint
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:158)
... 82 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.actuate.endpoint.AbstractEndpoint
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 98 common frames omitted

@brian-brazil
Copy link
Contributor

brian-brazil commented Oct 6, 2017

This client does not support Spring 2.

@oneiros-de
Copy link

Any idea when it will?

@brian-brazil
Copy link
Contributor

Spring 2 has its own instrumentation thing that now supports labels so I'm not sure there's anything to be done there. We continue to recommend using client_java directly rather than any other instrumentation system.

@nickstolwijk
Copy link
Author

To clarify:

You recommend to use only the client_java instead of the spring-boot module and spring-web module?

How would you run the client_java servlet in the Spring Boot application?

@brian-brazil
Copy link
Contributor

You recommend to use only the client_java instead of the spring-boot module and spring-web module?

For instrumentation, yes.

How would you run the client_java servlet in the Spring Boot application?

Use whatever exposition works for you, probably PrometheusEndpoint in simpleclient_spring_boot here.

@nickstolwijk
Copy link
Author

That one isn't working anymore in Spring 2.0.0.M4. Do you plan on upgrading the Endpoint to Spring 2 isn't that feasable?

@brian-brazil
Copy link
Contributor

I believe Spring 2 has Prometheus exposition out of the box.

@checketts
Copy link
Contributor

checketts commented Oct 6, 2017

@nickstolwijk You merely need to remove your dependency/usage of simpleclient_spring_boot with Spring Boot 2 and the error will go away.

@brian-brazil is correct in the Spring Boot 2 now uses MicroMeter.io for metrics and autoconfigures Prometheus support if you are using the client already.

Brian, would it be acceptable to add a deprecation warning/explanation to the readme for simpleclient_spring_boot? I'm happy to send a PR.

@brian-brazil
Copy link
Contributor

Brian, would it be acceptable to add a deprecation warning/explanation to the readme for simpleclient_spring_boot? I'm happy to send a PR.

As far as I'm aware Spring 2.0 isn't officially released yet, so I'd hold off on a deprecation warning. A note that it won't work with 2.0 would make sense though.

@britter
Copy link

britter commented Jan 15, 2018

@checketts can you please elaborate on how you got this working with Spring Boot 2.0.0? I'm using @EnablePrometheusEndpoint and @EnableSpringBootMetricsCollector from simple_spring_boot. If I remove it, my code does not compile anymore.

@checketts
Copy link
Contributor

@britter Remove the dependency on simple_spring_boot. The Spring Boot Prometheus instructions are found here: https://micrometer.io/docs/ref/spring/2.0#_configuring

Essentially Spring is now using Micrometer to handle the Prometheus configuration. Include the Prometheus java simple-client on your classpath and enable the actuator endpoint config: endpoints.default.web.enabled: true

@britter
Copy link

britter commented Jan 19, 2018

@checketts thanks a lot!

@sbilello
Copy link

Could somebody show their pom.xml working with spring boot 2?

@moshebs
Copy link

moshebs commented Jul 18, 2018

+1 on @sbilello's request

@nickstolwijk
Copy link
Author

nickstolwijk commented Jul 18, 2018 via email

@moshebs
Copy link

moshebs commented Jul 18, 2018

Thanks a lot, @nickstolwijk.

Just to complete the discussion, this makes Prometheus metrics to be exposed at http://whatever:8081/actuator/prometheus

@nickstolwijk
Copy link
Author

nickstolwijk commented Jul 18, 2018 via email

@arun-gupta
Copy link

In case anybody is still looking, here is a working application: https://github.com/arun-gupta/spring-boot-prometheus

@pvm30
Copy link

pvm30 commented Jun 1, 2020

In case anybody is still looking, here is a working application: https://github.com/arun-gupta/spring-boot-prometheus

It's not working man. The metrics you are creating in the controller don't get exposed. Where is "requests_total" in the output of curl http://$ENDPOINT/actuator/prometheus ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants