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 Jul 18, 2024
1 parent 1f69d1d commit 20135bd
Show file tree
Hide file tree
Showing 6 changed files with 4,740 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,10 @@
import java.util.Optional;
import java.util.Set;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
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 +21,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() {
Config runtimeConfig = ConfigProvider.getConfig();
String rootPath = runtimeConfig.getOptionalValue("quarkus.management.root-path", String.class).orElse("/q");
String metricsPath = runtimeConfig.getOptionalValue("quarkus.management.metrics.path", String.class).orElse("/metrics");
int httpPort = runtimeConfig.getOptionalValue("quarkus.http.port", Integer.class).orElse(0);
PrometheusYamlFile prometheusYamlFile = new PrometheusYamlFile(config.serviceName(), rootPath, metricsPath,
"host.docker.internal", httpPort);
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 20135bd

Please sign in to comment.