Skip to content

Polish gh-40023 #41208

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
wants to merge 1 commit into from
Closed
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
@@ -22,8 +22,6 @@
import java.util.Map;

import io.micrometer.core.instrument.Clock;
import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.exemplars.DefaultExemplarSampler;
import io.prometheus.client.exemplars.ExemplarSampler;
@@ -69,14 +67,14 @@
before = { CompositeMeterRegistryAutoConfiguration.class, SimpleMetricsExportAutoConfiguration.class },
after = { MetricsAutoConfiguration.class, PrometheusMetricsExportAutoConfiguration.class })
@ConditionalOnBean(Clock.class)
@ConditionalOnClass(PrometheusMeterRegistry.class)
@ConditionalOnClass(io.micrometer.prometheus.PrometheusMeterRegistry.class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for that change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhalbritter I just wanted to align with the fully qualified return type of the simpleclientPrometheusMeterRegistry() below and remove the import statement for the PrometheusMeterRegistry that has been deprecated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah so you switched to fully qualified types to get rid of the deprecated imports.

@ConditionalOnEnabledMetricsExport("prometheus")
@EnableConfigurationProperties(PrometheusProperties.class)
public class PrometheusSimpleclientMetricsExportAutoConfiguration {

@Bean
@ConditionalOnMissingBean
PrometheusConfig simpleclientPrometheusConfig(PrometheusProperties prometheusProperties) {
io.micrometer.prometheus.PrometheusConfig simpleclientPrometheusConfig(PrometheusProperties prometheusProperties) {
return new PrometheusSimpleclientPropertiesConfigAdapter(prometheusProperties);
}

Original file line number Diff line number Diff line change
@@ -192,8 +192,8 @@ void scrapeEndpointNotAddedToManagementContextWhenNotExposed() {
@Test
void scrapeEndpointCanBeDisabled() {
this.contextRunner.withConfiguration(AutoConfigurations.of(ManagementContextAutoConfiguration.class))
.withPropertyValues("management.endpoints.web.exposure.include=prometheus")
.withPropertyValues("management.endpoint.prometheus.enabled=false")
.withPropertyValues("management.endpoints.web.exposure.include=prometheus",
"management.endpoint.prometheus.enabled=false")
.withUserConfiguration(BaseConfiguration.class)
.run((context) -> assertThat(context).doesNotHaveBean(PrometheusSimpleclientScrapeEndpoint.class)
.doesNotHaveBean(PrometheusScrapeEndpoint.class));
Original file line number Diff line number Diff line change
@@ -138,8 +138,8 @@ void scrapeEndpointNotAddedToManagementContextWhenNotExposed() {
@Test
void scrapeEndpointCanBeDisabled() {
this.contextRunner.withConfiguration(AutoConfigurations.of(ManagementContextAutoConfiguration.class))
.withPropertyValues("management.endpoints.web.exposure.include=prometheus")
.withPropertyValues("management.endpoint.prometheus.enabled=false")
.withPropertyValues("management.endpoints.web.exposure.include=prometheus",
"management.endpoint.prometheus.enabled=false")
.withUserConfiguration(BaseConfiguration.class)
.run((context) -> assertThat(context).doesNotHaveBean(PrometheusScrapeEndpoint.class));
}
Original file line number Diff line number Diff line change
@@ -165,8 +165,8 @@ void scrapeEndpointNotAddedToManagementContextWhenNotExposed() {
@Test
void scrapeEndpointCanBeDisabled() {
this.contextRunner.withConfiguration(AutoConfigurations.of(ManagementContextAutoConfiguration.class))
.withPropertyValues("management.endpoints.web.exposure.include=prometheus")
.withPropertyValues("management.endpoint.prometheus.enabled=false")
.withPropertyValues("management.endpoints.web.exposure.include=prometheus",
"management.endpoint.prometheus.enabled=false")
.withUserConfiguration(BaseConfiguration.class)
.run((context) -> assertThat(context).doesNotHaveBean(PrometheusSimpleclientScrapeEndpoint.class));
}
Original file line number Diff line number Diff line change
@@ -62,21 +62,21 @@ public Tracer getIfUnique() throws BeansException {

};

private final LazyTracingSpanContext spanContextSupplier = new LazyTracingSpanContext(this.objectProvider);
private final LazyTracingSpanContext spanContext = new LazyTracingSpanContext(this.objectProvider);

@Test
void whenCurrentSpanIsNullThenSpanIdIsNull() {
assertThat(this.spanContextSupplier.getCurrentSpanId()).isNull();
assertThat(this.spanContext.getCurrentSpanId()).isNull();
}

@Test
void whenCurrentSpanIsNullThenTraceIdIsNull() {
assertThat(this.spanContextSupplier.getCurrentTraceId()).isNull();
assertThat(this.spanContext.getCurrentTraceId()).isNull();
}

@Test
void whenCurrentSpanIsNullThenSampledIsFalse() {
assertThat(this.spanContextSupplier.isCurrentSpanSampled()).isFalse();
assertThat(this.spanContext.isCurrentSpanSampled()).isFalse();
}

@Test
@@ -86,7 +86,7 @@ void whenCurrentSpanHasSpanIdThenSpanIdIsFromSpan() {
TraceContext traceContext = mock(TraceContext.class);
given(traceContext.spanId()).willReturn("span-id");
given(span.context()).willReturn(traceContext);
assertThat(this.spanContextSupplier.getCurrentSpanId()).isEqualTo("span-id");
assertThat(this.spanContext.getCurrentSpanId()).isEqualTo("span-id");
}

@Test
@@ -96,7 +96,7 @@ void whenCurrentSpanHasTraceIdThenTraceIdIsFromSpan() {
TraceContext traceContext = mock(TraceContext.class);
given(traceContext.traceId()).willReturn("trace-id");
given(span.context()).willReturn(traceContext);
assertThat(this.spanContextSupplier.getCurrentTraceId()).isEqualTo("trace-id");
assertThat(this.spanContext.getCurrentTraceId()).isEqualTo("trace-id");
}

@Test
@@ -105,7 +105,7 @@ void whenCurrentSpanHasNoSpanIdThenSpanIdIsNull() {
given(this.tracer.currentSpan()).willReturn(span);
TraceContext traceContext = mock(TraceContext.class);
given(span.context()).willReturn(traceContext);
assertThat(this.spanContextSupplier.getCurrentSpanId()).isNull();
assertThat(this.spanContext.getCurrentSpanId()).isNull();
}

@Test
@@ -114,7 +114,7 @@ void whenCurrentSpanHasNoTraceIdThenTraceIdIsNull() {
given(this.tracer.currentSpan()).willReturn(span);
TraceContext traceContext = mock(TraceContext.class);
given(span.context()).willReturn(traceContext);
assertThat(this.spanContextSupplier.getCurrentTraceId()).isNull();
assertThat(this.spanContext.getCurrentTraceId()).isNull();
}

@Test
@@ -124,7 +124,7 @@ void whenCurrentSpanIsSampledThenSampledIsTrue() {
TraceContext traceContext = mock(TraceContext.class);
given(traceContext.sampled()).willReturn(true);
given(span.context()).willReturn(traceContext);
assertThat(this.spanContextSupplier.isCurrentSpanSampled()).isTrue();
assertThat(this.spanContext.isCurrentSpanSampled()).isTrue();
}

@Test
@@ -134,7 +134,7 @@ void whenCurrentSpanIsNotSampledThenSampledIsFalse() {
TraceContext traceContext = mock(TraceContext.class);
given(traceContext.sampled()).willReturn(false);
given(span.context()).willReturn(traceContext);
assertThat(this.spanContextSupplier.isCurrentSpanSampled()).isFalse();
assertThat(this.spanContext.isCurrentSpanSampled()).isFalse();
}

@Test
@@ -144,7 +144,7 @@ void whenCurrentSpanHasDeferredSamplingThenSampledIsFalse() {
TraceContext traceContext = mock(TraceContext.class);
given(traceContext.sampled()).willReturn(null);
given(span.context()).willReturn(traceContext);
assertThat(this.spanContextSupplier.isCurrentSpanSampled()).isFalse();
assertThat(this.spanContext.isCurrentSpanSampled()).isFalse();
}

}
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@ void shouldSupplyCustomBeans() {
this.contextRunner.withUserConfiguration(CustomConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(SpanContext.class)
.getBean(SpanContext.class)
.isSameAs(CustomConfiguration.SUPPLIER));
.isSameAs(CustomConfiguration.SPAN_CONTEXT));
}

@Test
@@ -145,11 +145,11 @@ void prometheusOpenMetricsOutputShouldContainExemplars() {
@Configuration(proxyBeanMethods = false)
private static final class CustomConfiguration {

static final SpanContext SUPPLIER = mock(SpanContext.class);
static final SpanContext SPAN_CONTEXT = mock(SpanContext.class);

@Bean
SpanContext customSpanContext() {
return SUPPLIER;
return SPAN_CONTEXT;
}

}
Original file line number Diff line number Diff line change
@@ -47,20 +47,14 @@ class SecondCustomPrometheusScrapeEndpointIntegrationTests {

@WebEndpointTest
void scrapeHasContentTypeText004ByDefault(WebTestClient client) {
scrapeHasContentTypeText004ByDefault(client, "/actuator/prometheus");
scrapeHasContentTypeText004ByDefault(client, "/actuator/prometheussc");
}

private void scrapeHasContentTypeText004ByDefault(WebTestClient client, String uri) {
String expectedContentType = PrometheusTextFormatWriter.CONTENT_TYPE;
client.get()
.uri("/actuator/prometheus")
.exchange()
.expectStatus()
.isOk()
.expectHeader()
.contentType(MediaType.parseMediaType(expectedContentType))
.expectBody(String.class)
.value((body) -> assertThat(body).contains("counter1_total")
.contains("counter2_total")
.contains("counter3_total"));
client.get()
.uri("/actuator/prometheussc")
.uri(uri)
.exchange()
.expectStatus()
.isOk()
@@ -74,22 +68,16 @@ void scrapeHasContentTypeText004ByDefault(WebTestClient client) {

@WebEndpointTest
void scrapeHasContentTypeText004ByDefaultWhenClientAcceptsWildcardWithParameter(WebTestClient client) {
scrapeHasContentTypeText004ByDefaultWhenClientAcceptsWildcardWithParameter(client, "/actuator/prometheus");
scrapeHasContentTypeText004ByDefaultWhenClientAcceptsWildcardWithParameter(client, "/actuator/prometheussc");
}

private void scrapeHasContentTypeText004ByDefaultWhenClientAcceptsWildcardWithParameter(WebTestClient client,
String uri) {
String expectedContentType = PrometheusTextFormatWriter.CONTENT_TYPE;
String accept = "*/*;q=0.8";
client.get()
.uri("/actuator/prometheus")
.accept(MediaType.parseMediaType(accept))
.exchange()
.expectStatus()
.isOk()
.expectHeader()
.contentType(MediaType.parseMediaType(expectedContentType))
.expectBody(String.class)
.value((body) -> assertThat(body).contains("counter1_total")
.contains("counter2_total")
.contains("counter3_total"));
client.get()
.uri("/actuator/prometheussc")
.uri(uri)
.accept(MediaType.parseMediaType(accept))
.exchange()
.expectStatus()
@@ -104,21 +92,14 @@ void scrapeHasContentTypeText004ByDefaultWhenClientAcceptsWildcardWithParameter(

@WebEndpointTest
void scrapeCanProduceOpenMetrics100(WebTestClient client) {
scrapeCanProduceOpenMetrics100(client, "/actuator/prometheus");
scrapeCanProduceOpenMetrics100(client, "/actuator/prometheussc");
}

private void scrapeCanProduceOpenMetrics100(WebTestClient client, String uri) {
MediaType openMetrics = MediaType.parseMediaType(OpenMetricsTextFormatWriter.CONTENT_TYPE);
client.get()
.uri("/actuator/prometheus")
.accept(openMetrics)
.exchange()
.expectStatus()
.isOk()
.expectHeader()
.contentType(openMetrics)
.expectBody(String.class)
.value((body) -> assertThat(body).contains("counter1_total")
.contains("counter2_total")
.contains("counter3_total"));
client.get()
.uri("/actuator/prometheussc")
.uri(uri)
.accept(openMetrics)
.exchange()
.expectStatus()
@@ -133,18 +114,15 @@ void scrapeCanProduceOpenMetrics100(WebTestClient client) {

@WebEndpointTest
void scrapePrefersToProduceOpenMetrics100(WebTestClient client) {
scrapePrefersToProduceOpenMetrics100(client, "/actuator/prometheus");
scrapePrefersToProduceOpenMetrics100(client, "/actuator/prometheussc");
}

private void scrapePrefersToProduceOpenMetrics100(WebTestClient client, String uri) {
MediaType openMetrics = MediaType.parseMediaType(OpenMetricsTextFormatWriter.CONTENT_TYPE);
MediaType textPlain = MediaType.parseMediaType(PrometheusTextFormatWriter.CONTENT_TYPE);
client.get()
.uri("/actuator/prometheus")
.accept(openMetrics, textPlain)
.exchange()
.expectStatus()
.isOk()
.expectHeader()
.contentType(openMetrics);
client.get()
.uri("/actuator/prometheussc")
.uri(uri)
.accept(openMetrics, textPlain)
.exchange()
.expectStatus()
@@ -155,19 +133,13 @@ void scrapePrefersToProduceOpenMetrics100(WebTestClient client) {

@WebEndpointTest
void scrapeWithIncludedNames(WebTestClient client) {
scrapeWithIncludedNames(client, "/actuator/prometheus?includedNames=counter1,counter2");
scrapeWithIncludedNames(client, "/actuator/prometheussc?includedNames=counter1_total,counter2_total");
}

private void scrapeWithIncludedNames(WebTestClient client, String uri) {
client.get()
.uri("/actuator/prometheus?includedNames=counter1,counter2")
.exchange()
.expectStatus()
.isOk()
.expectHeader()
.contentType(MediaType.parseMediaType(PrometheusTextFormatWriter.CONTENT_TYPE))
.expectBody(String.class)
.value((body) -> assertThat(body).contains("counter1_total")
.contains("counter2_total")
.doesNotContain("counter3_total"));
client.get()
.uri("/actuator/prometheussc?includedNames=counter1_total,counter2_total")
.uri(uri)
.exchange()
.expectStatus()
.isOk()
4 changes: 2 additions & 2 deletions spring-boot-project/spring-boot-dependencies/build.gradle
Original file line number Diff line number Diff line change
@@ -1508,12 +1508,12 @@ bom {
library("Prometheus Client", "1.2.1") {
group("io.prometheus") {
imports = [
"prometheus-metrics-bom"
"prometheus-metrics-bom"
]
}
links {
site("https://github.com/prometheus/client_java")
releaseNotes("https://github.com/prometheus/client_java/releases/tag/parent-{version}")
releaseNotes("https://github.com/prometheus/client_java/releases/tag/v{version}")
}
}
library("Prometheus Simpleclient", "0.16.0") {