stagemonitor / stagemonitor

an open source solution to application performance monitoring for java server applications
www.stagemonitor.org
Apache License 2.0
1.71k stars 290 forks source link

Startup NullPointerException registry == null #479

Open cdalexndr opened 4 years ago

cdalexndr commented 4 years ago

Stagemonitor 0.89.1 Spring Boot 2.3.0.RELEASE Gradle 6.4.1

2020-05-31 15:50:51.413  INFO 348 --- [restartedMain] o.s.tracing.soap.SoapHandlerTransformer  : Adding SOAPHandlers [org.stagemonitor.tracing.soap.TracingServerSOAPHandler@2629f378, org.stagemonitor.tracing.soap.TracingClientSOAPHandler@b1133b]
2020-05-31 15:50:53.337  INFO 348 --- [restartedMain] o.s.j.ConnectionMonitoringTransformer    : TRANSFORM DataSource com.zaxxer.hikari.HikariDataSource (DefaultConnectionMonitoringTransformer)
2020-05-31 15:51:00.961  INFO 348 --- [restartedMain] org.stagemonitor.core.Stagemonitor       : Measurement Session is initialized: [application=myapp] [instance=dev] [host=my-pc]
2020-05-31 15:51:01.003  INFO 348 --- [restartedMain] org.stagemonitor.core.CorePlugin         : Not sending metrics to InfluxDB (url=null, interval=60s)
2020-05-31 15:53:18.473  WARN 348 --- [restartedMain] org.stagemonitor.core.Stagemonitor       : Error while initializing plugin CorePlugin (this exception is ignored)

java.lang.NullPointerException: registry == null
    at com.codahale.metrics.ScheduledReporter.<init>(ScheduledReporter.java:135) ~[metrics-core-4.1.7.jar:4.1.7]
    at com.codahale.metrics.ScheduledReporter.<init>(ScheduledReporter.java:122) ~[metrics-core-4.1.7.jar:4.1.7]
    at com.codahale.metrics.ScheduledReporter.<init>(ScheduledReporter.java:102) ~[metrics-core-4.1.7.jar:4.1.7]
    at org.stagemonitor.core.metrics.metrics2.ScheduledMetrics2Reporter.<init>(ScheduledMetrics2Reporter.java:36) ~[stagemonitor-core-0.89.1.jar:0.89.1]
    at org.stagemonitor.core.metrics.SortedTableLogReporter.<init>(SortedTableLogReporter.java:89) ~[stagemonitor-core-0.89.1.jar:0.89.1]
    at org.stagemonitor.core.metrics.SortedTableLogReporter.<init>(SortedTableLogReporter.java:29) ~[stagemonitor-core-0.89.1.jar:0.89.1]
    at org.stagemonitor.core.metrics.SortedTableLogReporter$Builder.build(SortedTableLogReporter.java:84) ~[stagemonitor-core-0.89.1.jar:0.89.1]
    at org.stagemonitor.core.CorePlugin.reportToConsole(CorePlugin.java:560) ~[stagemonitor-core-0.89.1.jar:0.89.1]
    at org.stagemonitor.core.CorePlugin.registerReporters(CorePlugin.java:509) ~[stagemonitor-core-0.89.1.jar:0.89.1]
    at org.stagemonitor.core.CorePlugin.initializePlugin(CorePlugin.java:489) ~[stagemonitor-core-0.89.1.jar:0.89.1]
    at org.stagemonitor.core.Stagemonitor.initializePlugin(Stagemonitor.java:184) ~[stagemonitor-core-0.89.1.jar:0.89.1]
    at org.stagemonitor.core.Stagemonitor.initializePluginsInOrder(Stagemonitor.java:154) ~[stagemonitor-core-0.89.1.jar:0.89.1]
    at org.stagemonitor.core.Stagemonitor.initializePlugins(Stagemonitor.java:140) ~[stagemonitor-core-0.89.1.jar:0.89.1]
    at org.stagemonitor.core.Stagemonitor.start(Stagemonitor.java:101) ~[stagemonitor-core-0.89.1.jar:0.89.1]
    at org.stagemonitor.core.Stagemonitor.doStartMonitoring(Stagemonitor.java:89) ~[stagemonitor-core-0.89.1.jar:0.89.1]
    at org.stagemonitor.core.Stagemonitor.startMonitoring(Stagemonitor.java:79) ~[stagemonitor-core-0.89.1.jar:0.89.1]
    at org.stagemonitor.core.Stagemonitor.reset(Stagemonitor.java:316) ~[stagemonitor-core-0.89.1.jar:0.89.1]
    at org.stagemonitor.core.Stagemonitor.reset(Stagemonitor.java:297) ~[stagemonitor-core-0.89.1.jar:0.89.1]
    at org.stagemonitor.core.Stagemonitor.init(Stagemonitor.java:58) ~[stagemonitor-core-0.89.1.jar:0.89.1]
    at org.stagemonitor.web.servlet.ServletPlugin$Initializer.onStartup(ServletPlugin.java:503) ~[stagemonitor-web-servlet-0.89.1.jar:0.89.1]
    at org.stagemonitor.web.servlet.initializer.ServletContainerInitializerUtil.registerStagemonitorServletContainerInitializers(ServletContainerInitializerUtil.java:24) ~[stagemonitor-web-servlet-0.89.1.jar:0.89.1]
    at pse.Application$StagemonitorInitializer.onStartup(Unknown Source) ~[main/:na]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:228) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:53) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5136) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140) ~[na:na]
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140) ~[na:na]
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
    at org.apache.catalina.startup.Tomcat.start(Tomcat.java:468) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:437) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:191) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:176) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:158) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
    at pse.Application.main(Unknown Source) ~[main/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.3.0.RELEASE.jar:2.3.0.RELEASE]

2020-05-31 15:53:18.475  WARN 348 --- [restartedMain] o.stagemonitor.core.StagemonitorPlugin   : The plugin CorePlugin has not been initialized yet. You should define a dependency via StagemonitorPlugin#dependsOn to InitArguments

Stagemonitor is initilialized with:

    @Component
    public class StagemonitorInitializer implements ServletContextInitializer {
        @Override
        public void onStartup( ServletContext servletContext ) throws ServletException {
            // necessary for spring boot 2.0.0 until stagemonitor supports it natively
            ServletContainerInitializerUtil.registerStagemonitorServletContainerInitializers( servletContext );
        }
    }
aldobongio commented 4 years ago

The problem is that Stagemonitor 0.89.1 depends on version 3.2.4 of Dropwizard Metrics.

Exporting dependencies of a project based on the latest Spring Boot (2.3.1.RELEASE) and Stagemonitor (0.89.1) you can see the following:

compileClasspath - Compile classpath for source set 'main'.
  ...
  +--- org.springframework.boot:spring-boot-starter-amqp -> 2.3.1.RELEASE
  |    +--- org.springframework.boot:spring-boot-dependencies:2.3.1.RELEASE
  |    |    +--- io.dropwizard.metrics:metrics-annotation:4.1.9 (c)
  |    |    +--- io.dropwizard.metrics:metrics-core:4.1.9 (c)
  |    |    +--- io.dropwizard.metrics:metrics-graphite:4.1.9 (c)
  |    |    +--- io.dropwizard.metrics:metrics-healthchecks:4.1.9 (c)
  |    |    +--- io.dropwizard.metrics:metrics-json:4.1.9 (c)
  ...
  +--- org.stagemonitor:stagemonitor-core:0.89.1
  |    +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
  |    +--- io.dropwizard.metrics:metrics-core:3.2.4 -> 4.1.9
  ...

So basically dropwizard libraries are promoted to version 4.1.9 due to the Spring Boot dependencies. Unfortunately Stagemonitor seems not compatible with version 4.x of Dropwizard: the NPE is due to this commit on Dropwizard Metrics 4.1.2.

If you downgrade the dependency to version 4.1.1 using the following Gradle snippet

configurations.all { 
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.group == 'io.dropwizard.metrics') {
            details.useVersion "4.1.1"
        }
    }
}

the NPE disappears but you experience a new error:

15:02:27.391 [main] ERROR org.stagemonitor.core.Stagemonitor - com/codahale/metrics/JmxReporter
java.lang.NoClassDefFoundError: com/codahale/metrics/JmxReporter
    at org.stagemonitor.core.CorePlugin.reportToJMX(CorePlugin.java:568)
    at org.stagemonitor.core.CorePlugin.registerReporters(CorePlugin.java:514)
    at org.stagemonitor.core.CorePlugin.initializePlugin(CorePlugin.java:489)
    at org.stagemonitor.core.Stagemonitor.initializePlugin(Stagemonitor.java:184)
    at org.stagemonitor.core.Stagemonitor.initializePluginsInOrder(Stagemonitor.java:154)
    at org.stagemonitor.core.Stagemonitor.initializePlugins(Stagemonitor.java:140)
    at org.stagemonitor.core.Stagemonitor.start(Stagemonitor.java:101)
    at org.stagemonitor.core.Stagemonitor.doStartMonitoring(Stagemonitor.java:89)
    at org.stagemonitor.core.Stagemonitor.startMonitoring(Stagemonitor.java:79)
    at org.stagemonitor.core.Stagemonitor.reset(Stagemonitor.java:316)
    at org.stagemonitor.core.Stagemonitor.reset(Stagemonitor.java:297)
    at org.stagemonitor.core.Stagemonitor.init(Stagemonitor.java:58)

This is due to a rename of the package where the Dropwizard Metrics JmxReporter class is included.

Finally you can downgrade Dropwizard Metrics to version 3.2.4

configurations.all { 
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.group == 'io.dropwizard.metrics') {
            details.useVersion "3.2.4"
        }
    }
}

In that case, the application starts. Not sure if Stagemonitor works correctly and/or how the Spring Boot application is affected by the downgrade of Dropwizard Metrics.