Skip to content

Commit

Permalink
Fix quarkusio#40933: LGTM Quarkus Dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored and mskacelik committed Oct 2, 2024
1 parent 8bb909f commit 60b2939
Show file tree
Hide file tree
Showing 5 changed files with 4,665 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,7 +3,10 @@
import java.util.Optional;
import java.util.Set;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;
import org.testcontainers.utility.MountableFile;

import io.quarkus.observability.common.ContainerConstants;
import io.quarkus.observability.common.config.AbstractGrafanaConfig;
Expand All @@ -17,6 +20,21 @@ public class LgtmContainer extends GrafanaContainer<LgtmContainer, LgtmConfig> {

protected static final String LGTM_NETWORK_ALIAS = "ltgm.testcontainer.docker";

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']
""";

public LgtmContainer() {
this(new LgtmConfigImpl());
}
Expand All @@ -25,12 +43,29 @@ public LgtmContainer(LgtmConfig config) {
super(config);
addExposedPorts(config.otlpPort());
withLogConsumer(new LgtmContainerLogConsumer(log).withPrefix("LGTM"));
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);

return String.format(PROMETHEUS_CONFIG, config.serviceName(), rootPath, metricsPath, "host.docker.internal", httpPort);
}

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
Loading

0 comments on commit 60b2939

Please sign in to comment.