diff --git a/boot-grafana-lgtm/docker/docker-compose.yml b/boot-grafana-lgtm/docker/docker-compose.yml index 7020dd54b..2d09b16ad 100644 --- a/boot-grafana-lgtm/docker/docker-compose.yml +++ b/boot-grafana-lgtm/docker/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3.8' services: grafanalgtm: @@ -11,19 +10,6 @@ services: - "3000:3000" - "4317:4317" - "4318:4318" - - prometheus: - image: prom/prometheus:v3.0.1 - extra_hosts: ['host.docker.internal:host-gateway'] - container_name: prometheus - command: - - --enable-feature=exemplar-storage - - --config.file=/etc/prometheus/prometheus.yml + - "9090:9090" volumes: - ../config/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro - ports: - - "9090:9090" - healthcheck: - interval: 5s - retries: 10 - test: wget --no-verbose --tries=1 --spider http://localhost:9090/status || exit 1 \ No newline at end of file diff --git a/boot-grafana-lgtm/src/test/java/com/learning/grafanalgtm/GrafanaLGTMApplicationTest.java b/boot-grafana-lgtm/src/test/java/com/learning/grafanalgtm/GrafanaLGTMApplicationTest.java index ffa181f13..d9da3b790 100644 --- a/boot-grafana-lgtm/src/test/java/com/learning/grafanalgtm/GrafanaLGTMApplicationTest.java +++ b/boot-grafana-lgtm/src/test/java/com/learning/grafanalgtm/GrafanaLGTMApplicationTest.java @@ -5,6 +5,7 @@ import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.is; +import com.learning.grafanalgtm.common.ContainerConfig; import io.restassured.RestAssured; import io.restassured.authentication.PreemptiveBasicAuthScheme; import io.restassured.http.ContentType; @@ -19,7 +20,7 @@ import org.testcontainers.grafana.LgtmStackContainer; @SpringBootTest( - classes = {TestGrafanaLGTMApplication.class}, + classes = {ContainerConfig.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @TestInstance(TestInstance.Lifecycle.PER_CLASS) class GrafanaLGTMApplicationTest { @@ -61,6 +62,22 @@ void prometheus() { .body("data.result", empty()); } + @Test + void queryPrometheus() { + // calling endpoint to load metrics + when().get("/greetings").then().statusCode(HttpStatus.SC_OK); + + RestAssured.port = lgtmContainer.getMappedPort(9090); + given().contentType(ContentType.URLENC) + .body("query=up") + .when() + .post("/api/v1/query") + .then() + .statusCode(HttpStatus.SC_OK) + .contentType(ContentType.JSON) + .body("status", is("success")); + } + @Test void tempoQuery() { // calling endpoint to load metrics diff --git a/boot-grafana-lgtm/src/test/java/com/learning/grafanalgtm/TestGrafanaLGTMApplication.java b/boot-grafana-lgtm/src/test/java/com/learning/grafanalgtm/TestGrafanaLGTMApplication.java index 3a8d9af08..f489c0a91 100644 --- a/boot-grafana-lgtm/src/test/java/com/learning/grafanalgtm/TestGrafanaLGTMApplication.java +++ b/boot-grafana-lgtm/src/test/java/com/learning/grafanalgtm/TestGrafanaLGTMApplication.java @@ -1,26 +1,13 @@ package com.learning.grafanalgtm; -import java.time.Duration; +import com.learning.grafanalgtm.common.ContainerConfig; import org.springframework.boot.SpringApplication; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.boot.testcontainers.service.connection.ServiceConnection; -import org.springframework.context.annotation.Bean; -import org.testcontainers.grafana.LgtmStackContainer; -import org.testcontainers.utility.DockerImageName; -@TestConfiguration(proxyBeanMethods = false) public class TestGrafanaLGTMApplication { public static void main(String[] args) { SpringApplication.from(GrafanaLGTMApplication::main) - .with(TestGrafanaLGTMApplication.class) + .with(ContainerConfig.class) .run(args); } - - @Bean - @ServiceConnection - LgtmStackContainer lgtmContainer() { - return new LgtmStackContainer(DockerImageName.parse("grafana/otel-lgtm:0.7.8")) - .withStartupTimeout(Duration.ofMinutes(2)); - } } diff --git a/boot-grafana-lgtm/src/test/java/com/learning/grafanalgtm/common/ContainerConfig.java b/boot-grafana-lgtm/src/test/java/com/learning/grafanalgtm/common/ContainerConfig.java new file mode 100644 index 000000000..df23a8b47 --- /dev/null +++ b/boot-grafana-lgtm/src/test/java/com/learning/grafanalgtm/common/ContainerConfig.java @@ -0,0 +1,19 @@ +package com.learning.grafanalgtm.common; + +import java.time.Duration; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.testcontainers.service.connection.ServiceConnection; +import org.springframework.context.annotation.Bean; +import org.testcontainers.grafana.LgtmStackContainer; +import org.testcontainers.utility.DockerImageName; + +@TestConfiguration(proxyBeanMethods = false) +public class ContainerConfig { + + @Bean + @ServiceConnection + LgtmStackContainer lgtmContainer() { + return new LgtmStackContainer(DockerImageName.parse("grafana/otel-lgtm:0.8.1")) + .withStartupTimeout(Duration.ofMinutes(2)); + } +}