Commit b8fbe395 authored by Andy Wilkinson's avatar Andy Wilkinson

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
parents f0fe7060 ab82e59a
...@@ -34,8 +34,8 @@ class ValidationFailureAnalyzer extends AbstractFailureAnalyzer<ValidationExcept ...@@ -34,8 +34,8 @@ 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.getProperty(), failure.getValue(), failure.getMessage())); failure.getMessage()));
} }
return new FailureAnalysis(description.toString(), return new FailureAnalysis(description.toString(),
"Update your application to correct the invalid configuration.", cause); "Update your application to correct the invalid configuration.", cause);
......
...@@ -32,6 +32,11 @@ class AppOpticsPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapt ...@@ -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);
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -33,6 +33,11 @@ class DatadogPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter ...@@ -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);
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -32,6 +32,11 @@ class DynatracePropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapt ...@@ -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 ...@@ -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);
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -36,6 +36,11 @@ class GangliaPropertiesConfigAdapter extends PropertiesConfigAdapter<GangliaProp ...@@ -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 ...@@ -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 ...@@ -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;
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -34,6 +34,11 @@ class InfluxPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter< ...@@ -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);
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -34,6 +34,11 @@ class JmxPropertiesConfigAdapter extends PropertiesConfigAdapter<JmxProperties> ...@@ -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;
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -32,6 +32,11 @@ class KairosPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter< ...@@ -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 ...@@ -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 ...@@ -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;
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -34,6 +34,11 @@ public class SignalFxPropertiesConfigAdapter extends StepRegistryPropertiesConfi ...@@ -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);
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -35,6 +35,11 @@ public class SimplePropertiesConfigAdapter extends PropertiesConfigAdapter<Simpl ...@@ -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 ...@@ -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);
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -40,6 +40,11 @@ public class StatsdPropertiesConfigAdapter extends PropertiesConfigAdapter<Stats ...@@ -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);
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -33,6 +33,11 @@ public class WavefrontPropertiesConfigAdapter extends PushRegistryPropertiesConf ...@@ -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; ...@@ -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;
...@@ -41,6 +44,7 @@ class ValidationFailureAnalyzerTests { ...@@ -41,6 +44,7 @@ class ValidationFailureAnalyzerTests {
FailureAnalysis analysis = new ValidationFailureAnalyzer() FailureAnalysis analysis = new ValidationFailureAnalyzer()
.analyze(createFailure(MissingAccountIdAndApiKeyConfiguration.class)); .analyze(createFailure(MissingAccountIdAndApiKeyConfiguration.class));
assertThat(analysis).isNotNull(); 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" 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"
+ " - management.metrics.export.newrelic.accountId was 'null' but it is required when publishing to Insights API")); + " - management.metrics.export.newrelic.accountId was 'null' but it is required when publishing to Insights API"));
...@@ -57,11 +61,12 @@ class ValidationFailureAnalyzerTests { ...@@ -57,11 +61,12 @@ 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);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment