Polish "Update validation of Micrometer configuration"

See gh-21067
pull/21069/head
Andy Wilkinson 5 years ago
parent 95798265b6
commit 60a76ce6e7

@ -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,31 +16,29 @@
package org.springframework.boot.actuate.autoconfigure.metrics;
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;
import java.util.stream.Collectors;
/**
* An {@link AbstractFailureAnalyzer} that performs analysis of failures caused by a
* {@link ValidationException}.
*
* @author Andy Wilkinson
*/
class ValidationFailureAnalyzer
extends AbstractFailureAnalyzer<ValidationException> {
class ValidationFailureAnalyzer extends AbstractFailureAnalyzer<ValidationException> {
@Override
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);
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 correct the invalid configuration.", cause);
}
}

@ -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
@ -46,10 +47,7 @@ public class GangliaProperties {
/**
* Base time unit used to report rates.
*
* @deprecated No longer used by Micrometer.
*/
@Deprecated
private TimeUnit rateUnits;
/**
@ -59,10 +57,7 @@ public class GangliaProperties {
/**
* Ganglia protocol version. Must be either 3.1 or 3.0.
*
* @deprecated No longer used by Micrometer.
*/
@Deprecated
private String protocolVersion;
/**
@ -102,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;
}
@ -118,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;

@ -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.
@ -39,12 +39,11 @@ class ValidationFailureAnalyzerTests {
@Test
void analyzesMissingRequiredConfiguration() {
FailureAnalysis analysis = new ValidationFailureAnalyzer()
.analyze(createFailure(MissingAccountIdConfiguration.class));
.analyze(createFailure(MissingAccountIdAndApiKeyConfiguration.class));
assertThat(analysis).isNotNull();
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.");
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) {
@ -58,7 +57,7 @@ class ValidationFailureAnalyzerTests {
}
@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.
@ -16,14 +16,12 @@
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}.

Loading…
Cancel
Save