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 committed Aug 20, 2024
1 parent 2ac0a6d commit 1b6fca0
Show file tree
Hide file tree
Showing 5 changed files with 4,675 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,26 +3,62 @@
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;

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());
}

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);

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 1b6fca0

Please sign in to comment.