Skip to content

Commit

Permalink
Add prometheus tio actuator-webflux sample
Browse files Browse the repository at this point in the history
See gh-86
  • Loading branch information
mhalbritter committed Aug 10, 2022
1 parent 3b80aae commit 7980166
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions actuator-webflux/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation(project(":aot-smoke-test-third-party-hints"))

runtimeOnly("io.micrometer:micrometer-registry-prometheus")

testImplementation("org.springframework.boot:spring-boot-starter-test")

aotTestImplementation(project(":aot-smoke-test-support"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.springframework.aot.smoketest.support.junit.AotSmokeTest;
import org.springframework.test.web.reactive.server.WebTestClient;

import static org.assertj.core.api.Assertions.assertThat;

@AotSmokeTest
class ActuatorWebFluxApplicationAotTests {

Expand Down Expand Up @@ -45,4 +47,15 @@ void shouldHaveOsInfoProperties(WebTestClient client) {
.isNotEmpty();
}

@Test
void prometheusWorks(WebTestClient client) {
client.get().uri("/actuator/prometheus").exchange().expectStatus().isOk().expectBody()
.consumeWith((result) -> assertThat(new String(result.getResponseBodyContent()))
// Check custom timer
.contains("custom_timer_seconds_max 5.0").contains("custom_timer_seconds_count 1.0")
.contains("custom_timer_seconds_sum 5.0")
// Check JVM metric
.contains("# TYPE jvm_threads_peak_threads gauge"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.actuator.webflux;

import java.time.Duration;

import io.micrometer.core.instrument.MeterRegistry;

import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
class RegisterCustomTimer implements CommandLineRunner {

private final MeterRegistry meterRegistry;

RegisterCustomTimer(MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;
}

@Override
public void run(String... args) {
this.meterRegistry.timer("custom.timer").record(Duration.ofSeconds(5));
}

}

0 comments on commit 7980166

Please sign in to comment.