From 9acf79d64ffb9512f094d2bade82e1a8f84026b4 Mon Sep 17 00:00:00 2001 From: brunobat Date: Wed, 15 Jan 2025 17:37:21 +0000 Subject: [PATCH] Update grafana image and remove dashboard hack --- .../common/ContainerConstants.java | 2 +- .../testcontainers/LgtmContainer.java | 79 ++++++++++++++----- .../ObservabilityContainer.java | 2 +- 3 files changed, 60 insertions(+), 23 deletions(-) diff --git a/extensions/observability-devservices/common/src/main/java/io/quarkus/observability/common/ContainerConstants.java b/extensions/observability-devservices/common/src/main/java/io/quarkus/observability/common/ContainerConstants.java index bb50ac4513475..55576ccd82b1e 100644 --- a/extensions/observability-devservices/common/src/main/java/io/quarkus/observability/common/ContainerConstants.java +++ b/extensions/observability-devservices/common/src/main/java/io/quarkus/observability/common/ContainerConstants.java @@ -4,7 +4,7 @@ public final class ContainerConstants { // Images - public static final String LGTM = "docker.io/grafana/otel-lgtm:0.7.5"; + public static final String LGTM = "docker.io/grafana/otel-lgtm:0.8.2"; // Ports diff --git a/extensions/observability-devservices/testcontainers/src/main/java/io/quarkus/observability/testcontainers/LgtmContainer.java b/extensions/observability-devservices/testcontainers/src/main/java/io/quarkus/observability/testcontainers/LgtmContainer.java index 89992c23f8102..1f9fdc301c3a0 100644 --- a/extensions/observability-devservices/testcontainers/src/main/java/io/quarkus/observability/testcontainers/LgtmContainer.java +++ b/extensions/observability-devservices/testcontainers/src/main/java/io/quarkus/observability/testcontainers/LgtmContainer.java @@ -15,18 +15,57 @@ public class LgtmContainer extends GrafanaContainer { 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'] + --- + otlp: + # Recommended attributes to be promoted to labels. + promote_resource_attributes: + - service.instance.id + - service.name + - service.namespace + - service.version + - cloud.availability_zone + - cloud.region + - container.name + - deployment.environment.name + - k8s.cluster.name + - k8s.container.name + - k8s.cronjob.name + - k8s.daemonset.name + - k8s.deployment.name + - k8s.job.name + - k8s.namespace.name + - k8s.pod.name + - k8s.replicaset.name + - k8s.statefulset.name + storage: + tsdb: + # A 10min time window is enough because it can easily absorb retries and network delays. + out_of_order_time_window: 10m + global: + scrape_interval: 5s + evaluation_interval: 5s + scrape_configs: + - job_name: '%s' + metrics_path: '%s%s' + scrape_interval: 5s + static_configs: + - targets: ['%s:%d'] + """; + + protected static final String DASHBOARDS_CONFIG = """ + apiVersion: 1 + + providers: + - name: "Quarkus Micrometer Prometheus" + type: file + options: + path: /otel-lgtm/grafana-dashboard-quarkus-micrometer-prometheus.json + foldersFromFilesStructure: false + - name: "Quarkus Micrometer with OTLP output" + type: file + options: + path: /otel-lgtm/grafana-dashboard-quarkus-micrometer-otlp.json + foldersFromFilesStructure: false """; public LgtmContainer() { @@ -37,18 +76,16 @@ public LgtmContainer(LgtmConfig config) { super(config); // always expose both -- since the LGTM image already does that as well addExposedPorts(ContainerConstants.OTEL_GRPC_EXPORTER_PORT, ContainerConstants.OTEL_HTTP_EXPORTER_PORT); - // cannot override grafana-dashboards.yaml in the container because it's on a version dependent path: - // ./grafana-v11.0.0/conf/provisioning/dashboards/grafana-dashboards.yaml - // will replace contents of current dashboards + + // Replacing bundled dashboards with our own + addFileToContainer(DASHBOARDS_CONFIG.getBytes(), + "/otel-lgtm/grafana/conf/provisioning/dashboards/grafana-dashboards.yaml"); withCopyFileToContainer( MountableFile.forClasspathResource("/grafana-dashboard-quarkus-micrometer-prometheus.json"), - "/otel-lgtm/grafana-dashboard-red-metrics-classic.json"); + "/otel-lgtm/grafana-dashboard-quarkus-micrometer-prometheus.json"); withCopyFileToContainer( MountableFile.forClasspathResource("/grafana-dashboard-quarkus-micrometer-otlp.json"), - "/otel-lgtm/grafana-dashboard-red-metrics-native.json"); - withCopyFileToContainer( - MountableFile.forClasspathResource("/empty.json"), - "/otel-lgtm/grafana-dashboard-jvm-metrics.json"); + "/otel-lgtm/grafana-dashboard-quarkus-micrometer-otlp.json"); addFileToContainer(getPrometheusConfig().getBytes(), "/otel-lgtm/prometheus.yaml"); } @@ -82,7 +119,7 @@ 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); + int httpPort = runtimeConfig.getOptionalValue("quarkus.http.port", Integer.class).orElse(8080); // when not set use default return String.format(PROMETHEUS_CONFIG, config.serviceName(), rootPath, metricsPath, "host.docker.internal", httpPort); } diff --git a/extensions/observability-devservices/testcontainers/src/main/java/io/quarkus/observability/testcontainers/ObservabilityContainer.java b/extensions/observability-devservices/testcontainers/src/main/java/io/quarkus/observability/testcontainers/ObservabilityContainer.java index f47f85c98fd43..a3e6c6610890f 100644 --- a/extensions/observability-devservices/testcontainers/src/main/java/io/quarkus/observability/testcontainers/ObservabilityContainer.java +++ b/extensions/observability-devservices/testcontainers/src/main/java/io/quarkus/observability/testcontainers/ObservabilityContainer.java @@ -51,7 +51,7 @@ protected byte[] getResourceAsBytes(String resource) { @SuppressWarnings("OctalInteger") protected void addFileToContainer(byte[] content, String pathInContainer) { - log.infof("Content [%s]: \n%s", pathInContainer, new String(content, StandardCharsets.UTF_8)); + log.debugf("Content [%s]: \n%s", pathInContainer, new String(content, StandardCharsets.UTF_8)); withCopyToContainer(Transferable.of(content, 0777), pathInContainer); }