From 6cef6c275ed6dcc5422434882fb95df630740551 Mon Sep 17 00:00:00 2001 From: Yuya Ebihara Date: Tue, 25 Jan 2022 15:37:09 +0900 Subject: [PATCH 1/2] Allow setting extra properties in Prometheus query runner Additionally, set http-server.http.port as 8080 in the main method. --- .../io/trino/plugin/prometheus/PrometheusQueryRunner.java | 6 +++--- .../plugin/prometheus/TestPrometheusIntegrationStatus.java | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/plugin/trino-prometheus/src/test/java/io/trino/plugin/prometheus/PrometheusQueryRunner.java b/plugin/trino-prometheus/src/test/java/io/trino/plugin/prometheus/PrometheusQueryRunner.java index 7477e3f81830..f5a22df13d03 100644 --- a/plugin/trino-prometheus/src/test/java/io/trino/plugin/prometheus/PrometheusQueryRunner.java +++ b/plugin/trino-prometheus/src/test/java/io/trino/plugin/prometheus/PrometheusQueryRunner.java @@ -33,12 +33,12 @@ public final class PrometheusQueryRunner { private PrometheusQueryRunner() {} - public static DistributedQueryRunner createPrometheusQueryRunner(PrometheusServer server) + public static DistributedQueryRunner createPrometheusQueryRunner(PrometheusServer server, Map extraProperties) throws Exception { DistributedQueryRunner queryRunner = null; try { - queryRunner = DistributedQueryRunner.builder(createSession()).build(); + queryRunner = DistributedQueryRunner.builder(createSession()).setExtraProperties(extraProperties).build(); queryRunner.installPlugin(new PrometheusPlugin()); Map properties = ImmutableMap.of( @@ -75,7 +75,7 @@ public static void main(String[] args) throws Exception { Logging.initialize(); - DistributedQueryRunner queryRunner = createPrometheusQueryRunner(new PrometheusServer()); + DistributedQueryRunner queryRunner = createPrometheusQueryRunner(new PrometheusServer(), ImmutableMap.of("http-server.http.port", "8080")); Thread.sleep(10); Logger log = Logger.get(PrometheusQueryRunner.class); log.info("======== SERVER STARTED ========"); diff --git a/plugin/trino-prometheus/src/test/java/io/trino/plugin/prometheus/TestPrometheusIntegrationStatus.java b/plugin/trino-prometheus/src/test/java/io/trino/plugin/prometheus/TestPrometheusIntegrationStatus.java index f6625457f5ef..36ce6597cb4e 100644 --- a/plugin/trino-prometheus/src/test/java/io/trino/plugin/prometheus/TestPrometheusIntegrationStatus.java +++ b/plugin/trino-prometheus/src/test/java/io/trino/plugin/prometheus/TestPrometheusIntegrationStatus.java @@ -13,6 +13,7 @@ */ package io.trino.plugin.prometheus; +import com.google.common.collect.ImmutableMap; import io.airlift.log.Logger; import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.MaterializedResult; @@ -43,7 +44,7 @@ protected QueryRunner createQueryRunner() throws Exception { this.server = new PrometheusServer(); - return createPrometheusQueryRunner(server); + return createPrometheusQueryRunner(server, ImmutableMap.of()); } @Test From a4ab2696facd882bcad7d67dd706114f751a4d4c Mon Sep 17 00:00:00 2001 From: Yuya Ebihara Date: Tue, 25 Jan 2022 14:42:48 +0900 Subject: [PATCH 2/2] Tweak assertion in TestPrometheusIntegrationStatus.testPushDown The interval might be shorter than 15s, so it returns 1 or 2 row. --- .../plugin/prometheus/TestPrometheusIntegrationStatus.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin/trino-prometheus/src/test/java/io/trino/plugin/prometheus/TestPrometheusIntegrationStatus.java b/plugin/trino-prometheus/src/test/java/io/trino/plugin/prometheus/TestPrometheusIntegrationStatus.java index 36ce6597cb4e..3d5c886f8447 100644 --- a/plugin/trino-prometheus/src/test/java/io/trino/plugin/prometheus/TestPrometheusIntegrationStatus.java +++ b/plugin/trino-prometheus/src/test/java/io/trino/plugin/prometheus/TestPrometheusIntegrationStatus.java @@ -27,6 +27,7 @@ import java.util.concurrent.TimeUnit; import static io.trino.plugin.prometheus.PrometheusQueryRunner.createPrometheusQueryRunner; +import static org.assertj.core.api.Assertions.assertThat; import static org.testng.Assert.assertEquals; import static org.testng.Assert.fail; @@ -101,8 +102,8 @@ public void testConfirmMetricAvailableAndCheckUp() @Test public void testPushDown() { - // default interval on the `up` metric that Prometheus records on itself is 15 seconds, so this should only yield one row + // default interval on the `up` metric that Prometheus records on itself is about 15 seconds, so this should only yield one or two row MaterializedResult results = computeActual("SELECT * FROM prometheus.default.up WHERE timestamp > (NOW() - INTERVAL '15' SECOND)"); - assertEquals(results.getRowCount(), 1); + assertThat(results).hasSizeBetween(1, 2); } }