Refactor annotations for metric export
Users can add @ExportMetric[Reader,Writer] to readers and writers that they want to participate in the default exporter. There is also still an @ActuatorMetricWriter that is used for the legacy (non-Java8) Gauge and CounterServices.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
||||
/**
|
||||
* Qualifier annotation for a metric reader that can be exported (to distinguish it from
|
||||
* others that might be installed by the user for other purposes).
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@Qualifier
|
||||
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE,
|
||||
ElementType.ANNOTATION_TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Inherited
|
||||
@Documented
|
||||
public @interface ExportMetricReader {
|
||||
|
||||
}
|
||||
@@ -26,8 +26,8 @@ import java.lang.annotation.Target;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
||||
/**
|
||||
* Qualifier annotation for a metric repository that is used by the actuator (to
|
||||
* distinguish it from others that might be installed by the user).
|
||||
* Qualifier annotation for a metric repository that is to be used to export metrics from
|
||||
* the {@link ExportMetricReader} readers.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@@ -37,6 +37,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Inherited
|
||||
@Documented
|
||||
public @interface ActuatorMetricReader {
|
||||
public @interface ExportMetricWriter {
|
||||
|
||||
}
|
||||
@@ -47,17 +47,14 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
public class MetricExportAutoConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
@ExportMetricWriter
|
||||
private Map<String, MetricWriter> writers = Collections.emptyMap();
|
||||
|
||||
@Autowired
|
||||
private MetricExportProperties metrics;
|
||||
|
||||
@Autowired(required = false)
|
||||
@ActuatorMetricWriter
|
||||
private List<MetricWriter> actuatorMetrics = Collections.emptyList();
|
||||
|
||||
@Autowired(required = false)
|
||||
@ActuatorMetricReader
|
||||
@ExportMetricReader
|
||||
private List<MetricReader> readers;
|
||||
|
||||
@Autowired(required = false)
|
||||
@@ -77,11 +74,6 @@ public class MetricExportAutoConfiguration {
|
||||
|
||||
if (reader != null) {
|
||||
writers.putAll(this.writers);
|
||||
for (String name : this.writers.keySet()) {
|
||||
if (this.actuatorMetrics.contains(writers.get(name))) {
|
||||
writers.remove(name);
|
||||
}
|
||||
}
|
||||
MetricExporters exporters = new MetricExporters(reader, writers, this.metrics);
|
||||
return exporters;
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ public class MetricRepositoryAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ActuatorMetricReader
|
||||
@ExportMetricReader
|
||||
@ConditionalOnMissingBean
|
||||
public BufferMetricReader actuatorMetricReader(CounterBuffers counters,
|
||||
GaugeBuffers gauges) {
|
||||
@@ -151,7 +151,7 @@ public class MetricRepositoryAutoConfiguration {
|
||||
static class LegacyMetricRepositoryConfiguration {
|
||||
|
||||
@Bean
|
||||
@ActuatorMetricReader
|
||||
@ExportMetricReader
|
||||
@ActuatorMetricWriter
|
||||
public InMemoryMetricRepository actuatorMetricRepository() {
|
||||
return new InMemoryMetricRepository();
|
||||
|
||||
@@ -70,7 +70,7 @@ import org.springframework.lang.UsesJava7;
|
||||
public class PublicMetricsAutoConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
@ActuatorMetricReader
|
||||
@ExportMetricReader
|
||||
private List<MetricReader> metricReaders = Collections.emptyList();
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -208,8 +208,14 @@ class Trigger {
|
||||
*/
|
||||
private Boolean sendLatest;
|
||||
|
||||
/**
|
||||
* List of patterns for metric names to include.
|
||||
*/
|
||||
private String[] includes;
|
||||
|
||||
/**
|
||||
* List of patterns for metric names to exclude. Applied after the includes.
|
||||
*/
|
||||
private String[] excludes;
|
||||
|
||||
public String[] getIncludes() {
|
||||
|
||||
@@ -116,6 +116,7 @@ public class MetricExportAutoConfigurationTests {
|
||||
public static class WriterConfig {
|
||||
|
||||
@Bean
|
||||
@ExportMetricWriter
|
||||
public MetricWriter writer() {
|
||||
return Mockito.mock(MetricWriter.class);
|
||||
}
|
||||
@@ -126,6 +127,7 @@ public class MetricExportAutoConfigurationTests {
|
||||
public static class MetricEndpointConfiguration {
|
||||
|
||||
@Bean
|
||||
@ExportMetricReader
|
||||
public MetricsEndpointMetricReader endpointReader() {
|
||||
return Mockito.mock(MetricsEndpointMetricReader.class);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user