Skip to content

Commit 3a7dba0

Browse files
eddumelendezkiview
andauthored
Add grafana module (#8851)
Add Grafana Otel LGTM container implementation. Expose ports for Grafana (3000), OTLP GRPC (4317), OTLP HTTP (4318) and Prometheus (9090). Also, utility methods to get URLs. Co-authored-by: Kevin Wittek <[email protected]>
1 parent bd919df commit 3a7dba0

File tree

12 files changed

+223
-0
lines changed

12 files changed

+223
-0
lines changed

.github/ISSUE_TEMPLATE/bug_report.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ body:
2727
- Dynalite
2828
- Elasticsearch
2929
- GCloud
30+
- Grafana
3031
- HiveMQ
3132
- InfluxDB
3233
- K3S

.github/ISSUE_TEMPLATE/enhancement.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ body:
2727
- Dynalite
2828
- Elasticsearch
2929
- GCloud
30+
- Grafana
3031
- HiveMQ
3132
- InfluxDB
3233
- K3S

.github/ISSUE_TEMPLATE/feature.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ body:
2727
- Dynalite
2828
- Elasticsearch
2929
- GCloud
30+
- Grafana
3031
- HiveMQ
3132
- InfluxDB
3233
- K3S

.github/dependabot.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ updates:
106106
schedule:
107107
interval: "weekly"
108108
open-pull-requests-limit: 10
109+
- package-ecosystem: "gradle"
110+
directory: "/modules/grafana"
111+
schedule:
112+
interval: "weekly"
113+
open-pull-requests-limit: 10
109114
- package-ecosystem: "gradle"
110115
directory: "/modules/hivemq"
111116
schedule:

.github/labeler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
- changed-files:
6868
- any-glob-to-any-file:
6969
- modules/gcloud/**/*
70+
"modules/grafana":
71+
- changed-files:
72+
- any-glob-to-any-file:
73+
- modules/grafana/**/*
7074
"modules/hivemq":
7175
- changed-files:
7276
- any-glob-to-any-file:

.github/settings.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ labels:
145145
- name: modules/gcloud
146146
color: '#006b75'
147147

148+
- name: modules/grafana
149+
color: '#006b75'
150+
148151
- name: modules/hivemq
149152
color: '#006b75'
150153

docs/modules/grafana.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Grafana
2+
3+
Testcontainers module for [Grafana OTel LGTM](https://hub.docker.com/r/grafana/otel-lgtm).
4+
5+
## LGTM's usage examples
6+
7+
You can start a Grafana OTel LGTM container instance from any Java application by using:
8+
9+
<!--codeinclude-->
10+
[Grafana Otel LGTM container](../../modules/grafana/src/test/java/org/testcontainers/grafana/LgtmStackContainerTest.java) inside_block:container
11+
<!--/codeinclude-->
12+
13+
Add the following dependency to your `pom.xml`/`build.gradle` file:
14+
15+
=== "Gradle"
16+
```groovy
17+
testImplementation "org.testcontainers:grafana:{{latest_version}}"
18+
```
19+
20+
=== "Maven"
21+
```xml
22+
<dependency>
23+
<groupId>org.testcontainers</groupId>
24+
<artifactId>grafana</artifactId>
25+
<version>{{latest_version}}</version>
26+
<scope>test</scope>
27+
</dependency>
28+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ nav:
8181
- modules/docker_compose.md
8282
- modules/elasticsearch.md
8383
- modules/gcloud.md
84+
- modules/grafana.md
8485
- modules/hivemq.md
8586
- modules/k3s.md
8687
- modules/k6.md

modules/grafana/build.gradle

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
description = "Testcontainers :: Grafana"
2+
3+
dependencies {
4+
api project(':testcontainers')
5+
6+
testImplementation 'org.assertj:assertj-core:3.25.3'
7+
testImplementation 'io.rest-assured:rest-assured:5.4.0'
8+
testImplementation 'io.micrometer:micrometer-registry-otlp:1.13.1'
9+
testImplementation 'uk.org.webcompere:system-stubs-junit4:2.1.6'
10+
}
11+
12+
test {
13+
javaLauncher = javaToolchains.launcherFor {
14+
languageVersion = JavaLanguageVersion.of(11)
15+
}
16+
}
17+
18+
compileTestJava {
19+
javaCompiler = javaToolchains.compilerFor {
20+
languageVersion = JavaLanguageVersion.of(11)
21+
}
22+
options.release.set(11)
23+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)