diff --git a/monitoring/micrometer-prometheus-kafka/src/test/java/io/quarkus/ts/micrometer/prometheus/kafka/BaseOpenShiftAlertEventsIT.java b/monitoring/micrometer-prometheus-kafka/src/test/java/io/quarkus/ts/micrometer/prometheus/kafka/BaseOpenShiftAlertEventsIT.java index e0ef09450..fdc23db61 100644 --- a/monitoring/micrometer-prometheus-kafka/src/test/java/io/quarkus/ts/micrometer/prometheus/kafka/BaseOpenShiftAlertEventsIT.java +++ b/monitoring/micrometer-prometheus-kafka/src/test/java/io/quarkus/ts/micrometer/prometheus/kafka/BaseOpenShiftAlertEventsIT.java @@ -4,12 +4,16 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.io.IOException; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.function.Predicate; +import java.util.stream.Collectors; import javax.inject.Inject; import javax.ws.rs.client.ClientBuilder; @@ -23,6 +27,7 @@ import io.quarkus.test.bootstrap.RestService; import io.quarkus.test.bootstrap.Service; import io.quarkus.test.bootstrap.inject.OpenShiftClient; +import io.quarkus.test.utils.Command; public abstract class BaseOpenShiftAlertEventsIT { @@ -85,7 +90,7 @@ private void thenKafkaConsumerMetricsAreFound() throws Exception { private void thenMetricIsExposedInPrometheus(String name, Predicate valueMatcher) throws Exception { await().ignoreExceptions().atMost(ASSERT_PROMETHEUS_TIMEOUT_MINUTES, TimeUnit.MINUTES).untilAsserted(() -> { - String output = client.execOnPod(PROMETHEUS_NAMESPACE, PROMETHEUS_POD, PROMETHEUS_CONTAINER, "curl", + String output = execOnPod(PROMETHEUS_NAMESPACE, PROMETHEUS_POD, PROMETHEUS_CONTAINER, "curl", "http://localhost:9090/api/v1/query?query=" + name); assertTrue(output.contains("\"status\":\"success\""), "Verify the status was ok"); @@ -126,6 +131,19 @@ private Double extractValueFromMetric(String line) { return Double.parseDouble(line.substring(line.lastIndexOf(" "))); } + // TODO: Will be fixed once either https://github.com/fabric8io/kubernetes-client/issues/3473 is fixed + // or when releasing test framework to 0.0.12. + private String execOnPod(String prometheusNamespace, String prometheusPod, String prometheusContainer, String... input) + throws IOException, InterruptedException { + List output = new ArrayList<>(); + List args = new ArrayList<>(); + args.addAll(Arrays.asList("oc", "exec", prometheusPod, "-c", prometheusContainer, "-n", prometheusNamespace)); + args.addAll(Arrays.asList(input)); + new Command(args).outputToLines(output).runAndWait(); + + return output.stream().collect(Collectors.joining(System.lineSeparator())); + } + protected static void loadServiceMonitor(Service app) { client.apply(Paths.get("target/test-classes/service-monitor.yaml")); } diff --git a/monitoring/micrometer-prometheus/src/test/java/io/quarkus/ts/micrometer/prometheus/OpenShiftPrimeNumberResourceIT.java b/monitoring/micrometer-prometheus/src/test/java/io/quarkus/ts/micrometer/prometheus/OpenShiftPrimeNumberResourceIT.java index 0c2572a3a..b4be6cd1e 100644 --- a/monitoring/micrometer-prometheus/src/test/java/io/quarkus/ts/micrometer/prometheus/OpenShiftPrimeNumberResourceIT.java +++ b/monitoring/micrometer-prometheus/src/test/java/io/quarkus/ts/micrometer/prometheus/OpenShiftPrimeNumberResourceIT.java @@ -4,8 +4,13 @@ import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.io.IOException; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; import javax.inject.Inject; @@ -19,6 +24,7 @@ import io.quarkus.test.scenarios.OpenShiftDeploymentStrategy; import io.quarkus.test.scenarios.OpenShiftScenario; import io.quarkus.test.services.QuarkusApplication; +import io.quarkus.test.utils.Command; /** * The application contains a `PrimeNumberResource` resource that generates a few metrics: @@ -79,7 +85,7 @@ private void whenCheckPrimeNumber(int number) { private void thenMetricIsExposedInPrometheus(String name, Integer expected) throws Exception { await().ignoreExceptions().atMost(ASSERT_PROMETHEUS_TIMEOUT_MINUTES, TimeUnit.MINUTES).untilAsserted(() -> { - String output = client.execOnPod(PROMETHEUS_NAMESPACE, PROMETHEUS_POD, PROMETHEUS_CONTAINER, "curl", + String output = execOnPod(PROMETHEUS_NAMESPACE, PROMETHEUS_POD, PROMETHEUS_CONTAINER, "curl", "http://localhost:9090/api/v1/query?query=" + primeNumberCustomMetricName(name)); assertTrue(output.contains("\"status\":\"success\""), "Verify the status was ok"); @@ -109,6 +115,19 @@ private String primeNumberCustomMetricName(String metricName) { return String.format(metricName, uniqueId); } + // TODO: Will be fixed once either https://github.com/fabric8io/kubernetes-client/issues/3473 is fixed + // or when releasing test framework to 0.0.12. + private String execOnPod(String prometheusNamespace, String prometheusPod, String prometheusContainer, String... input) + throws IOException, InterruptedException { + List output = new ArrayList<>(); + List args = new ArrayList<>(); + args.addAll(Arrays.asList("oc", "exec", prometheusPod, "-c", prometheusContainer, "-n", prometheusNamespace)); + args.addAll(Arrays.asList(input)); + new Command(args).outputToLines(output).runAndWait(); + + return output.stream().collect(Collectors.joining(System.lineSeparator())); + } + private static void loadServiceMonitor(Service app) { client.apply(Paths.get("target/test-classes/service-monitor.yaml")); }