Skip to content

Commit 4d12a29

Browse files
committed
Move metrics properties
- Moved from 'management.metrics.export.<product>' to 'management.<product>.metrics.export' - The default enabled property moved from 'management.metrics.export.defaults.enabled' to 'management.defaults.metrics.export.enabled' See spring-projectsgh-30381
1 parent e431842 commit 4d12a29

File tree

64 files changed

+1929
-439
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1929
-439
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ConditionalOnEnabledMetricsExport.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,9 +26,9 @@
2626

2727
/**
2828
* {@link Conditional @Conditional} that checks whether or not a metrics exporter is
29-
* enabled. If the {@code management.metrics.export.<name>.enabled} property is configured
29+
* enabled. If the {@code management.<name>.metrics.export.enabled} property is configured
3030
* then its value is used to determine if it matches. Otherwise, matches if the value of
31-
* the {@code management.metrics.export.defaults.enabled} property is {@code true} or if
31+
* the {@code management.defaults.metrics.export.enabled} property is {@code true} or if
3232
* it is not configured.
3333
*
3434
* @author Chris Bono

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/OnMetricsExportEnabledCondition.java

+48-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,18 +16,61 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.metrics.export;
1818

19-
import org.springframework.boot.actuate.autoconfigure.OnEndpointElementCondition;
19+
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
20+
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
21+
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
2022
import org.springframework.context.annotation.Condition;
23+
import org.springframework.context.annotation.ConditionContext;
24+
import org.springframework.core.annotation.AnnotationAttributes;
25+
import org.springframework.core.env.Environment;
26+
import org.springframework.core.type.AnnotatedTypeMetadata;
2127

2228
/**
2329
* {@link Condition} that checks if a metrics exporter is enabled.
2430
*
2531
* @author Chris Bono
32+
* @author Moritz Halbritter
2633
*/
27-
class OnMetricsExportEnabledCondition extends OnEndpointElementCondition {
34+
class OnMetricsExportEnabledCondition extends SpringBootCondition {
2835

29-
protected OnMetricsExportEnabledCondition() {
30-
super("management.metrics.export.", ConditionalOnEnabledMetricsExport.class);
36+
private static final String PROPERTY_TEMPLATE = "management.%s.metrics.export.enabled";
37+
38+
private static final String DEFAULT_PROPERTY_NAME = "management.defaults.metrics.export.enabled";
39+
40+
@Override
41+
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
42+
AnnotationAttributes annotationAttributes = AnnotationAttributes
43+
.fromMap(metadata.getAnnotationAttributes(ConditionalOnEnabledMetricsExport.class.getName()));
44+
String endpointName = annotationAttributes.getString("value");
45+
ConditionOutcome outcome = getProductOutcome(context, endpointName);
46+
if (outcome != null) {
47+
return outcome;
48+
}
49+
return getDefaultOutcome(context);
50+
}
51+
52+
private ConditionOutcome getProductOutcome(ConditionContext context, String productName) {
53+
Environment environment = context.getEnvironment();
54+
String enabledProperty = PROPERTY_TEMPLATE.formatted(productName);
55+
if (environment.containsProperty(enabledProperty)) {
56+
boolean match = environment.getProperty(enabledProperty, Boolean.class, true);
57+
return new ConditionOutcome(match, ConditionMessage.forCondition(ConditionalOnEnabledMetricsExport.class)
58+
.because(enabledProperty + " is " + match));
59+
}
60+
return null;
61+
}
62+
63+
/**
64+
* Return the default outcome that should be used if property is not set. By default
65+
* this method will use the {@link #DEFAULT_PROPERTY_NAME} property, matching if it is
66+
* {@code true} or if it is not configured.
67+
* @param context the condition context
68+
* @return the default outcome
69+
*/
70+
private ConditionOutcome getDefaultOutcome(ConditionContext context) {
71+
boolean match = Boolean.parseBoolean(context.getEnvironment().getProperty(DEFAULT_PROPERTY_NAME, "true"));
72+
return new ConditionOutcome(match, ConditionMessage.forCondition(ConditionalOnEnabledMetricsExport.class)
73+
.because(DEFAULT_PROPERTY_NAME + " is considered " + match));
3174
}
3275

3376
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsProperties.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@
2828
* @author Stephane Nicoll
2929
* @since 2.1.0
3030
*/
31-
@ConfigurationProperties(prefix = "management.metrics.export.appoptics")
31+
@ConfigurationProperties(prefix = "management.appoptics.metrics.export")
3232
public class AppOpticsProperties extends StepRegistryProperties {
3333

3434
/**

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ class AppOpticsPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapt
3434

3535
@Override
3636
public String prefix() {
37-
return "management.metrics.export.appoptics";
37+
return "management.appoptics.metrics.export";
3838
}
3939

4040
@Override

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasProperties.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@
2828
* @author Stephane Nicoll
2929
* @since 2.0.0
3030
*/
31-
@ConfigurationProperties(prefix = "management.metrics.export.atlas")
31+
@ConfigurationProperties(prefix = "management.atlas.metrics.export")
3232
public class AtlasProperties {
3333

3434
/**

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogProperties.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@
2727
* @author Stephane Nicoll
2828
* @since 2.0.0
2929
*/
30-
@ConfigurationProperties(prefix = "management.metrics.export.datadog")
30+
@ConfigurationProperties(prefix = "management.datadog.metrics.export")
3131
public class DatadogProperties extends StepRegistryProperties {
3232

3333
/**

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,7 +35,7 @@ class DatadogPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter
3535

3636
@Override
3737
public String prefix() {
38-
return "management.metrics.export.datadog";
38+
return "management.datadog.metrics.export";
3939
}
4040

4141
@Override

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatraceProperties.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@
3030
* @author Georg Pirklbauer
3131
* @since 2.1.0
3232
*/
33-
@ConfigurationProperties(prefix = "management.metrics.export.dynatrace")
33+
@ConfigurationProperties(prefix = "management.dynatrace.metrics.export")
3434
public class DynatraceProperties extends StepRegistryProperties {
3535

3636
private final V1 v1 = new V1();
@@ -57,7 +57,7 @@ public void setApiToken(String apiToken) {
5757
}
5858

5959
@Deprecated
60-
@DeprecatedConfigurationProperty(replacement = "management.metrics.export.dynatrace.v1.device-id")
60+
@DeprecatedConfigurationProperty(replacement = "management.dynatrace.metrics.export.v1.device-id")
6161
public String getDeviceId() {
6262
return this.v1.getDeviceId();
6363
}
@@ -68,7 +68,7 @@ public void setDeviceId(String deviceId) {
6868
}
6969

7070
@Deprecated
71-
@DeprecatedConfigurationProperty(replacement = "management.metrics.export.dynatrace.v1.technology-type")
71+
@DeprecatedConfigurationProperty(replacement = "management.dynatrace.metrics.export.v1.technology-type")
7272
public String getTechnologyType() {
7373
return this.v1.getTechnologyType();
7474
}
@@ -87,7 +87,7 @@ public void setUri(String uri) {
8787
}
8888

8989
@Deprecated
90-
@DeprecatedConfigurationProperty(replacement = "management.metrics.export.dynatrace.v1.group")
90+
@DeprecatedConfigurationProperty(replacement = "management.dynatrace.metrics.export.v1.group")
9191
public String getGroup() {
9292
return this.v1.getGroup();
9393
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,7 +41,7 @@ class DynatracePropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapt
4141

4242
@Override
4343
public String prefix() {
44-
return "management.metrics.export.dynatrace";
44+
return "management.dynatrace.metrics.export";
4545
}
4646

4747
@Override

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticProperties.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@
2626
* @author Andy Wilkinson
2727
* @since 2.1.0
2828
*/
29-
@ConfigurationProperties(prefix = "management.metrics.export.elastic")
29+
@ConfigurationProperties(prefix = "management.elastic.metrics.export")
3030
public class ElasticProperties extends StepRegistryProperties {
3131

3232
/**

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ class ElasticPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter
3434

3535
@Override
3636
public String prefix() {
37-
return "management.metrics.export.elastic";
37+
return "management.elastic.metrics.export";
3838
}
3939

4040
@Override

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaProperties.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @author Stephane Nicoll
3232
* @since 2.0.0
3333
*/
34-
@ConfigurationProperties(prefix = "management.metrics.export.ganglia")
34+
@ConfigurationProperties(prefix = "management.ganglia.metrics.export")
3535
public class GangliaProperties {
3636

3737
/**

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class GangliaPropertiesConfigAdapter extends PropertiesConfigAdapter<GangliaProp
3838

3939
@Override
4040
public String prefix() {
41-
return "management.metrics.export.ganglia";
41+
return "management.ganglia.metrics.export";
4242
}
4343

4444
@Override

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteProperties.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@
3232
* @author Stephane Nicoll
3333
* @since 2.0.0
3434
*/
35-
@ConfigurationProperties(prefix = "management.metrics.export.graphite")
35+
@ConfigurationProperties(prefix = "management.graphite.metrics.export")
3636
public class GraphiteProperties {
3737

3838
/**

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,7 +38,7 @@ class GraphitePropertiesConfigAdapter extends PropertiesConfigAdapter<GraphitePr
3838

3939
@Override
4040
public String prefix() {
41-
return "management.metrics.export.graphite";
41+
return "management.graphite.metrics.export";
4242
}
4343

4444
@Override

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioProperties.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@
3030
* @author Andy Wilkinson
3131
* @since 2.1.0
3232
*/
33-
@ConfigurationProperties(prefix = "management.metrics.export.humio")
33+
@ConfigurationProperties(prefix = "management.humio.metrics.export")
3434
public class HumioProperties extends StepRegistryProperties {
3535

3636
/**

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioPropertiesConfigAdapter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,7 +35,7 @@ class HumioPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<H
3535

3636
@Override
3737
public String prefix() {
38-
return "management.metrics.export.humio";
38+
return "management.humio.metrics.export";
3939
}
4040

4141
@Override

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxProperties.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@
3030
* @author Stephane Nicoll
3131
* @since 2.0.0
3232
*/
33-
@ConfigurationProperties(prefix = "management.metrics.export.influx")
33+
@ConfigurationProperties(prefix = "management.influx.metrics.export")
3434
public class InfluxProperties extends StepRegistryProperties {
3535

3636
/**

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@ class InfluxPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<
3737

3838
@Override
3939
public String prefix() {
40-
return "management.metrics.export.influx";
40+
return "management.influx.metrics.export";
4141
}
4242

4343
@Override

0 commit comments

Comments
 (0)