Skip to content

Statsd server gets no metric report when using spring boot metrics API and Dropwizard implementation #8254

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

Closed
ZhuzhuDing opened this issue Feb 10, 2017 · 6 comments

Comments

@ZhuzhuDing
Copy link

ZhuzhuDing commented Feb 10, 2017

I'm doing it as below:

  • Use CounterService as metrics repository api just as official reference:
    @Component
    public class ComponentUseSpringBootMetrics {

	    @Autowired
	    private CounterService counterService;

	    @Scheduled(fixedRate = 5000)
	    public void increment() {
		    counterService.increment("meter.springboot.counter");
	    }
    }
  • Import Dropwizard metrics in build.gradle
buildscript {
	ext {
		springBootVersion = '1.5.1.RELEASE'
	}
	repositories {
		mavenCentral()
	}
	dependencies {
		classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
	}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

jar {
	baseName = 'spring_boot_metrics_study'
	version = '0.0.1-SNAPSHOT'
}

sourceCompatibility = 1.8

repositories {
	mavenCentral()
}

dependencies {

	compile('org.springframework.boot:spring-boot-starter-web')
	compile('org.springframework.boot:spring-boot-starter-actuator')
	
        // remove this library then it works
	compile group: 'io.dropwizard.metrics', name: 'metrics-core', version: '3.1.2'	
	compile group: 'com.timgroup', name: 'java-statsd-client', version: '3.1.0'
	
	testCompile('org.springframework.boot:spring-boot-starter-test')
}
  • Add statsd property in application.properties
spring.metrics.export.statsd.host=localhost

The result is statsd server won't get any report when using spring boot metrics API and Dropwizard implementation.

If I remove Dropwizard metric dependency, just use default implementation then it works.

Do I miss anything or is it a bug?

@ZhuzhuDing ZhuzhuDing changed the title Statsd server gets no metrics when using spring boot metrics API and Dropwizard implementation Statsd server gets no metric report when using spring boot metrics API and Dropwizard implementation Feb 10, 2017
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 10, 2017
@ZhuzhuDing
Copy link
Author

ZhuzhuDing commented Feb 13, 2017

I think the reason is that MetricsDropwizardAutoConfiguration doesn't have any Bean defined as @ExportMetricReader, but overrides the bean definition in MetricRepositoryAutoConfiguration .
If a configuration class is added like below , then the problem gone.

@Configuration
public class MetricConfig {
	
    @Bean
    @ExportMetricReader
    public MetricReader metricReader(MetricRegistry metricRegistry) {
        return new MetricRegistryMetricReader(metricRegistry);
    }

}

@wilkinsona
Copy link
Member

When you add Dropwizard to the classpath, I believe the assumption is that you want metrics to be sent into Dropwizard. This is done automatically by DropwizardMetricServices that sends gauges and counters to a com.codahale.metrics.MetricRegistry.

What was your goal when you added the io.dropwizard.metrics:metrics-core dependency?

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Feb 14, 2017
@ZhuzhuDing
Copy link
Author

ZhuzhuDing commented Feb 14, 2017

@wilkinsona
We want to use Spring boot API and Dropwizard metric as implementation, and report to Statsd server all by auto configuration. But it doesn't work.
When an extra configuration class as above added, the problem is gone.

Through debug, I can see the CounterService instance is type of DropwizardMetricServices, but the exporter won't get a reader. Thus Statsd server won't get any report.

I guess the reason is MetricsDropwizardAutoConfiguration doesn't have any Bean defined as @ExportMetricReader, but overrides the bean definition in MetricRepositoryAutoConfiguration .
So no MetricReader is defined under this circumstance.

Is it supposed to define MetricRegistryMetricReader as MetricReader automatically ( in MetricsDropwizardAutoConfiguration) when dropwizard dependency imports , right?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 14, 2017
@OrangeDog
Copy link
Contributor

OrangeDog commented May 23, 2017

When you add Dropwizard to the classpath

It should be noted that it can also come from transitive dependencies (such as via spring-boot-starter-data-cassandra) as it's a very popular instrumentation library. It's surprising that this disables existing redis and statsd exports.

@psoares
Copy link

psoares commented May 25, 2017

I tried to exclude that transitive dependency from spring-starter-data-cassandra because my project uses it. Unfortunately the cassandra driver then complains about not having it. I solved the issue for now by excluding the MetricsDropwizardAutoConfiguration in application.yml, like this:

spring:
  autoconfigure:
    exclude:
      - org.springframework.boot.actuate.autoconfigure.MetricsDropwizardAutoConfiguration

@wilkinsona
Copy link
Member

This has been superseded by the planned move to Micrometer-based metrics (#9970)

@wilkinsona wilkinsona removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged theme: actuator labels Aug 11, 2017
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

6 participants