Skip to content

Commit 12cbfa6

Browse files
committed
Add product test for Loki connector
1 parent 26d7413 commit 12cbfa6

File tree

9 files changed

+177
-1
lines changed

9 files changed

+177
-1
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ jobs:
923923
- suite-parquet
924924
- suite-oauth2
925925
- suite-ldap
926+
- suite-loki
926927
- suite-compatibility
927928
- suite-all-connectors-smoke
928929
- suite-delta-lake-oss

plugin/trino-loki/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
<dependency>
5454
<groupId>io.github.jeschkies</groupId>
5555
<artifactId>loki-client</artifactId>
56-
<version>0.0.5</version>
5756
</dependency>
5857

5958
<dependency>

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,12 @@
788788
<version>4.2.37</version>
789789
</dependency>
790790

791+
<dependency>
792+
<groupId>io.github.jeschkies</groupId>
793+
<artifactId>loki-client</artifactId>
794+
<version>0.0.5</version>
795+
</dependency>
796+
791797
<dependency>
792798
<groupId>io.jsonwebtoken</groupId>
793799
<artifactId>jjwt-api</artifactId>

testing/trino-product-tests-groups/src/main/java/io/trino/tests/product/TestGroups.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public final class TestGroups
7272
public static final String LDAP_CLI = "ldap_cli";
7373
public static final String LDAP_AND_FILE_CLI = "ldap_and_file_cli";
7474
public static final String LDAP_MULTIPLE_BINDS = "ldap_multiple_binds";
75+
public static final String LOKI = "loki";
7576
public static final String TLS = "tls";
7677
public static final String LARGE_QUERY = "large_query";
7778
public static final String KAFKA = "kafka";
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package io.trino.tests.product.launcher.env.environment;
15+
16+
import com.google.inject.Inject;
17+
import io.trino.tests.product.launcher.docker.DockerFiles;
18+
import io.trino.tests.product.launcher.docker.DockerFiles.ResourceProvider;
19+
import io.trino.tests.product.launcher.env.DockerContainer;
20+
import io.trino.tests.product.launcher.env.Environment.Builder;
21+
import io.trino.tests.product.launcher.env.EnvironmentProvider;
22+
import io.trino.tests.product.launcher.env.common.StandardMultinode;
23+
import io.trino.tests.product.launcher.env.common.TestsEnvironment;
24+
import io.trino.tests.product.launcher.testcontainers.PortBinder;
25+
import org.testcontainers.containers.wait.strategy.Wait;
26+
27+
import java.time.Duration;
28+
29+
import static java.util.Objects.requireNonNull;
30+
import static org.testcontainers.utility.MountableFile.forHostPath;
31+
32+
@TestsEnvironment
33+
public class EnvMultinodeLoki
34+
extends EnvironmentProvider
35+
{
36+
public static final int LOKI_PORT = 3100;
37+
38+
private final ResourceProvider configDir;
39+
private final PortBinder portBinder;
40+
41+
@Inject
42+
public EnvMultinodeLoki(StandardMultinode standardMultinode, DockerFiles dockerFiles, PortBinder portBinder)
43+
{
44+
super(standardMultinode);
45+
this.configDir = dockerFiles.getDockerFilesHostDirectory("conf/environment/multinode-loki/");
46+
this.portBinder = requireNonNull(portBinder, "portBinder is null");
47+
}
48+
49+
@Override
50+
public void extendEnvironment(Builder builder)
51+
{
52+
builder.addConnector("loki", forHostPath(configDir.getPath("loki.properties")));
53+
builder.addContainer(createLoki());
54+
}
55+
56+
private DockerContainer createLoki()
57+
{
58+
DockerContainer container = new DockerContainer("grafana/loki:3.2.0", "loki")
59+
.withExposedPorts(LOKI_PORT)
60+
.waitingFor(Wait.forHttp("/ready").forResponsePredicate(response -> response.contains("ready")))
61+
.withStartupTimeout(Duration.ofMinutes(6));
62+
63+
portBinder.exposePort(container, LOKI_PORT);
64+
65+
return container;
66+
}
67+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package io.trino.tests.product.launcher.suite.suites;
15+
16+
import com.google.common.collect.ImmutableList;
17+
import io.trino.tests.product.launcher.env.EnvironmentConfig;
18+
import io.trino.tests.product.launcher.env.environment.EnvMultinodeLoki;
19+
import io.trino.tests.product.launcher.suite.Suite;
20+
import io.trino.tests.product.launcher.suite.SuiteTestRun;
21+
22+
import java.util.List;
23+
24+
import static io.trino.tests.product.launcher.suite.SuiteTestRun.testOnEnvironment;
25+
26+
public class SuiteLoki
27+
extends Suite
28+
{
29+
@Override
30+
public List<SuiteTestRun> getTestRuns(EnvironmentConfig config)
31+
{
32+
return ImmutableList.of(
33+
testOnEnvironment(EnvMultinodeLoki.class)
34+
.withGroups("configured_features", "loki")
35+
.build());
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
connector.name=loki
2+
loki.uri=http://loki:3100

testing/trino-product-tests/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@
9898
<artifactId>kafka-schema-registry-client</artifactId>
9999
</dependency>
100100

101+
<dependency>
102+
<groupId>io.github.jeschkies</groupId>
103+
<artifactId>loki-client</artifactId>
104+
</dependency>
105+
101106
<dependency>
102107
<groupId>io.minio</groupId>
103108
<artifactId>minio</artifactId>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package io.trino.tests.product.loki;
15+
16+
import com.google.common.collect.ImmutableMap;
17+
import io.github.jeschkies.loki.client.LokiClient;
18+
import io.github.jeschkies.loki.client.LokiClientConfig;
19+
import org.testng.annotations.Test;
20+
21+
import java.net.URI;
22+
import java.time.Duration;
23+
import java.time.Instant;
24+
import java.time.format.DateTimeFormatter;
25+
26+
import static io.trino.tempto.assertions.QueryAssert.Row.row;
27+
import static io.trino.tests.product.TestGroups.LOKI;
28+
import static io.trino.tests.product.TestGroups.PROFILE_SPECIFIC_TESTS;
29+
import static io.trino.tests.product.utils.QueryExecutors.onTrino;
30+
import static java.time.ZoneOffset.UTC;
31+
import static org.assertj.core.api.Assertions.assertThat;
32+
33+
public class TestLoki
34+
{
35+
private static final DateTimeFormatter TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss.SSS'Z'").withZone(UTC);
36+
37+
@Test(groups = {LOKI, PROFILE_SPECIFIC_TESTS})
38+
public void testQueryRange()
39+
throws Exception
40+
{
41+
LokiClient client = new LokiClient(new LokiClientConfig(URI.create("http://loki:3100"), Duration.ofSeconds(10)));
42+
43+
Instant start = Instant.now().minus(Duration.ofHours(3));
44+
Instant end = start.plus(Duration.ofHours(2));
45+
46+
client.pushLogLine("line 1", end.minus(Duration.ofMinutes(10)), ImmutableMap.of("test", "logs_query"));
47+
client.pushLogLine("line 2", end.minus(Duration.ofMinutes(5)), ImmutableMap.of("test", "logs_query"));
48+
client.pushLogLine("line 3", end.minus(Duration.ofMinutes(1)), ImmutableMap.of("test", "logs_query"));
49+
client.flush();
50+
51+
assertThat(onTrino().executeQuery("SELECT value FROM TABLE(loki.system.query_range(" +
52+
"'{test=\"logs_query\"}'," +
53+
"TIMESTAMP '" + TIMESTAMP_FORMATTER.format(start) + "'," +
54+
"TIMESTAMP '" + TIMESTAMP_FORMATTER.format(end) + "'))" +
55+
"LIMIT 1"))
56+
.containsOnly(row("line 1"));
57+
}
58+
}

0 commit comments

Comments
 (0)