|
26 | 26 | import org.springframework.boot.actuate.metrics.export.prometheus.PrometheusPushGatewayManager;
|
27 | 27 | import org.springframework.boot.actuate.metrics.export.prometheus.PrometheusScrapeEndpoint;
|
28 | 28 | import org.springframework.boot.autoconfigure.AutoConfigurations;
|
| 29 | +import org.springframework.boot.test.context.assertj.AssertableApplicationContext; |
29 | 30 | import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
30 | 31 | import org.springframework.context.annotation.Bean;
|
31 | 32 | import org.springframework.context.annotation.Configuration;
|
32 | 33 | import org.springframework.context.annotation.Import;
|
| 34 | +import org.springframework.test.util.ReflectionTestUtils; |
33 | 35 |
|
34 | 36 | import static org.assertj.core.api.Assertions.assertThat;
|
35 | 37 |
|
@@ -151,8 +153,29 @@ public void withPushGatewayEnabled() {
|
151 | 153 | .withPropertyValues(
|
152 | 154 | "management.metrics.export.prometheus.pushgateway.enabled=true")
|
153 | 155 | .withUserConfiguration(BaseConfiguration.class)
|
154 |
| - .run((context) -> assertThat(context) |
155 |
| - .hasSingleBean(PrometheusPushGatewayManager.class)); |
| 156 | + .run((context) -> hasGatewayURL(context, |
| 157 | + "http://localhost:9091/metrics/job/")); |
| 158 | + } |
| 159 | + |
| 160 | + @Test |
| 161 | + public void withCustomPushGatewayURL() { |
| 162 | + this.contextRunner |
| 163 | + .withConfiguration( |
| 164 | + AutoConfigurations.of(ManagementContextAutoConfiguration.class)) |
| 165 | + .withPropertyValues( |
| 166 | + "management.metrics.export.prometheus.pushgateway.enabled=true", |
| 167 | + "management.metrics.export.prometheus.pushgateway.base-url=https://localhost:8080/push") |
| 168 | + .withUserConfiguration(BaseConfiguration.class) |
| 169 | + .run((context) -> hasGatewayURL(context, |
| 170 | + "https://localhost:8080/push/metrics/job/")); |
| 171 | + } |
| 172 | + |
| 173 | + private void hasGatewayURL(AssertableApplicationContext context, String url) { |
| 174 | + assertThat(context).hasSingleBean(PrometheusPushGatewayManager.class); |
| 175 | + PrometheusPushGatewayManager gatewayManager = context |
| 176 | + .getBean(PrometheusPushGatewayManager.class); |
| 177 | + Object pushGateway = ReflectionTestUtils.getField(gatewayManager, "pushGateway"); |
| 178 | + assertThat(pushGateway).hasFieldOrPropertyWithValue("gatewayBaseURL", url); |
156 | 179 | }
|
157 | 180 |
|
158 | 181 | @Configuration(proxyBeanMethods = false)
|
|
0 commit comments