|
| 1 | +package org.testcontainers.grafana; |
| 2 | + |
| 3 | +import com.github.dockerjava.api.command.InspectContainerResponse; |
| 4 | +import lombok.extern.slf4j.Slf4j; |
| 5 | +import org.testcontainers.containers.GenericContainer; |
| 6 | +import org.testcontainers.containers.wait.strategy.Wait; |
| 7 | +import org.testcontainers.utility.DockerImageName; |
| 8 | + |
| 9 | +/** |
| 10 | + * Testcontainers implementation for Grafana OTel LGTM. |
| 11 | + * <p> |
| 12 | + * Supported image: {@code grafana/otel-lgtm} |
| 13 | + * <p> |
| 14 | + * Exposed ports: |
| 15 | + * <ul> |
| 16 | + * <li>Grafana: 3000</li> |
| 17 | + * <li>OTel Http: 4317</li> |
| 18 | + * <li>OTel Grpc: 4318</li> |
| 19 | + * <li>Prometheus: 9090</li> |
| 20 | + * </ul> |
| 21 | + */ |
| 22 | +@Slf4j |
| 23 | +public class LgtmStackContainer extends GenericContainer<LgtmStackContainer> { |
| 24 | + |
| 25 | + private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("grafana/otel-lgtm"); |
| 26 | + |
| 27 | + private static final int GRAFANA_PORT = 3000; |
| 28 | + |
| 29 | + private static final int OTLP_GRPC_PORT = 4317; |
| 30 | + |
| 31 | + private static final int OTLP_HTTP_PORT = 4318; |
| 32 | + |
| 33 | + private static final int PROMETHEUS_PORT = 9090; |
| 34 | + |
| 35 | + public LgtmStackContainer(String image) { |
| 36 | + this(DockerImageName.parse(image)); |
| 37 | + } |
| 38 | + |
| 39 | + public LgtmStackContainer(DockerImageName image) { |
| 40 | + super(image); |
| 41 | + image.assertCompatibleWith(DEFAULT_IMAGE_NAME); |
| 42 | + withExposedPorts(GRAFANA_PORT, OTLP_GRPC_PORT, OTLP_HTTP_PORT, PROMETHEUS_PORT); |
| 43 | + waitingFor( |
| 44 | + Wait.forLogMessage(".*The OpenTelemetry collector and the Grafana LGTM stack are up and running.*\\s", 1) |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + protected void containerIsStarted(InspectContainerResponse containerInfo) { |
| 50 | + log.info("Access to the Grafana dashboard: {}", getOtlpHttpUrl()); |
| 51 | + } |
| 52 | + |
| 53 | + public String getOtlpGrpcUrl() { |
| 54 | + return "http://" + getHost() + ":" + getMappedPort(OTLP_GRPC_PORT); |
| 55 | + } |
| 56 | + |
| 57 | + public String getOtlpHttpUrl() { |
| 58 | + return "http://" + getHost() + ":" + getMappedPort(OTLP_HTTP_PORT); |
| 59 | + } |
| 60 | + |
| 61 | + public String getPromehteusHttpUrl() { |
| 62 | + return "http://" + getHost() + ":" + getMappedPort(PROMETHEUS_PORT); |
| 63 | + } |
| 64 | +} |
0 commit comments