Merge pull request #21067 from jkschneider
* gh-21067: Polish "Update validation of Micrometer configuration" Update validation of Micrometer configuration Closes gh-21067
This commit is contained in:
commit
a034c9a118
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
|
|
@ -16,29 +16,29 @@
|
|||
|
||||
package org.springframework.boot.actuate.autoconfigure.metrics;
|
||||
|
||||
import io.micrometer.core.instrument.config.MissingRequiredConfigurationException;
|
||||
import io.micrometer.core.instrument.config.validate.Validated.Invalid;
|
||||
import io.micrometer.core.instrument.config.validate.ValidationException;
|
||||
|
||||
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
|
||||
import org.springframework.boot.diagnostics.FailureAnalysis;
|
||||
|
||||
/**
|
||||
* 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(".");
|
||||
protected FailureAnalysis analyze(Throwable rootFailure, ValidationException cause) {
|
||||
StringBuilder description = new StringBuilder(String.format("Invalid Micrometer configuration detected:%n"));
|
||||
for (Invalid<?> failure : cause.getValidation().failures()) {
|
||||
description.append(String.format("%n - management.metrics.export.%s was '%s' but it %s",
|
||||
failure.getProperty(), failure.getValue(), failure.getMessage()));
|
||||
}
|
||||
return new FailureAnalysis(description.toString(),
|
||||
"Update your application to provide the missing configuration.", cause);
|
||||
"Update your application to correct the invalid 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;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
|
|
@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import info.ganglia.gmetric4j.gmetric.GMetric;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
|
||||
|
||||
/**
|
||||
* {@link ConfigurationProperties @ConfigurationProperties} for configuring Ganglia
|
||||
|
|
@ -47,7 +48,7 @@ public class GangliaProperties {
|
|||
/**
|
||||
* Base time unit used to report rates.
|
||||
*/
|
||||
private TimeUnit rateUnits = TimeUnit.SECONDS;
|
||||
private TimeUnit rateUnits;
|
||||
|
||||
/**
|
||||
* Base time unit used to report durations.
|
||||
|
|
@ -57,7 +58,7 @@ public class GangliaProperties {
|
|||
/**
|
||||
* Ganglia protocol version. Must be either 3.1 or 3.0.
|
||||
*/
|
||||
private String protocolVersion = "3.1";
|
||||
private String protocolVersion;
|
||||
|
||||
/**
|
||||
* UDP addressing mode, either unicast or multicast.
|
||||
|
|
@ -96,10 +97,13 @@ public class GangliaProperties {
|
|||
this.step = step;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@DeprecatedConfigurationProperty(reason = "No longer used by Micormeter")
|
||||
public TimeUnit getRateUnits() {
|
||||
return this.rateUnits;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setRateUnits(TimeUnit rateUnits) {
|
||||
this.rateUnits = rateUnits;
|
||||
}
|
||||
|
|
@ -112,10 +116,13 @@ public class GangliaProperties {
|
|||
this.durationUnits = durationUnits;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@DeprecatedConfigurationProperty(reason = "No longer used by Micormeter")
|
||||
public String getProtocolVersion() {
|
||||
return this.protocolVersion;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setProtocolVersion(String protocolVersion) {
|
||||
this.protocolVersion = protocolVersion;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,11 +36,6 @@ public abstract class PushRegistryPropertiesConfigAdapter<T extends PushRegistry
|
|||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prefix() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(String k) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
|
|
@ -30,19 +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()
|
||||
.analyze(createFailure(MissingAccountIdConfiguration.class));
|
||||
FailureAnalysis analysis = new ValidationFailureAnalyzer()
|
||||
.analyze(createFailure(MissingAccountIdAndApiKeyConfiguration.class));
|
||||
assertThat(analysis).isNotNull();
|
||||
assertThat(analysis.getDescription()).isEqualTo("accountId must be set to report metrics to New Relic.");
|
||||
assertThat(analysis.getAction()).isEqualTo("Update your application to provide the missing configuration.");
|
||||
assertThat(analysis.getDescription()).isEqualTo(String.format("Invalid Micrometer configuration detected:%n%n"
|
||||
+ " - 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"));
|
||||
}
|
||||
|
||||
private Exception createFailure(Class<?> configuration) {
|
||||
|
|
@ -56,7 +57,7 @@ class MissingRequiredConfigurationFailureAnalyzerTests {
|
|||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class MissingAccountIdConfiguration {
|
||||
static class MissingAccountIdAndApiKeyConfiguration {
|
||||
|
||||
@Bean
|
||||
NewRelicMeterRegistry meterRegistry() {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
|
|
@ -29,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
class GangliaPropertiesTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void defaultValuesAreConsistent() {
|
||||
GangliaProperties properties = new GangliaProperties();
|
||||
GangliaConfig config = GangliaConfig.DEFAULT;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
|
|
@ -36,8 +36,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());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue