Skip to content

Commit

Permalink
Fix #40933: LGTM Quarkus Dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Jun 17, 2024
1 parent 6d2456b commit c5e4654
Show file tree
Hide file tree
Showing 6 changed files with 4,738 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public final class ContainerConstants {

// Images

public static final String LGTM = "docker.io/grafana/otel-lgtm:0.4.0";
public static final String LGTM = "docker.io/grafana/otel-lgtm:0.6.0";

// Ports

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.Optional;
import java.util.Set;

import org.testcontainers.utility.MountableFile;

import io.quarkus.observability.common.ContainerConstants;
import io.quarkus.observability.common.config.AbstractGrafanaConfig;
import io.quarkus.observability.common.config.LgtmConfig;
Expand All @@ -17,12 +19,30 @@ public LgtmContainer() {
public LgtmContainer(LgtmConfig config) {
super(config);
addExposedPorts(config.otlpPort());
withCopyFileToContainer(
MountableFile.forClasspathResource("/grafana-dashboard-quarkus-metrics.json"),
"/otel-lgtm/grafana-dashboard-jvm-metrics.json");
withCopyFileToContainer(
MountableFile.forClasspathResource("/grafana-dashboards.yaml"),
"/otel-lgtm/grafana-dashboards.yaml");
addFileToContainer(getPrometheusConfig().getBytes(), "/otel-lgtm/prometheus.yaml");

}

public int getOtlpPort() {
return getMappedPort(config.otlpPort());
}

private String getPrometheusConfig() {
// TODO: these need to be replaced with quarkus application.properties values
// quarkus.management.root-path = "/q"
// quarkus.management.metrics.path = "/metrics"
// quarkus.http.port = 8080
PrometheusYamlFile prometheusYamlFile = new PrometheusYamlFile(config.serviceName(), "/q", "/metrics",
"host.docker.internal", 8080);
return prometheusYamlFile.createPrometheusYamlFile();
}

protected static class LgtmConfigImpl extends AbstractGrafanaConfig implements LgtmConfig {
public LgtmConfigImpl() {
this(ContainerConstants.LGTM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected byte[] getResourceAsBytes(String resource) {
@SuppressWarnings("OctalInteger")
protected void addFileToContainer(byte[] content, String pathInContainer) {
logger().info("Content [{}]: \n{}", pathInContainer, new String(content, StandardCharsets.UTF_8));
copyFileToContainer(Transferable.of(content, 0777), pathInContainer);
withCopyToContainer(Transferable.of(content, 0777), pathInContainer);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package io.quarkus.observability.testcontainers;

public class PrometheusYamlFile {

protected static final String PROMETHEUS_CONFIG = """
global:
scrape_interval: 10s
evaluation_interval: 10s
storage:
tsdb:
out_of_order_time_window: 10m
scrape_configs:
- job_name: '%s'
metrics_path: '%s%s'
scrape_interval: 10s
static_configs:
- targets: ['%s:%d']
""";

private String serviceName;
private String rootPath;
private String metricsPath;
private String host;
private int port;

public PrometheusYamlFile(String serviceName, String rootPath, String metricsPath, String host, int port) {
this.serviceName = serviceName;
this.rootPath = rootPath;
this.metricsPath = metricsPath;
this.host = host;
this.port = port;
}

public String createPrometheusYamlFile() {
return String.format(PROMETHEUS_CONFIG, getServiceName(), getRootPath(), getMetricsPath(), getHost(),
getPort());
}

public String getServiceName() {
return serviceName;
}

public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}

public String getRootPath() {
return rootPath;
}

public void setRootPath(String rootPath) {
this.rootPath = rootPath;
}

public String getMetricsPath() {
return metricsPath;
}

public void setMetricsPath(String metricsPath) {
this.metricsPath = metricsPath;
}

public String getHost() {
return host;
}

public void setHost(String host) {
this.host = host;
}

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}

}
Loading

0 comments on commit c5e4654

Please sign in to comment.