Skip to content

Commit

Permalink
adds testcase and polish
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Dec 19, 2024
1 parent 1c95019 commit 18d9b46
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 31 deletions.
16 changes: 1 addition & 15 deletions boot-grafana-lgtm/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.8'
services:

grafanalgtm:
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit 18d9b46

Please sign in to comment.