Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to the Grafana LGTM dashboards I #45620

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.7.5";
public static final String LGTM = "docker.io/grafana/otel-lgtm:0.8.2";

// Ports

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,57 @@ 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']
---
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() {
Expand All @@ -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");

}
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the 0 do that -- helps set the default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that 0 is the default and should mean some random port, however, in devmode, the default port is 8080.
Unless the property is set by the user, the port ended up being set to 0 in the scraper, leading to no data collection. An insidious bug.


return String.format(PROMETHEUS_CONFIG, config.serviceName(), rootPath, metricsPath, "host.docker.internal", httpPort);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading