Commit 23cde300 by Dave Syer

Align metrics with Spring Boot 1.3

Should be no change for users of Boot 1.2 right now, but with this patch it is possible to use 1.3 with the new conventions for metrics (e.g. in particular exporting by declaring beans of type MetricWriter)
parent 899a5779
......@@ -17,6 +17,8 @@
package org.springframework.cloud.netflix.eureka;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
......@@ -26,6 +28,7 @@ import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.actuate.metrics.reader.CompositeMetricReader;
import org.springframework.boot.actuate.metrics.reader.MetricReader;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
......@@ -220,11 +223,15 @@ public class EurekaDiscoveryClientConfiguration implements SmartLifecycle, Order
@ConditionalOnClass(Endpoint.class)
@ConditionalOnBean(MetricReader.class)
protected static class EurekaHealthIndicatorConfiguration {
@Autowired
private List<MetricReader> metricReaders = Collections.emptyList();
@Bean
@ConditionalOnMissingBean
public EurekaHealthIndicator eurekaHealthIndicator(
com.netflix.discovery.DiscoveryClient eurekaDiscoveryClient,
MetricReader metrics, EurekaInstanceConfig config) {
com.netflix.discovery.DiscoveryClient eurekaDiscoveryClient, EurekaInstanceConfig config) {
CompositeMetricReader metrics = new CompositeMetricReader(metricReaders.toArray(new MetricReader[0]));
return new EurekaHealthIndicator(eurekaDiscoveryClient, metrics, config);
}
}
......
......@@ -18,7 +18,10 @@ package org.springframework.cloud.netflix.servo;
import org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.MetricRepositoryAutoConfiguration;
import org.springframework.boot.actuate.metrics.GaugeService;
import org.springframework.boot.actuate.metrics.Metric;
import org.springframework.boot.actuate.metrics.reader.MetricReader;
import org.springframework.boot.actuate.metrics.writer.Delta;
import org.springframework.boot.actuate.metrics.writer.MetricWriter;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
......@@ -38,7 +41,7 @@ import com.netflix.servo.monitor.Monitors;
*/
@Configuration
@ConditionalOnClass({ Monitors.class, MetricReader.class })
@ConditionalOnBean(MetricReader.class)
@ConditionalOnBean(GaugeService.class)
@AutoConfigureBefore(EndpointAutoConfiguration.class)
@AutoConfigureAfter({ MetricRepositoryAutoConfiguration.class })
public class ServoMetricsAutoConfiguration {
......@@ -51,9 +54,34 @@ public class ServoMetricsAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public ServoMetricCollector servoMetricCollector(MetricWriter metrics,
public ServoMetricCollector servoMetricCollector(GaugeService gauges,
ServoMetricNaming naming) {
return new ServoMetricCollector(metrics, naming);
return new ServoMetricCollector(new ActuatorMetricWriter(gauges), naming);
}
// TODO: refactor this when Spring Boot 1.3 is mandatory
private static class ActuatorMetricWriter implements MetricWriter {
private GaugeService gauges;
public ActuatorMetricWriter(GaugeService gauges) {
this.gauges = gauges;
}
@Override
public void increment(Delta<?> delta) {
}
@Override
public void set(Metric<?> value) {
gauges.submit(value.getName(), value.getValue().doubleValue());
}
@Override
public void reset(String metricName) {
gauges.submit(metricName, 0.);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment