Skip to content

Commit 60a76ce

Browse files
committed
Polish "Update validation of Micrometer configuration"
See gh-21067
1 parent 9579826 commit 60a76ce

File tree

6 files changed

+28
-36
lines changed

6 files changed

+28
-36
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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,31 +16,29 @@
1616

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

19+
import io.micrometer.core.instrument.config.validate.Validated.Invalid;
1920
import io.micrometer.core.instrument.config.validate.ValidationException;
21+
2022
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
2123
import org.springframework.boot.diagnostics.FailureAnalysis;
2224

23-
import java.util.stream.Collectors;
24-
2525
/**
2626
* An {@link AbstractFailureAnalyzer} that performs analysis of failures caused by a
2727
* {@link ValidationException}.
2828
*
2929
* @author Andy Wilkinson
3030
*/
31-
class ValidationFailureAnalyzer
32-
extends AbstractFailureAnalyzer<ValidationException> {
31+
class ValidationFailureAnalyzer extends AbstractFailureAnalyzer<ValidationException> {
3332

3433
@Override
3534
protected FailureAnalysis analyze(Throwable rootFailure, ValidationException cause) {
36-
String description = cause.getValidation().failures().stream()
37-
.map(failure -> "management.metrics.export." + failure.getProperty() + " was '" +
38-
(failure.getValue() == null ? "null" : failure.getValue().toString()) +
39-
"' but it " + failure.getMessage() + ".")
40-
.collect(Collectors.joining("\n"));
41-
42-
return new FailureAnalysis(description,
43-
"Update your application to provide the missing configuration.", cause);
35+
StringBuilder description = new StringBuilder(String.format("Invalid Micrometer configuration detected:%n"));
36+
for (Invalid<?> failure : cause.getValidation().failures()) {
37+
description.append(String.format("%n - management.metrics.export.%s was '%s' but it %s",
38+
failure.getProperty(), failure.getValue(), failure.getMessage()));
39+
}
40+
return new FailureAnalysis(description.toString(),
41+
"Update your application to correct the invalid configuration.", cause);
4442
}
4543

4644
}

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -22,6 +22,7 @@
2222
import info.ganglia.gmetric4j.gmetric.GMetric;
2323

2424
import org.springframework.boot.context.properties.ConfigurationProperties;
25+
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
2526

2627
/**
2728
* {@link ConfigurationProperties @ConfigurationProperties} for configuring Ganglia
@@ -46,10 +47,7 @@ public class GangliaProperties {
4647

4748
/**
4849
* Base time unit used to report rates.
49-
*
50-
* @deprecated No longer used by Micrometer.
5150
*/
52-
@Deprecated
5351
private TimeUnit rateUnits;
5452

5553
/**
@@ -59,10 +57,7 @@ public class GangliaProperties {
5957

6058
/**
6159
* Ganglia protocol version. Must be either 3.1 or 3.0.
62-
*
63-
* @deprecated No longer used by Micrometer.
6460
*/
65-
@Deprecated
6661
private String protocolVersion;
6762

6863
/**
@@ -102,10 +97,13 @@ public void setStep(Duration step) {
10297
this.step = step;
10398
}
10499

100+
@Deprecated
101+
@DeprecatedConfigurationProperty(reason = "No longer used by Micormeter")
105102
public TimeUnit getRateUnits() {
106103
return this.rateUnits;
107104
}
108105

106+
@Deprecated
109107
public void setRateUnits(TimeUnit rateUnits) {
110108
this.rateUnits = rateUnits;
111109
}
@@ -118,10 +116,13 @@ public void setDurationUnits(TimeUnit durationUnits) {
118116
this.durationUnits = durationUnits;
119117
}
120118

119+
@Deprecated
120+
@DeprecatedConfigurationProperty(reason = "No longer used by Micormeter")
121121
public String getProtocolVersion() {
122122
return this.protocolVersion;
123123
}
124124

125+
@Deprecated
125126
public void setProtocolVersion(String protocolVersion) {
126127
this.protocolVersion = protocolVersion;
127128
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ public PushRegistryPropertiesConfigAdapter(T properties) {
3636
super(properties);
3737
}
3838

39-
@Override
40-
public String prefix() {
41-
return null;
42-
}
43-
4439
@Override
4540
public String get(String k) {
4641
return null;

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/ValidationFailureAnalyzerTests.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -39,12 +39,11 @@ class ValidationFailureAnalyzerTests {
3939
@Test
4040
void analyzesMissingRequiredConfiguration() {
4141
FailureAnalysis analysis = new ValidationFailureAnalyzer()
42-
.analyze(createFailure(MissingAccountIdConfiguration.class));
42+
.analyze(createFailure(MissingAccountIdAndApiKeyConfiguration.class));
4343
assertThat(analysis).isNotNull();
44-
assertThat(analysis.getDescription()).isEqualTo(
45-
"management.metrics.export.newrelic.apiKey was 'null' but it is required when publishing to Insights API.\n" +
46-
"management.metrics.export.newrelic.accountId was 'null' but it is required when publishing to Insights API.");
47-
assertThat(analysis.getAction()).isEqualTo("Update your application to provide the missing configuration.");
44+
assertThat(analysis.getDescription()).isEqualTo(String.format("Invalid Micrometer configuration detected:%n%n"
45+
+ " - management.metrics.export.newrelic.apiKey was 'null' but it is required when publishing to Insights API%n"
46+
+ " - management.metrics.export.newrelic.accountId was 'null' but it is required when publishing to Insights API"));
4847
}
4948

5049
private Exception createFailure(Class<?> configuration) {
@@ -58,7 +57,7 @@ private Exception createFailure(Class<?> configuration) {
5857
}
5958

6059
@Configuration(proxyBeanMethods = false)
61-
static class MissingAccountIdConfiguration {
60+
static class MissingAccountIdAndApiKeyConfiguration {
6261

6362
@Bean
6463
NewRelicMeterRegistry meterRegistry() {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -29,6 +29,7 @@
2929
class GangliaPropertiesTests {
3030

3131
@Test
32+
@SuppressWarnings("deprecation")
3233
void defaultValuesAreConsistent() {
3334
GangliaProperties properties = new GangliaProperties();
3435
GangliaConfig config = GangliaConfig.DEFAULT;

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontPropertiesTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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,14 +16,12 @@
1616

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

19-
import io.micrometer.core.instrument.config.validate.ValidationException;
2019
import io.micrometer.wavefront.WavefrontConfig;
2120
import org.junit.jupiter.api.Test;
2221

2322
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.PushRegistryPropertiesTests;
2423

2524
import static org.assertj.core.api.Assertions.assertThat;
26-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2725

2826
/**
2927
* Tests for {@link WavefrontProperties}.

0 commit comments

Comments
 (0)