Update validation of Micrometer configuration
See gh-21067
This commit is contained in:
committed by
Andy Wilkinson
parent
e26f3e2a65
commit
95798265b6
@@ -16,28 +16,30 @@
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure.metrics;
|
||||
|
||||
import io.micrometer.core.instrument.config.MissingRequiredConfigurationException;
|
||||
|
||||
import io.micrometer.core.instrument.config.validate.ValidationException;
|
||||
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
|
||||
import org.springframework.boot.diagnostics.FailureAnalysis;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* An {@link AbstractFailureAnalyzer} that performs analysis of failures caused by a
|
||||
* {@link MissingRequiredConfigurationException}.
|
||||
* {@link ValidationException}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
class MissingRequiredConfigurationFailureAnalyzer
|
||||
extends AbstractFailureAnalyzer<MissingRequiredConfigurationException> {
|
||||
class ValidationFailureAnalyzer
|
||||
extends AbstractFailureAnalyzer<ValidationException> {
|
||||
|
||||
@Override
|
||||
protected FailureAnalysis analyze(Throwable rootFailure, MissingRequiredConfigurationException cause) {
|
||||
StringBuilder description = new StringBuilder();
|
||||
description.append(cause.getMessage());
|
||||
if (!cause.getMessage().endsWith(".")) {
|
||||
description.append(".");
|
||||
}
|
||||
return new FailureAnalysis(description.toString(),
|
||||
protected FailureAnalysis analyze(Throwable rootFailure, ValidationException cause) {
|
||||
String description = cause.getValidation().failures().stream()
|
||||
.map(failure -> "management.metrics.export." + failure.getProperty() + " was '" +
|
||||
(failure.getValue() == null ? "null" : failure.getValue().toString()) +
|
||||
"' but it " + failure.getMessage() + ".")
|
||||
.collect(Collectors.joining("\n"));
|
||||
|
||||
return new FailureAnalysis(description,
|
||||
"Update your application to provide the missing configuration.", cause);
|
||||
}
|
||||
|
||||
@@ -62,17 +62,17 @@ public class ElasticProperties extends StepRegistryProperties {
|
||||
/**
|
||||
* Login user of the Elastic server.
|
||||
*/
|
||||
private String userName = "";
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* Login password of the Elastic server.
|
||||
*/
|
||||
private String password = "";
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* Ingest pipeline name. By default, events are not pre-processed.
|
||||
*/
|
||||
private String pipeline = "";
|
||||
private String pipeline;
|
||||
|
||||
public String getHost() {
|
||||
return this.host;
|
||||
|
||||
@@ -46,8 +46,11 @@ public class GangliaProperties {
|
||||
|
||||
/**
|
||||
* Base time unit used to report rates.
|
||||
*
|
||||
* @deprecated No longer used by Micrometer.
|
||||
*/
|
||||
private TimeUnit rateUnits = TimeUnit.SECONDS;
|
||||
@Deprecated
|
||||
private TimeUnit rateUnits;
|
||||
|
||||
/**
|
||||
* Base time unit used to report durations.
|
||||
@@ -56,8 +59,11 @@ public class GangliaProperties {
|
||||
|
||||
/**
|
||||
* Ganglia protocol version. Must be either 3.1 or 3.0.
|
||||
*
|
||||
* @deprecated No longer used by Micrometer.
|
||||
*/
|
||||
private String protocolVersion = "3.1";
|
||||
@Deprecated
|
||||
private String protocolVersion;
|
||||
|
||||
/**
|
||||
* UDP addressing mode, either unicast or multicast.
|
||||
|
||||
@@ -105,4 +105,4 @@ org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementChil
|
||||
org.springframework.boot.actuate.autoconfigure.web.servlet.WebMvcEndpointChildContextConfiguration
|
||||
|
||||
org.springframework.boot.diagnostics.FailureAnalyzer=\
|
||||
org.springframework.boot.actuate.autoconfigure.metrics.MissingRequiredConfigurationFailureAnalyzer
|
||||
org.springframework.boot.actuate.autoconfigure.metrics.ValidationFailureAnalyzer
|
||||
|
||||
@@ -30,18 +30,20 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Tests for {@link MissingRequiredConfigurationFailureAnalyzer}.
|
||||
* Tests for {@link ValidationFailureAnalyzer}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
class MissingRequiredConfigurationFailureAnalyzerTests {
|
||||
class ValidationFailureAnalyzerTests {
|
||||
|
||||
@Test
|
||||
void analyzesMissingRequiredConfiguration() {
|
||||
FailureAnalysis analysis = new MissingRequiredConfigurationFailureAnalyzer()
|
||||
FailureAnalysis analysis = new ValidationFailureAnalyzer()
|
||||
.analyze(createFailure(MissingAccountIdConfiguration.class));
|
||||
assertThat(analysis).isNotNull();
|
||||
assertThat(analysis.getDescription()).isEqualTo("accountId must be set to report metrics to New Relic.");
|
||||
assertThat(analysis.getDescription()).isEqualTo(
|
||||
"management.metrics.export.newrelic.apiKey was 'null' but it is required when publishing to Insights API.\n" +
|
||||
"management.metrics.export.newrelic.accountId was 'null' but it is required when publishing to Insights API.");
|
||||
assertThat(analysis.getAction()).isEqualTo("Update your application to provide the missing configuration.");
|
||||
}
|
||||
|
||||
@@ -16,12 +16,14 @@
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront;
|
||||
|
||||
import io.micrometer.core.instrument.config.validate.ValidationException;
|
||||
import io.micrometer.wavefront.WavefrontConfig;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.PushRegistryPropertiesTests;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/**
|
||||
* Tests for {@link WavefrontProperties}.
|
||||
@@ -36,8 +38,6 @@ class WavefrontPropertiesTests extends PushRegistryPropertiesTests {
|
||||
WavefrontConfig config = WavefrontConfig.DEFAULT_DIRECT;
|
||||
assertStepRegistryDefaultValues(properties, config);
|
||||
assertThat(properties.getUri().toString()).isEqualTo(config.uri());
|
||||
// source has no static default value
|
||||
assertThat(properties.getApiToken()).isEqualTo(config.apiToken());
|
||||
assertThat(properties.getGlobalPrefix()).isEqualTo(config.globalPrefix());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user