Skip to content

Commit

Permalink
Fix wait strategy usage, Grafana should not know about LGTM
Browse files Browse the repository at this point in the history
  • Loading branch information
alesj committed Jan 21, 2025
1 parent 625a0e2 commit 449b87c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package io.quarkus.observability.testcontainers;

import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.containers.wait.strategy.WaitAllStrategy;
import org.testcontainers.containers.wait.strategy.WaitStrategy;

import io.quarkus.observability.common.config.GrafanaConfig;

@SuppressWarnings("resource")
public abstract class GrafanaContainer<T extends GrafanaContainer<T, C>, C extends GrafanaConfig>
extends ObservabilityContainer<T, C> {
protected static final String DATASOURCES_PATH = "/etc/grafana/provisioning/datasources/custom.yaml";

protected C config;

Expand All @@ -19,23 +17,17 @@ public GrafanaContainer(C config) {
withEnv("GF_SECURITY_ADMIN_USER", config.username());
withEnv("GF_SECURITY_ADMIN_PASSWORD", config.password());
addExposedPort(config.grafanaPort());
waitingFor(grafanaWaitStrategy());
waitingFor(waitStrategy());
}

public int getGrafanaPort() {
return getMappedPort(config.grafanaPort());
}

private WaitStrategy grafanaWaitStrategy() {
return new WaitAllStrategy()
.withStartupTimeout(config.timeout())
.withStrategy(
Wait.forHttp("/")
.forPort(config.grafanaPort())
.forStatusCode(200)
.withStartupTimeout(config.timeout()))
.withStrategy(
Wait.forLogMessage(".*The OpenTelemetry collector and the Grafana LGTM stack are up and running.*", 1)
.withStartupTimeout(config.timeout()));
protected WaitStrategy waitStrategy() {
return Wait.forHttp("/")
.forPort(config.grafanaPort())
.forStatusCode(200)
.withStartupTimeout(config.timeout());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.testcontainers.containers.output.OutputFrame;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.containers.wait.strategy.WaitAllStrategy;
import org.testcontainers.containers.wait.strategy.WaitStrategy;
import org.testcontainers.utility.MountableFile;

import io.quarkus.observability.common.ContainerConstants;
Expand Down Expand Up @@ -92,6 +95,16 @@ public LgtmContainer(LgtmConfig config) {

}

@Override
protected WaitStrategy waitStrategy() {
return new WaitAllStrategy()
.withStartupTimeout(config.timeout())
.withStrategy(super.waitStrategy())
.withStrategy(
Wait.forLogMessage(".*The OpenTelemetry collector and the Grafana LGTM stack are up and running.*", 1)
.withStartupTimeout(config.timeout()));
}

@Override
protected String prefix() {
return "LGTM";
Expand Down

0 comments on commit 449b87c

Please sign in to comment.