Improve property name in thrown Micrometer ValidationException

See gh-21069
pull/21079/head
Jon Schneider 5 years ago committed by Andy Wilkinson
parent f0fe7060df
commit 507b062c43

@ -34,7 +34,7 @@ class ValidationFailureAnalyzer extends AbstractFailureAnalyzer<ValidationExcept
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",
description.append(String.format("%n - %s was '%s' but it %s",
failure.getProperty(), failure.getValue(), failure.getMessage()));
}
return new FailureAnalysis(description.toString(),

@ -32,6 +32,11 @@ class AppOpticsPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapt
super(properties);
}
@Override
public String prefix() {
return "management.metrics.export.appoptics";
}
@Override
public String uri() {
return get(AppOpticsProperties::getUri, AppOpticsConfig.super::uri);

@ -33,6 +33,11 @@ class DatadogPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter
super(properties);
}
@Override
public String prefix() {
return "management.metrics.export.datadog";
}
@Override
public String apiKey() {
return get(DatadogProperties::getApiKey, DatadogConfig.super::apiKey);

@ -32,6 +32,11 @@ class DynatracePropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapt
super(properties);
}
@Override
public String prefix() {
return "management.metrics.export.dynatrace";
}
@Override
public String apiToken() {
return get(DynatraceProperties::getApiToken, DynatraceConfig.super::apiToken);

@ -32,6 +32,11 @@ class ElasticPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter
super(properties);
}
@Override
public String prefix() {
return "management.metrics.export.elastic";
}
@Override
public String host() {
return get(ElasticProperties::getHost, ElasticConfig.super::host);

@ -36,6 +36,11 @@ class GangliaPropertiesConfigAdapter extends PropertiesConfigAdapter<GangliaProp
super(properties);
}
@Override
public String prefix() {
return "management.metrics.export.ganglia";
}
@Override
public String get(String k) {
return null;

@ -36,6 +36,11 @@ class GraphitePropertiesConfigAdapter extends PropertiesConfigAdapter<GraphitePr
super(properties);
}
@Override
public String prefix() {
return "management.metrics.export.graphite";
}
@Override
public String get(String k) {
return null;

@ -33,6 +33,11 @@ class HumioPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<H
super(properties);
}
@Override
public String prefix() {
return "management.metrics.export.humio";
}
@Override
public String get(String k) {
return null;

@ -34,6 +34,11 @@ class InfluxPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<
super(properties);
}
@Override
public String prefix() {
return "management.metrics.export.influx";
}
@Override
public String db() {
return get(InfluxProperties::getDb, InfluxConfig.super::db);

@ -34,6 +34,11 @@ class JmxPropertiesConfigAdapter extends PropertiesConfigAdapter<JmxProperties>
super(properties);
}
@Override
public String prefix() {
return "management.metrics.export.jmx";
}
@Override
public String get(String key) {
return null;

@ -32,6 +32,11 @@ class KairosPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<
super(properties);
}
@Override
public String prefix() {
return "management.metrics.export.kairos";
}
@Override
public String uri() {
return get(KairosProperties::getUri, KairosConfig.super::uri);

@ -35,6 +35,11 @@ public class NewRelicPropertiesConfigAdapter extends StepRegistryPropertiesConfi
super(properties);
}
@Override
public String prefix() {
return "management.metrics.export.newrelic";
}
@Override
public boolean meterNameEventTypeEnabled() {
return get(NewRelicProperties::isMeterNameEventTypeEnabled, NewRelicConfig.super::meterNameEventTypeEnabled);

@ -36,6 +36,11 @@ class PrometheusPropertiesConfigAdapter extends PropertiesConfigAdapter<Promethe
super(properties);
}
@Override
public String prefix() {
return "management.metrics.export.prometheus";
}
@Override
public String get(String key) {
return null;

@ -34,6 +34,11 @@ public class SignalFxPropertiesConfigAdapter extends StepRegistryPropertiesConfi
accessToken(); // validate that an access token is set
}
@Override
public String prefix() {
return "management.metrics.export.signalfx";
}
@Override
public String accessToken() {
return get(SignalFxProperties::getAccessToken, SignalFxConfig.super::accessToken);

@ -35,6 +35,11 @@ public class SimplePropertiesConfigAdapter extends PropertiesConfigAdapter<Simpl
super(properties);
}
@Override
public String prefix() {
return "management.metrics.export.simple";
}
@Override
public String get(String k) {
return null;

@ -33,6 +33,11 @@ public class StackdriverPropertiesConfigAdapter extends StepRegistryPropertiesCo
super(properties);
}
@Override
public String prefix() {
return "management.metrics.export.stackdriver";
}
@Override
public String projectId() {
return get(StackdriverProperties::getProjectId, StackdriverConfig.super::projectId);

@ -40,6 +40,11 @@ public class StatsdPropertiesConfigAdapter extends PropertiesConfigAdapter<Stats
return null;
}
@Override
public String prefix() {
return "management.metrics.export.statsd";
}
@Override
public StatsdFlavor flavor() {
return get(StatsdProperties::getFlavor, StatsdConfig.super::flavor);

@ -33,6 +33,11 @@ public class WavefrontPropertiesConfigAdapter extends PushRegistryPropertiesConf
super(properties);
}
@Override
public String prefix() {
return "management.metrics.export.wavefront";
}
@Override
public String get(String k) {
return null;

@ -20,11 +20,14 @@ import io.micrometer.core.instrument.Clock;
import io.micrometer.newrelic.NewRelicMeterRegistry;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.export.newrelic.NewRelicProperties;
import org.springframework.boot.actuate.autoconfigure.metrics.export.newrelic.NewRelicPropertiesConfigAdapter;
import org.springframework.boot.diagnostics.FailureAnalysis;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
@ -40,6 +43,7 @@ class ValidationFailureAnalyzerTests {
void analyzesMissingRequiredConfiguration() {
FailureAnalysis analysis = new ValidationFailureAnalyzer()
.analyze(createFailure(MissingAccountIdAndApiKeyConfiguration.class));
assertThat(analysis.getCause().getMessage()).contains("management.metrics.export.newrelic.apiKey was 'null'");
assertThat(analysis).isNotNull();
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"
@ -57,11 +61,11 @@ class ValidationFailureAnalyzerTests {
}
@Configuration(proxyBeanMethods = false)
@Import(NewRelicProperties.class)
static class MissingAccountIdAndApiKeyConfiguration {
@Bean
NewRelicMeterRegistry meterRegistry() {
return new NewRelicMeterRegistry((key) -> null, Clock.SYSTEM);
NewRelicMeterRegistry meterRegistry(NewRelicProperties newRelicProperties) {
return new NewRelicMeterRegistry(new NewRelicPropertiesConfigAdapter(newRelicProperties), Clock.SYSTEM);
}
}

Loading…
Cancel
Save