|
|
@ -17,15 +17,16 @@
|
|
|
|
package org.springframework.boot.actuate.autoconfigure.metrics.export.newrelic;
|
|
|
|
package org.springframework.boot.actuate.autoconfigure.metrics.export.newrelic;
|
|
|
|
|
|
|
|
|
|
|
|
import io.micrometer.core.instrument.Clock;
|
|
|
|
import io.micrometer.core.instrument.Clock;
|
|
|
|
|
|
|
|
import io.micrometer.influx.InfluxMeterRegistry;
|
|
|
|
import io.micrometer.newrelic.NewRelicConfig;
|
|
|
|
import io.micrometer.newrelic.NewRelicConfig;
|
|
|
|
import io.micrometer.newrelic.NewRelicMeterRegistry;
|
|
|
|
import io.micrometer.newrelic.NewRelicMeterRegistry;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
@ -39,29 +40,31 @@ public class NewRelicMetricsExportAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
private final ApplicationContextRunner runner = new ApplicationContextRunner()
|
|
|
|
private final ApplicationContextRunner runner = new ApplicationContextRunner()
|
|
|
|
.withConfiguration(
|
|
|
|
.withConfiguration(
|
|
|
|
AutoConfigurations.of(NewRelicMetricsExportAutoConfiguration.class,
|
|
|
|
AutoConfigurations.of(NewRelicMetricsExportAutoConfiguration.class));
|
|
|
|
MetricsAutoConfiguration.class));
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void backsOffWithoutAClock() {
|
|
|
|
|
|
|
|
this.runner.run((context) -> assertThat(context)
|
|
|
|
|
|
|
|
.doesNotHaveBean(InfluxMeterRegistry.class));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void failsWithoutAnApiKey() {
|
|
|
|
public void failsWithoutAnApiKey() {
|
|
|
|
this.runner
|
|
|
|
this.runner.withUserConfiguration(BaseConfiguration.class)
|
|
|
|
.withPropertyValues("management.metrics.export.newrelic.account-id=12345")
|
|
|
|
.withPropertyValues("management.metrics.export.newrelic.account-id=12345")
|
|
|
|
.run((context) -> assertThat(context).hasFailed());
|
|
|
|
.run((context) -> assertThat(context).hasFailed());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void failsWithoutAnAccountId() {
|
|
|
|
public void failsWithoutAnAccountId() {
|
|
|
|
this.runner
|
|
|
|
this.runner.withUserConfiguration(BaseConfiguration.class)
|
|
|
|
.withConfiguration(AutoConfigurations.of(
|
|
|
|
|
|
|
|
NewRelicMetricsExportAutoConfiguration.class,
|
|
|
|
|
|
|
|
MetricsAutoConfiguration.class))
|
|
|
|
|
|
|
|
.withPropertyValues("management.metrics.export.newrelic.api-key=abcde")
|
|
|
|
.withPropertyValues("management.metrics.export.newrelic.api-key=abcde")
|
|
|
|
.run((context) -> assertThat(context).hasFailed());
|
|
|
|
.run((context) -> assertThat(context).hasFailed());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void autoConfiguresWithAccountIdAndApiKey() {
|
|
|
|
public void autoConfiguresWithAccountIdAndApiKey() {
|
|
|
|
this.runner
|
|
|
|
this.runner.withUserConfiguration(BaseConfiguration.class)
|
|
|
|
.withPropertyValues("management.metrics.export.newrelic.api-key=abcde",
|
|
|
|
.withPropertyValues("management.metrics.export.newrelic.api-key=abcde",
|
|
|
|
"management.metrics.export.newrelic.account-id=12345")
|
|
|
|
"management.metrics.export.newrelic.account-id=12345")
|
|
|
|
.run((context) -> assertThat(context)
|
|
|
|
.run((context) -> assertThat(context)
|
|
|
@ -71,7 +74,7 @@ public class NewRelicMetricsExportAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void autoConfigurationCanBeDisabled() {
|
|
|
|
public void autoConfigurationCanBeDisabled() {
|
|
|
|
this.runner
|
|
|
|
this.runner.withUserConfiguration(BaseConfiguration.class)
|
|
|
|
.withPropertyValues("management.metrics.export.newrelic.enabled=false",
|
|
|
|
.withPropertyValues("management.metrics.export.newrelic.enabled=false",
|
|
|
|
"management.metrics.export.newrelic.api-key=abcde",
|
|
|
|
"management.metrics.export.newrelic.api-key=abcde",
|
|
|
|
"management.metrics.export.newrelic.account-id=12345")
|
|
|
|
"management.metrics.export.newrelic.account-id=12345")
|
|
|
@ -80,15 +83,6 @@ public class NewRelicMetricsExportAutoConfigurationTests {
|
|
|
|
.doesNotHaveBean(NewRelicConfig.class));
|
|
|
|
.doesNotHaveBean(NewRelicConfig.class));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void allowsClockToBeCustomized() {
|
|
|
|
|
|
|
|
this.runner.withUserConfiguration(CustomClockConfiguration.class)
|
|
|
|
|
|
|
|
.withPropertyValues("management.metrics.export.newrelic.api-key=abcde",
|
|
|
|
|
|
|
|
"management.metrics.export.newrelic.account-id=12345")
|
|
|
|
|
|
|
|
.run((context) -> assertThat(context).hasSingleBean(Clock.class)
|
|
|
|
|
|
|
|
.hasBean("customClock"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void allowsConfigToBeCustomized() {
|
|
|
|
public void allowsConfigToBeCustomized() {
|
|
|
|
this.runner.withUserConfiguration(CustomConfigConfiguration.class)
|
|
|
|
this.runner.withUserConfiguration(CustomConfigConfiguration.class)
|
|
|
@ -109,7 +103,7 @@ public class NewRelicMetricsExportAutoConfigurationTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
static class CustomClockConfiguration {
|
|
|
|
static class BaseConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
public Clock customClock() {
|
|
|
|
public Clock customClock() {
|
|
|
@ -119,6 +113,7 @@ public class NewRelicMetricsExportAutoConfigurationTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
|
|
|
|
@Import(BaseConfiguration.class)
|
|
|
|
static class CustomConfigConfiguration {
|
|
|
|
static class CustomConfigConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
@ -142,6 +137,7 @@ public class NewRelicMetricsExportAutoConfigurationTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
|
|
|
|
@Import(BaseConfiguration.class)
|
|
|
|
static class CustomRegistryConfiguration {
|
|
|
|
static class CustomRegistryConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|