From cf07e5a766cdb148f80bbacfb3eac6de3654e33b Mon Sep 17 00:00:00 2001 From: Fiete Ostkamp Date: Wed, 4 Sep 2024 16:06:07 +0200 Subject: Enable prometheus metrics in model-loader - add micrometer-registry-prometheus dependency - update vulnerable dependencies Issue-ID: AAI-3983 Change-Id: I9377ee4a1d1f77ca2811d3b954814374a2b2774e Signed-off-by: Fiete Ostkamp --- pom.xml | 28 ++++++++------ src/main/resources/application.properties | 2 + .../aai/modelloader/actuator/ActuatorTest.java | 45 +++++++++++++++------- version.properties | 2 +- 4 files changed, 51 insertions(+), 26 deletions(-) diff --git a/pom.xml b/pom.xml index 2574071..26d276e 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ org.onap.aai.model-loader model-loader aai-model-loader - 1.14.1-SNAPSHOT + 1.14.2-SNAPSHOT @@ -60,10 +60,11 @@ ${basedir}/target 2.7.18 2021.0.8 + 2.9.13 1.10.0 - 1.22 + 1.27.0 + 2.16.1 2.10.1 - 1.3 1.13.0 2.0.0 1.2.11 @@ -238,6 +239,11 @@ + + org.springframework.boot + spring-boot-starter-webflux + test + org.springframework.boot spring-boot-starter-aop @@ -246,14 +252,20 @@ org.springframework.boot spring-boot-starter-actuator - + + + io.micrometer + micrometer-registry-prometheus + org.springframework.kafka spring-kafka + ${spring-kafka.version} org.springframework.kafka spring-kafka-test + ${spring-kafka.version} test @@ -313,7 +325,7 @@ commons-io commons-io - 2.11.0 + ${commons-io.version} org.apache.commons @@ -334,12 +346,6 @@ - - org.hamcrest - hamcrest-all - ${hamcrest-all.version} - test - org.junit.jupiter junit-jupiter diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index d3b4f45..ab5186a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -29,3 +29,5 @@ server.tomcat.threads.min-spare=25 # Spring Boot logging logging.config=${logback.configurationFile} + +management.endpoints.web.exposure.include=* diff --git a/src/test/java/org/onap/aai/modelloader/actuator/ActuatorTest.java b/src/test/java/org/onap/aai/modelloader/actuator/ActuatorTest.java index e9a6da5..2ccbb0c 100644 --- a/src/test/java/org/onap/aai/modelloader/actuator/ActuatorTest.java +++ b/src/test/java/org/onap/aai/modelloader/actuator/ActuatorTest.java @@ -19,29 +19,46 @@ */ package org.onap.aai.modelloader.actuator; -import static org.junit.jupiter.api.Assertions.assertEquals; - import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.server.LocalServerPort; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.client.RestTemplate; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.web.reactive.server.WebTestClient; +@AutoConfigureWebTestClient +@TestPropertySource(properties = { + "management.endpoints.web.exposure.include=prometheus,metrics,info,health" +}) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class ActuatorTest { - - @Autowired RestTemplate restTemplate; - @LocalServerPort - private int serverPort; + + @Autowired + private WebTestClient webTestClient; @Test public void thatLivenessEndpointReturnsOk() { - String url = String.format("http://localhost:%s/actuator/health", serverPort); - ResponseEntity entity = restTemplate.getForEntity(url, String.class); - assertEquals(entity.getStatusCode(), HttpStatus.OK); - assertEquals(entity.getBody(), "{\"status\":\"UP\"}"); + webTestClient.get().uri("/actuator/health") + .exchange() + .expectStatus().isOk() + .expectBody() + .jsonPath("$.status") + .isEqualTo("UP"); } + + // @Test + // public void testPrometheusEndpoint() { + // webTestClient.get().uri("/actuator/prometheus") + // .exchange() + // .expectStatus().isOk() + // .expectHeader().contentType("text/plain; charset=utf-8") + // .expectBody(String.class) + // .consumeWith(response -> { + // String responseBody = response.getResponseBody(); + // assert responseBody != null; + // assert responseBody.contains("# HELP"); + // assert responseBody.contains("# TYPE"); + // }); + // } } diff --git a/version.properties b/version.properties index 5cd0baf..44f7d2f 100644 --- a/version.properties +++ b/version.properties @@ -25,7 +25,7 @@ major=1 minor=14 -patch=1 +patch=2 base_version=${major}.${minor}.${patch} -- cgit 1.2.3-korg