Skip to content

Improve property name in thrown Micrometer ValidationException #21069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public NewRelicPropertiesConfigAdapter(NewRelicProperties properties) {
super(properties);
}

@Override
public String prefix() {
return "management.metrics.export.newrelic";
}

@Override
public boolean meterNameEventTypeEnabled() {
return get(NewRelicProperties::isMeterNameEventTypeEnabled, NewRelicConfig.super::meterNameEventTypeEnabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public SignalFxPropertiesConfigAdapter(SignalFxProperties properties) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public SimplePropertiesConfigAdapter(SimpleProperties properties) {
super(properties);
}

@Override
public String prefix() {
return "management.metrics.export.simple";
}

@Override
public String get(String k) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public StackdriverPropertiesConfigAdapter(StackdriverProperties properties) {
super(properties);
}

@Override
public String prefix() {
return "management.metrics.export.stackdriver";
}

@Override
public String projectId() {
return get(StackdriverProperties::getProjectId, StackdriverConfig.super::projectId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public String get(String s) {
return null;
}

@Override
public String prefix() {
return "management.metrics.export.statsd";
}

@Override
public StatsdFlavor flavor() {
return get(StatsdProperties::getFlavor, StatsdConfig.super::flavor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public WavefrontPropertiesConfigAdapter(WavefrontProperties properties) {
super(properties);
}

@Override
public String prefix() {
return "management.metrics.export.wavefront";
}

@Override
public String get(String k) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
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;
Expand All @@ -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"
Expand All @@ -57,11 +61,11 @@ private Exception createFailure(Class<?> configuration) {
}

@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);
}

}
Expand Down