@ -26,10 +26,12 @@ import org.springframework.boot.actuate.autoconfigure.web.server.ManagementConte
@@ -26,10 +26,12 @@ import org.springframework.boot.actuate.autoconfigure.web.server.ManagementConte
import org.springframework.boot.actuate.metrics.export.prometheus.PrometheusPushGatewayManager ;
import org.springframework.boot.actuate.metrics.export.prometheus.PrometheusScrapeEndpoint ;
import org.springframework.boot.autoconfigure.AutoConfigurations ;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext ;
import org.springframework.boot.test.context.runner.ApplicationContextRunner ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.context.annotation.Import ;
import org.springframework.test.util.ReflectionTestUtils ;
import static org.assertj.core.api.Assertions.assertThat ;
@ -151,8 +153,29 @@ public class PrometheusMetricsExportAutoConfigurationTests {
@@ -151,8 +153,29 @@ public class PrometheusMetricsExportAutoConfigurationTests {
. withPropertyValues (
"management.metrics.export.prometheus.pushgateway.enabled=true" )
. withUserConfiguration ( BaseConfiguration . class )
. run ( ( context ) - > assertThat ( context )
. hasSingleBean ( PrometheusPushGatewayManager . class ) ) ;
. run ( ( context ) - > hasGatewayURL ( context ,
"http://localhost:9091/metrics/job/" ) ) ;
}
@Test
public void withCustomPushGatewayURL ( ) {
this . contextRunner
. withConfiguration (
AutoConfigurations . of ( ManagementContextAutoConfiguration . class ) )
. withPropertyValues (
"management.metrics.export.prometheus.pushgateway.enabled=true" ,
"management.metrics.export.prometheus.pushgateway.base-url=https://localhost:8080/push" )
. withUserConfiguration ( BaseConfiguration . class )
. run ( ( context ) - > hasGatewayURL ( context ,
"https://localhost:8080/push/metrics/job/" ) ) ;
}
private void hasGatewayURL ( AssertableApplicationContext context , String url ) {
assertThat ( context ) . hasSingleBean ( PrometheusPushGatewayManager . class ) ;
PrometheusPushGatewayManager gatewayManager = context
. getBean ( PrometheusPushGatewayManager . class ) ;
Object pushGateway = ReflectionTestUtils . getField ( gatewayManager , "pushGateway" ) ;
assertThat ( pushGateway ) . hasFieldOrPropertyWithValue ( "gatewayBaseURL" , url ) ;
}
@Configuration ( proxyBeanMethods = false )