Improve property name in thrown Micrometer ValidationException
See gh-21069
This commit is contained in:
parent
f0fe7060df
commit
507b062c43
|
|
@ -34,7 +34,7 @@ class ValidationFailureAnalyzer extends AbstractFailureAnalyzer<ValidationExcept
|
||||||
protected FailureAnalysis analyze(Throwable rootFailure, ValidationException cause) {
|
protected FailureAnalysis analyze(Throwable rootFailure, ValidationException cause) {
|
||||||
StringBuilder description = new StringBuilder(String.format("Invalid Micrometer configuration detected:%n"));
|
StringBuilder description = new StringBuilder(String.format("Invalid Micrometer configuration detected:%n"));
|
||||||
for (Invalid<?> failure : cause.getValidation().failures()) {
|
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()));
|
failure.getProperty(), failure.getValue(), failure.getMessage()));
|
||||||
}
|
}
|
||||||
return new FailureAnalysis(description.toString(),
|
return new FailureAnalysis(description.toString(),
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,11 @@ class AppOpticsPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapt
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String prefix() {
|
||||||
|
return "management.metrics.export.appoptics";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String uri() {
|
public String uri() {
|
||||||
return get(AppOpticsProperties::getUri, AppOpticsConfig.super::uri);
|
return get(AppOpticsProperties::getUri, AppOpticsConfig.super::uri);
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,11 @@ class DatadogPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String prefix() {
|
||||||
|
return "management.metrics.export.datadog";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apiKey() {
|
public String apiKey() {
|
||||||
return get(DatadogProperties::getApiKey, DatadogConfig.super::apiKey);
|
return get(DatadogProperties::getApiKey, DatadogConfig.super::apiKey);
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,11 @@ class DynatracePropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapt
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String prefix() {
|
||||||
|
return "management.metrics.export.dynatrace";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apiToken() {
|
public String apiToken() {
|
||||||
return get(DynatraceProperties::getApiToken, DynatraceConfig.super::apiToken);
|
return get(DynatraceProperties::getApiToken, DynatraceConfig.super::apiToken);
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,11 @@ class ElasticPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String prefix() {
|
||||||
|
return "management.metrics.export.elastic";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String host() {
|
public String host() {
|
||||||
return get(ElasticProperties::getHost, ElasticConfig.super::host);
|
return get(ElasticProperties::getHost, ElasticConfig.super::host);
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,11 @@ class GangliaPropertiesConfigAdapter extends PropertiesConfigAdapter<GangliaProp
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String prefix() {
|
||||||
|
return "management.metrics.export.ganglia";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String get(String k) {
|
public String get(String k) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,11 @@ class GraphitePropertiesConfigAdapter extends PropertiesConfigAdapter<GraphitePr
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String prefix() {
|
||||||
|
return "management.metrics.export.graphite";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String get(String k) {
|
public String get(String k) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,11 @@ class HumioPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<H
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String prefix() {
|
||||||
|
return "management.metrics.export.humio";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String get(String k) {
|
public String get(String k) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,11 @@ class InfluxPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String prefix() {
|
||||||
|
return "management.metrics.export.influx";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String db() {
|
public String db() {
|
||||||
return get(InfluxProperties::getDb, InfluxConfig.super::db);
|
return get(InfluxProperties::getDb, InfluxConfig.super::db);
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,11 @@ class JmxPropertiesConfigAdapter extends PropertiesConfigAdapter<JmxProperties>
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String prefix() {
|
||||||
|
return "management.metrics.export.jmx";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String get(String key) {
|
public String get(String key) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,11 @@ class KairosPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String prefix() {
|
||||||
|
return "management.metrics.export.kairos";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String uri() {
|
public String uri() {
|
||||||
return get(KairosProperties::getUri, KairosConfig.super::uri);
|
return get(KairosProperties::getUri, KairosConfig.super::uri);
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,11 @@ public class NewRelicPropertiesConfigAdapter extends StepRegistryPropertiesConfi
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String prefix() {
|
||||||
|
return "management.metrics.export.newrelic";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean meterNameEventTypeEnabled() {
|
public boolean meterNameEventTypeEnabled() {
|
||||||
return get(NewRelicProperties::isMeterNameEventTypeEnabled, NewRelicConfig.super::meterNameEventTypeEnabled);
|
return get(NewRelicProperties::isMeterNameEventTypeEnabled, NewRelicConfig.super::meterNameEventTypeEnabled);
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,11 @@ class PrometheusPropertiesConfigAdapter extends PropertiesConfigAdapter<Promethe
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String prefix() {
|
||||||
|
return "management.metrics.export.prometheus";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String get(String key) {
|
public String get(String key) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,11 @@ public class SignalFxPropertiesConfigAdapter extends StepRegistryPropertiesConfi
|
||||||
accessToken(); // validate that an access token is set
|
accessToken(); // validate that an access token is set
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String prefix() {
|
||||||
|
return "management.metrics.export.signalfx";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String accessToken() {
|
public String accessToken() {
|
||||||
return get(SignalFxProperties::getAccessToken, SignalFxConfig.super::accessToken);
|
return get(SignalFxProperties::getAccessToken, SignalFxConfig.super::accessToken);
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,11 @@ public class SimplePropertiesConfigAdapter extends PropertiesConfigAdapter<Simpl
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String prefix() {
|
||||||
|
return "management.metrics.export.simple";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String get(String k) {
|
public String get(String k) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,11 @@ public class StackdriverPropertiesConfigAdapter extends StepRegistryPropertiesCo
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String prefix() {
|
||||||
|
return "management.metrics.export.stackdriver";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String projectId() {
|
public String projectId() {
|
||||||
return get(StackdriverProperties::getProjectId, StackdriverConfig.super::projectId);
|
return get(StackdriverProperties::getProjectId, StackdriverConfig.super::projectId);
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,11 @@ public class StatsdPropertiesConfigAdapter extends PropertiesConfigAdapter<Stats
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String prefix() {
|
||||||
|
return "management.metrics.export.statsd";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StatsdFlavor flavor() {
|
public StatsdFlavor flavor() {
|
||||||
return get(StatsdProperties::getFlavor, StatsdConfig.super::flavor);
|
return get(StatsdProperties::getFlavor, StatsdConfig.super::flavor);
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,11 @@ public class WavefrontPropertiesConfigAdapter extends PushRegistryPropertiesConf
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String prefix() {
|
||||||
|
return "management.metrics.export.wavefront";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String get(String k) {
|
public String get(String k) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,14 @@ import io.micrometer.core.instrument.Clock;
|
||||||
import io.micrometer.newrelic.NewRelicMeterRegistry;
|
import io.micrometer.newrelic.NewRelicMeterRegistry;
|
||||||
import org.junit.jupiter.api.Test;
|
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.boot.diagnostics.FailureAnalysis;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
@ -40,6 +43,7 @@ class ValidationFailureAnalyzerTests {
|
||||||
void analyzesMissingRequiredConfiguration() {
|
void analyzesMissingRequiredConfiguration() {
|
||||||
FailureAnalysis analysis = new ValidationFailureAnalyzer()
|
FailureAnalysis analysis = new ValidationFailureAnalyzer()
|
||||||
.analyze(createFailure(MissingAccountIdAndApiKeyConfiguration.class));
|
.analyze(createFailure(MissingAccountIdAndApiKeyConfiguration.class));
|
||||||
|
assertThat(analysis.getCause().getMessage()).contains("management.metrics.export.newrelic.apiKey was 'null'");
|
||||||
assertThat(analysis).isNotNull();
|
assertThat(analysis).isNotNull();
|
||||||
assertThat(analysis.getDescription()).isEqualTo(String.format("Invalid Micrometer configuration detected:%n%n"
|
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.apiKey was 'null' but it is required when publishing to Insights API%n"
|
||||||
|
|
@ -57,11 +61,11 @@ class ValidationFailureAnalyzerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@Import(NewRelicProperties.class)
|
||||||
static class MissingAccountIdAndApiKeyConfiguration {
|
static class MissingAccountIdAndApiKeyConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
NewRelicMeterRegistry meterRegistry() {
|
NewRelicMeterRegistry meterRegistry(NewRelicProperties newRelicProperties) {
|
||||||
return new NewRelicMeterRegistry((key) -> null, Clock.SYSTEM);
|
return new NewRelicMeterRegistry(new NewRelicPropertiesConfigAdapter(newRelicProperties), Clock.SYSTEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue