Skip to content

Commit b8fbe39

Browse files
committed
Merge pull request #21069 from jkschneider
* gh-21069: Polish "Improve property name in thrown Micrometer ValidationException" Improve property name in thrown Micrometer ValidationException Closes gh-21069
2 parents f0fe706 + ab82e59 commit b8fbe39

19 files changed

+104
-14
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class ValidationFailureAnalyzer extends AbstractFailureAnalyzer<ValidationExcept
3434
protected FailureAnalysis analyze(Throwable rootFailure, ValidationException cause) {
3535
StringBuilder description = new StringBuilder(String.format("Invalid Micrometer configuration detected:%n"));
3636
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()));
37+
description.append(String.format("%n - %s was '%s' but it %s", failure.getProperty(), failure.getValue(),
38+
failure.getMessage()));
3939
}
4040
return new FailureAnalysis(description.toString(),
4141
"Update your application to correct the invalid configuration.", cause);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class AppOpticsPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapt
3232
super(properties);
3333
}
3434

35+
@Override
36+
public String prefix() {
37+
return "management.metrics.export.appoptics";
38+
}
39+
3540
@Override
3641
public String uri() {
3742
return get(AppOpticsProperties::getUri, AppOpticsConfig.super::uri);

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

Lines changed: 6 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.
@@ -33,6 +33,11 @@ class DatadogPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter
3333
super(properties);
3434
}
3535

36+
@Override
37+
public String prefix() {
38+
return "management.metrics.export.datadog";
39+
}
40+
3641
@Override
3742
public String apiKey() {
3843
return get(DatadogProperties::getApiKey, DatadogConfig.super::apiKey);

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

Lines changed: 6 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.
@@ -32,6 +32,11 @@ class DynatracePropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapt
3232
super(properties);
3333
}
3434

35+
@Override
36+
public String prefix() {
37+
return "management.metrics.export.dynatrace";
38+
}
39+
3540
@Override
3641
public String apiToken() {
3742
return get(DynatraceProperties::getApiToken, DynatraceConfig.super::apiToken);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class ElasticPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter
3232
super(properties);
3333
}
3434

35+
@Override
36+
public String prefix() {
37+
return "management.metrics.export.elastic";
38+
}
39+
3540
@Override
3641
public String host() {
3742
return get(ElasticProperties::getHost, ElasticConfig.super::host);

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

Lines changed: 6 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.
@@ -36,6 +36,11 @@ class GangliaPropertiesConfigAdapter extends PropertiesConfigAdapter<GangliaProp
3636
super(properties);
3737
}
3838

39+
@Override
40+
public String prefix() {
41+
return "management.metrics.export.ganglia";
42+
}
43+
3944
@Override
4045
public String get(String k) {
4146
return null;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class GraphitePropertiesConfigAdapter extends PropertiesConfigAdapter<GraphitePr
3636
super(properties);
3737
}
3838

39+
@Override
40+
public String prefix() {
41+
return "management.metrics.export.graphite";
42+
}
43+
3944
@Override
4045
public String get(String k) {
4146
return null;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class HumioPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<H
3333
super(properties);
3434
}
3535

36+
@Override
37+
public String prefix() {
38+
return "management.metrics.export.humio";
39+
}
40+
3641
@Override
3742
public String get(String k) {
3843
return null;

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

Lines changed: 6 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.
@@ -34,6 +34,11 @@ class InfluxPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<
3434
super(properties);
3535
}
3636

37+
@Override
38+
public String prefix() {
39+
return "management.metrics.export.influx";
40+
}
41+
3742
@Override
3843
public String db() {
3944
return get(InfluxProperties::getDb, InfluxConfig.super::db);

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

Lines changed: 6 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.
@@ -34,6 +34,11 @@ class JmxPropertiesConfigAdapter extends PropertiesConfigAdapter<JmxProperties>
3434
super(properties);
3535
}
3636

37+
@Override
38+
public String prefix() {
39+
return "management.metrics.export.jmx";
40+
}
41+
3742
@Override
3843
public String get(String key) {
3944
return null;

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

Lines changed: 6 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.
@@ -32,6 +32,11 @@ class KairosPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<
3232
super(properties);
3333
}
3434

35+
@Override
36+
public String prefix() {
37+
return "management.metrics.export.kairos";
38+
}
39+
3540
@Override
3641
public String uri() {
3742
return get(KairosProperties::getUri, KairosConfig.super::uri);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public NewRelicPropertiesConfigAdapter(NewRelicProperties properties) {
3535
super(properties);
3636
}
3737

38+
@Override
39+
public String prefix() {
40+
return "management.metrics.export.newrelic";
41+
}
42+
3843
@Override
3944
public boolean meterNameEventTypeEnabled() {
4045
return get(NewRelicProperties::isMeterNameEventTypeEnabled, NewRelicConfig.super::meterNameEventTypeEnabled);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class PrometheusPropertiesConfigAdapter extends PropertiesConfigAdapter<Promethe
3636
super(properties);
3737
}
3838

39+
@Override
40+
public String prefix() {
41+
return "management.metrics.export.prometheus";
42+
}
43+
3944
@Override
4045
public String get(String key) {
4146
return null;

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

Lines changed: 6 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.
@@ -34,6 +34,11 @@ public SignalFxPropertiesConfigAdapter(SignalFxProperties properties) {
3434
accessToken(); // validate that an access token is set
3535
}
3636

37+
@Override
38+
public String prefix() {
39+
return "management.metrics.export.signalfx";
40+
}
41+
3742
@Override
3843
public String accessToken() {
3944
return get(SignalFxProperties::getAccessToken, SignalFxConfig.super::accessToken);

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

Lines changed: 6 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.
@@ -35,6 +35,11 @@ public SimplePropertiesConfigAdapter(SimpleProperties properties) {
3535
super(properties);
3636
}
3737

38+
@Override
39+
public String prefix() {
40+
return "management.metrics.export.simple";
41+
}
42+
3843
@Override
3944
public String get(String k) {
4045
return null;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public StackdriverPropertiesConfigAdapter(StackdriverProperties properties) {
3333
super(properties);
3434
}
3535

36+
@Override
37+
public String prefix() {
38+
return "management.metrics.export.stackdriver";
39+
}
40+
3641
@Override
3742
public String projectId() {
3843
return get(StackdriverProperties::getProjectId, StackdriverConfig.super::projectId);

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

Lines changed: 6 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.
@@ -40,6 +40,11 @@ public String get(String s) {
4040
return null;
4141
}
4242

43+
@Override
44+
public String prefix() {
45+
return "management.metrics.export.statsd";
46+
}
47+
4348
@Override
4449
public StatsdFlavor flavor() {
4550
return get(StatsdProperties::getFlavor, StatsdConfig.super::flavor);

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

Lines changed: 6 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.
@@ -33,6 +33,11 @@ public WavefrontPropertiesConfigAdapter(WavefrontProperties properties) {
3333
super(properties);
3434
}
3535

36+
@Override
37+
public String prefix() {
38+
return "management.metrics.export.wavefront";
39+
}
40+
3641
@Override
3742
public String get(String k) {
3843
return null;

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020
import io.micrometer.newrelic.NewRelicMeterRegistry;
2121
import org.junit.jupiter.api.Test;
2222

23+
import org.springframework.boot.actuate.autoconfigure.metrics.export.newrelic.NewRelicProperties;
24+
import org.springframework.boot.actuate.autoconfigure.metrics.export.newrelic.NewRelicPropertiesConfigAdapter;
2325
import org.springframework.boot.diagnostics.FailureAnalysis;
2426
import org.springframework.context.ConfigurableApplicationContext;
2527
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
2628
import org.springframework.context.annotation.Bean;
2729
import org.springframework.context.annotation.Configuration;
30+
import org.springframework.context.annotation.Import;
2831

2932
import static org.assertj.core.api.Assertions.assertThat;
3033
import static org.junit.jupiter.api.Assertions.fail;
@@ -41,6 +44,7 @@ void analyzesMissingRequiredConfiguration() {
4144
FailureAnalysis analysis = new ValidationFailureAnalyzer()
4245
.analyze(createFailure(MissingAccountIdAndApiKeyConfiguration.class));
4346
assertThat(analysis).isNotNull();
47+
assertThat(analysis.getCause().getMessage()).contains("management.metrics.export.newrelic.apiKey was 'null'");
4448
assertThat(analysis.getDescription()).isEqualTo(String.format("Invalid Micrometer configuration detected:%n%n"
4549
+ " - management.metrics.export.newrelic.apiKey was 'null' but it is required when publishing to Insights API%n"
4650
+ " - management.metrics.export.newrelic.accountId was 'null' but it is required when publishing to Insights API"));
@@ -57,11 +61,12 @@ private Exception createFailure(Class<?> configuration) {
5761
}
5862

5963
@Configuration(proxyBeanMethods = false)
64+
@Import(NewRelicProperties.class)
6065
static class MissingAccountIdAndApiKeyConfiguration {
6166

6267
@Bean
63-
NewRelicMeterRegistry meterRegistry() {
64-
return new NewRelicMeterRegistry((key) -> null, Clock.SYSTEM);
68+
NewRelicMeterRegistry meterRegistry(NewRelicProperties newRelicProperties) {
69+
return new NewRelicMeterRegistry(new NewRelicPropertiesConfigAdapter(newRelicProperties), Clock.SYSTEM);
6570
}
6671

6772
}

0 commit comments

Comments
 (0)