Merge pull request #18472 from neiljpowell
* pr/18472: Polish 'Support 'New Relic' eventType properties' Support 'New Relic' eventType properties Closes gh-18472
This commit is contained in:
@@ -26,11 +26,26 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
* @author Jon Schneider
|
||||
* @author Andy Wilkinson
|
||||
* @author Stephane Nicoll
|
||||
* @author Neil Powell
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "management.metrics.export.newrelic")
|
||||
public class NewRelicProperties extends StepRegistryProperties {
|
||||
|
||||
/**
|
||||
* Whether to send the meter name as the event type instead of using the 'event-type'
|
||||
* configuration property value. Can be set to 'true' if New Relic guidelines are not
|
||||
* being followed or event types consistent with previous Spring Boot releases are
|
||||
* required.
|
||||
*/
|
||||
private boolean meterNameEventTypeEnabled;
|
||||
|
||||
/**
|
||||
* The event type that should be published. This property will be ignored if
|
||||
* 'meter-name-event-type-enabled' is set to 'true'.
|
||||
*/
|
||||
private String eventType = "SpringBootSample";
|
||||
|
||||
/**
|
||||
* New Relic API key.
|
||||
*/
|
||||
@@ -46,6 +61,22 @@ public class NewRelicProperties extends StepRegistryProperties {
|
||||
*/
|
||||
private String uri = "https://insights-collector.newrelic.com";
|
||||
|
||||
public boolean isMeterNameEventTypeEnabled() {
|
||||
return this.meterNameEventTypeEnabled;
|
||||
}
|
||||
|
||||
public void setMeterNameEventTypeEnabled(boolean meterNameEventTypeEnabled) {
|
||||
this.meterNameEventTypeEnabled = meterNameEventTypeEnabled;
|
||||
}
|
||||
|
||||
public String getEventType() {
|
||||
return this.eventType;
|
||||
}
|
||||
|
||||
public void setEventType(String eventType) {
|
||||
this.eventType = eventType;
|
||||
}
|
||||
|
||||
public String getApiKey() {
|
||||
return this.apiKey;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.
|
||||
* Adapter to convert {@link NewRelicProperties} to a {@link NewRelicConfig}.
|
||||
*
|
||||
* @author Jon Schneider
|
||||
* @author Neil Powell
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public class NewRelicPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<NewRelicProperties>
|
||||
@@ -33,6 +34,16 @@ public class NewRelicPropertiesConfigAdapter extends StepRegistryPropertiesConfi
|
||||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean meterNameEventTypeEnabled() {
|
||||
return get(NewRelicProperties::isMeterNameEventTypeEnabled, NewRelicConfig.super::meterNameEventTypeEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String eventType() {
|
||||
return get(NewRelicProperties::getEventType, NewRelicConfig.super::eventType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiKey() {
|
||||
return get(NewRelicProperties::getApiKey, NewRelicConfig.super::apiKey);
|
||||
|
||||
@@ -59,6 +59,36 @@ class NewRelicMetricsExportAutoConfigurationTests {
|
||||
.run((context) -> assertThat(context).hasFailed());
|
||||
}
|
||||
|
||||
@Test
|
||||
void failsToAutoConfigureWithoutEventType() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.newrelic.api-key=abcde",
|
||||
"management.metrics.export.newrelic.account-id=12345",
|
||||
"management.metrics.export.newrelic.event-type=")
|
||||
.run((context) -> assertThat(context).hasFailed());
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfiguresWithEventTypeOverriden() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.newrelic.api-key=abcde",
|
||||
"management.metrics.export.newrelic.account-id=12345",
|
||||
"management.metrics.export.newrelic.event-type=wxyz")
|
||||
.run((context) -> assertThat(context).hasSingleBean(NewRelicMeterRegistry.class)
|
||||
.hasSingleBean(Clock.class).hasSingleBean(NewRelicConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfiguresWithMeterNameEventTypeEnabledAndWithoutEventType() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
.withPropertyValues("management.metrics.export.newrelic.api-key=abcde",
|
||||
"management.metrics.export.newrelic.account-id=12345",
|
||||
"management.metrics.export.newrelic.event-type=",
|
||||
"management.metrics.export.newrelic.meter-name-event-type-enabled=true")
|
||||
.run((context) -> assertThat(context).hasSingleBean(NewRelicMeterRegistry.class)
|
||||
.hasSingleBean(Clock.class).hasSingleBean(NewRelicConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfiguresWithAccountIdAndApiKey() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
|
||||
@@ -37,6 +37,16 @@ class NewRelicPropertiesTests extends StepRegistryPropertiesTests {
|
||||
assertStepRegistryDefaultValues(properties, config);
|
||||
// apiKey and account are mandatory
|
||||
assertThat(properties.getUri()).isEqualTo(config.uri());
|
||||
assertThat(properties.isMeterNameEventTypeEnabled()).isEqualTo(config.meterNameEventTypeEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void eventTypeDefaultValueIsOverriden() {
|
||||
NewRelicProperties properties = new NewRelicProperties();
|
||||
NewRelicConfig config = (key) -> null;
|
||||
assertThat(properties.getEventType()).isNotEqualTo(config.eventType());
|
||||
assertThat(properties.getEventType()).isEqualTo("SpringBootSample");
|
||||
assertThat(config.eventType()).isEqualTo("MicrometerSample");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user