Merge pull request #21069 from jkschneider
* gh-21069: Polish "Improve property name in thrown Micrometer ValidationException" Improve property name in thrown Micrometer ValidationException Closes gh-21069
This commit is contained in:
commit
b8fbe395ce
|
|
@ -34,8 +34,8 @@ 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",
|
||||
failure.getProperty(), failure.getValue(), failure.getMessage()));
|
||||
description.append(String.format("%n - %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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,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;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -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;
|
||||
|
|
@ -41,6 +44,7 @@ class ValidationFailureAnalyzerTests {
|
|||
FailureAnalysis analysis = new ValidationFailureAnalyzer()
|
||||
.analyze(createFailure(MissingAccountIdAndApiKeyConfiguration.class));
|
||||
assertThat(analysis).isNotNull();
|
||||
assertThat(analysis.getCause().getMessage()).contains("management.metrics.export.newrelic.apiKey was 'null'");
|
||||
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"));
|
||||
|
|
@ -57,11 +61,12 @@ 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…
Reference in New Issue