Fix sample and tidy up MetricWriter/GaugeWriter

The metric export configuration was still using the MetricWriter
interface where it should be using GaugeWriter
pull/4359/head
Dave Syer 9 years ago
parent 03c56b4cf1
commit db03e8ea50

@ -30,7 +30,7 @@ import org.springframework.boot.actuate.metrics.export.MetricExporters;
import org.springframework.boot.actuate.metrics.reader.CompositeMetricReader;
import org.springframework.boot.actuate.metrics.reader.MetricReader;
import org.springframework.boot.actuate.metrics.statsd.StatsdMetricWriter;
import org.springframework.boot.actuate.metrics.writer.MetricWriter;
import org.springframework.boot.actuate.metrics.writer.GaugeWriter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@ -67,7 +67,7 @@ public class MetricExportAutoConfiguration {
@Autowired(required = false)
@ExportMetricWriter
private Map<String, MetricWriter> writers = Collections.emptyMap();
private Map<String, GaugeWriter> writers = Collections.emptyMap();
@Autowired(required = false)
private Map<String, Exporter> exporters = Collections.emptyMap();
@ -75,7 +75,7 @@ public class MetricExportAutoConfiguration {
@Bean
@ConditionalOnMissingBean(name = "metricWritersMetricExporter")
public SchedulingConfigurer metricWritersMetricExporter() {
Map<String, MetricWriter> writers = new HashMap<String, MetricWriter>();
Map<String, GaugeWriter> writers = new HashMap<String, GaugeWriter>();
MetricReader reader = this.endpointReader;
if (reader == null && !CollectionUtils.isEmpty(this.readers)) {
reader = new CompositeMetricReader(

@ -21,7 +21,7 @@ import java.util.Map;
import java.util.Map.Entry;
import org.springframework.boot.actuate.metrics.reader.MetricReader;
import org.springframework.boot.actuate.metrics.writer.MetricWriter;
import org.springframework.boot.actuate.metrics.writer.GaugeWriter;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.IntervalTask;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
@ -36,7 +36,7 @@ public class MetricExporters implements SchedulingConfigurer {
private MetricReader reader;
private Map<String, MetricWriter> writers = new HashMap<String, MetricWriter>();
private Map<String, GaugeWriter> writers = new HashMap<String, GaugeWriter>();
private final MetricExportProperties properties;
@ -50,7 +50,7 @@ public class MetricExporters implements SchedulingConfigurer {
this.reader = reader;
}
public void setWriters(Map<String, MetricWriter> writers) {
public void setWriters(Map<String, GaugeWriter> writers) {
this.writers.putAll(writers);
}
@ -71,9 +71,9 @@ public class MetricExporters implements SchedulingConfigurer {
taskRegistrar.addFixedDelayTask(task);
}
}
for (Entry<String, MetricWriter> entry : this.writers.entrySet()) {
for (Entry<String, GaugeWriter> entry : this.writers.entrySet()) {
String name = entry.getKey();
MetricWriter writer = entry.getValue();
GaugeWriter writer = entry.getValue();
TriggerProperties trigger = this.properties.findTrigger(name);
if (trigger != null) {
MetricCopyExporter exporter = getExporter(writer, trigger);
@ -86,7 +86,7 @@ public class MetricExporters implements SchedulingConfigurer {
}
}
private MetricCopyExporter getExporter(MetricWriter writer,
private MetricCopyExporter getExporter(GaugeWriter writer,
TriggerProperties trigger) {
MetricCopyExporter exporter = new MetricCopyExporter(this.reader, writer);
exporter.setIncludes(trigger.getIncludes());

@ -24,6 +24,7 @@ import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.boot.actuate.metrics.reader.MetricReader;
import org.springframework.boot.actuate.metrics.writer.GaugeWriter;
import org.springframework.boot.actuate.metrics.writer.MetricWriter;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
@ -41,7 +42,7 @@ public class MetricExportersTests {
private MetricExportProperties export = new MetricExportProperties();
private Map<String, MetricWriter> writers = new LinkedHashMap<String, MetricWriter>();
private Map<String, GaugeWriter> writers = new LinkedHashMap<String, GaugeWriter>();
private MetricReader reader = Mockito.mock(MetricReader.class);

@ -21,7 +21,7 @@ import org.springframework.boot.actuate.autoconfigure.ExportMetricWriter;
import org.springframework.boot.actuate.metrics.opentsdb.DefaultOpenTsdbNamingStrategy;
import org.springframework.boot.actuate.metrics.opentsdb.OpenTsdbMetricWriter;
import org.springframework.boot.actuate.metrics.opentsdb.OpenTsdbNamingStrategy;
import org.springframework.boot.actuate.metrics.writer.MetricWriter;
import org.springframework.boot.actuate.metrics.writer.GaugeWriter;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
@ -32,7 +32,7 @@ public class SampleOpenTsdbExportApplication {
@Bean
@ConfigurationProperties("metrics.export")
@ExportMetricWriter
public MetricWriter openTsdbMetricWriter() {
public GaugeWriter openTsdbMetricWriter() {
OpenTsdbMetricWriter writer = new OpenTsdbMetricWriter();
writer.setNamingStrategy(namingStrategy());
return writer;

Loading…
Cancel
Save