This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 6c639d94c6b Optimize jaeger e2e test (#24316)
6c639d94c6b is described below
commit 6c639d94c6b3af1075f010529c8e3af63502cabb
Author: jiangML <[email protected]>
AuthorDate: Thu Feb 23 18:36:21 2023 +0800
Optimize jaeger e2e test (#24316)
* optimize jaeger e2e test
* fix checkstyle error
* optimize code
---
.../test/e2e/agent/common/BasePluginE2EIT.java | 18 ++++
.../e2e/agent/common/env/E2ETestEnvironment.java | 8 +-
.../test/e2e/agent/metrics/MetricsPluginE2EIT.java | 10 +-
.../src/test/resources/env/engine-env.properties | 3 +-
test/e2e/agent/plugins/tracing/jaeger/pom.xml | 22 +----
.../test/e2e/agent/jaeger/JaegerPluginE2EIT.java | 38 ++++----
.../test/e2e/agent/jaeger/asserts/SpanAssert.java | 93 +++++++++++++++++++
.../agent/jaeger/cases/IntegrationTestCases.java | 36 ++++++++
.../jaeger/cases/IntegrationTestCasesLoader.java | 101 +++++++++++++++++++++
.../test/e2e/agent/jaeger/cases/SpanTestCase.java | 45 +++++++++
.../test/e2e/agent/jaeger/cases/TagAssertion.java | 43 +++++++++
.../test/e2e/agent/jaeger/result/SpanResult.java | 39 ++++++++
.../test/e2e/agent/jaeger/result/TagResult.java | 32 +++++++
.../test/e2e/agent/jaeger/result/TraceResult.java | 34 +++++++
.../test/e2e/agent/jaeger/result/TraceResults.java | 30 ++++++
.../src/test/resources/cases/execute_sql.xml | 9 +-
.../src/test/resources/cases/parse_sql.xml} | 10 +-
.../src/test/resources/cases/root_invoke.xml | 2 +-
.../src/test/resources/docker/docker-compose.yml | 2 +
.../src/test/resources/env/engine-env.properties | 4 +-
.../test/e2e/agent/zipkin/ZipkinPluginE2EIT.java | 4 +-
.../test/e2e/agent/zipkin/asserts/SpanAssert.java | 48 +++++-----
.../src/test/resources/cases/execute_sql.xml | 7 +-
.../zipkin/src/test/resources/cases/parse_sql.xml | 7 +-
.../src/test/resources/cases/root_invoke.xml | 2 +-
.../src/test/resources/env/engine-env.properties | 1 +
26 files changed, 546 insertions(+), 102 deletions(-)
diff --git
a/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/BasePluginE2EIT.java
b/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/BasePluginE2EIT.java
index 2a206f01fc0..2884c01f0a2 100644
---
a/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/BasePluginE2EIT.java
+++
b/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/BasePluginE2EIT.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.test.e2e.agent.common;
+import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.test.e2e.agent.common.entity.OrderEntity;
import org.apache.shardingsphere.test.e2e.agent.common.env.E2ETestEnvironment;
@@ -29,6 +30,7 @@ import javax.sql.DataSource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
@@ -39,6 +41,8 @@ import static org.junit.Assert.assertNotNull;
@Slf4j
public abstract class BasePluginE2EIT {
+ private static boolean hasSleep;
+
@Before
public void check() {
Assume.assumeThat(E2ETestEnvironment.getInstance().isEnvironmentPrepared(),
is(true));
@@ -64,5 +68,19 @@ public abstract class BasePluginE2EIT {
JDBCAgentTestUtils.deleteOrderByOrderId(each, dataSource);
}
JDBCAgentTestUtils.createExecuteError(dataSource);
+ sleep();
+ }
+
+ @SneakyThrows(InterruptedException.class)
+ private void sleep() {
+ if (!hasSleep) {
+ log.info("Waiting to collect data ...");
+ TimeUnit.MILLISECONDS.sleep(getSleepTime());
+ hasSleep = true;
+ }
+ }
+
+ private Long getSleepTime() {
+ return
Long.valueOf(E2ETestEnvironment.getInstance().getProps().getProperty("collect.data.wait.milliseconds",
"0"));
}
}
diff --git
a/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/env/E2ETestEnvironment.java
b/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/env/E2ETestEnvironment.java
index 94c1e8f2faf..6579dc44eb2 100644
---
a/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/env/E2ETestEnvironment.java
+++
b/test/e2e/agent/plugins/common/src/test/java/org/apache/shardingsphere/test/e2e/agent/common/env/E2ETestEnvironment.java
@@ -63,7 +63,7 @@ public final class E2ETestEnvironment {
/**
* Create data source.
*/
- public synchronized void createDataSource() {
+ public void createDataSource() {
if (isEnvironmentPrepared && null == dataSource) {
if (waitForEnvironmentReady(props)) {
dataSource = createHikariCP(props);
@@ -76,7 +76,7 @@ public final class E2ETestEnvironment {
private boolean waitForEnvironmentReady(final Properties props) {
log.info("Proxy with agent environment initializing ...");
try {
- Awaitility.await().atMost(4, TimeUnit.MINUTES).pollInterval(5,
TimeUnit.SECONDS).until(() -> isProxyReady(props));
+ Awaitility.await().atMost(2, TimeUnit.MINUTES).pollInterval(5,
TimeUnit.SECONDS).until(() -> isProxyReady(props));
} catch (final ConditionTimeoutException ignored) {
log.info("Proxy with agent environment initialization failed ...");
return false;
@@ -85,7 +85,7 @@ public final class E2ETestEnvironment {
}
private boolean isProxyReady(final Properties props) {
- log.info("try to connect proxy ...");
+ log.info("Try to connect proxy ...");
String url = props.getProperty("proxy.url");
String username = props.getProperty("proxy.username", "root");
String password = props.getProperty("proxy.password", "root");
@@ -102,7 +102,7 @@ public final class E2ETestEnvironment {
private DataSource createHikariCP(final Properties props) {
HikariConfig result = new HikariConfig();
- result.setDriverClassName("com.mysql.jdbc.Driver");
+ result.setDriverClassName("com.mysql.cj.jdbc.Driver");
result.setJdbcUrl(props.getProperty("proxy.url"));
result.setUsername(props.getProperty("proxy.username", "root"));
result.setPassword(props.getProperty("proxy.password", "root"));
diff --git
a/test/e2e/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/MetricsPluginE2EIT.java
b/test/e2e/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/MetricsPluginE2EIT.java
index 9926807cd4d..2016c511ab4 100644
---
a/test/e2e/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/MetricsPluginE2EIT.java
+++
b/test/e2e/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/MetricsPluginE2EIT.java
@@ -38,14 +38,11 @@ import java.io.IOException;
import java.net.URLEncoder;
import java.util.Collection;
import java.util.Properties;
-import java.util.concurrent.TimeUnit;
@Slf4j
@RunWith(Parameterized.class)
public final class MetricsPluginE2EIT extends BasePluginE2EIT {
- private static boolean hasCollect;
-
private final MetricTestCase metricTestCase;
public MetricsPluginE2EIT(final MetricTestCase metricTestCase) {
@@ -58,17 +55,12 @@ public final class MetricsPluginE2EIT extends
BasePluginE2EIT {
}
@Test
- @SneakyThrows({IOException.class, InterruptedException.class})
+ @SneakyThrows(IOException.class)
public void assertProxyWithAgent() {
super.assertProxyWithAgent();
Properties props = E2ETestEnvironment.getInstance().getProps();
String metaDataURL = props.getProperty("prometheus.metadata.url");
String queryURL = props.getProperty("prometheus.query.url");
- if (!hasCollect) {
- log.info("Wait for prometheus to collect data ...");
- TimeUnit.SECONDS.sleep(35);
- hasCollect = true;
- }
assertMetadata(metaDataURL, metricTestCase);
assertQuery(queryURL, metricTestCase);
}
diff --git
a/test/e2e/agent/plugins/metrics/prometheus/src/test/resources/env/engine-env.properties
b/test/e2e/agent/plugins/metrics/prometheus/src/test/resources/env/engine-env.properties
index ecbca1fc062..ead6fba9393 100644
---
a/test/e2e/agent/plugins/metrics/prometheus/src/test/resources/env/engine-env.properties
+++
b/test/e2e/agent/plugins/metrics/prometheus/src/test/resources/env/engine-env.properties
@@ -18,9 +18,10 @@
it.env.type=${it.env}
it.env.value=prometheus
-proxy.url=jdbc:mysql://127.0.0.1:43070/agent-metrics-db?serverTimezone=UTC&useSSL=false&useLocalSessionState=true&characterEncoding=utf-8&connectTimeout=3000&socketTimeout=6000
+proxy.url=jdbc:mysql://127.0.0.1:43070/agent-metrics-db?serverTimezone=UTC&useSSL=false&useLocalSessionState=true&characterEncoding=utf-8
proxy.username=root
proxy.password=root
prometheus.metadata.url=http://127.0.0.1:19090/api/v1/metadata
prometheus.query.url=http://127.0.0.1:19090/api/v1/query
+collect.data.wait.milliseconds=35000
diff --git a/test/e2e/agent/plugins/tracing/jaeger/pom.xml
b/test/e2e/agent/plugins/tracing/jaeger/pom.xml
index 6a43fed3528..de1b4c90836 100644
--- a/test/e2e/agent/plugins/tracing/jaeger/pom.xml
+++ b/test/e2e/agent/plugins/tracing/jaeger/pom.xml
@@ -29,6 +29,7 @@
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
+ <mysql-connector-java.version>8.0.31</mysql-connector-java.version>
</properties>
<dependencies>
@@ -38,35 +39,16 @@
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-jdbc-core</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-proxy-bootstrap</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- </dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
+ <version>${mysql-connector-java.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <scope>compile</scope>
</dependency>
</dependencies>
diff --git
a/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/JaegerPluginE2EIT.java
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/JaegerPluginE2EIT.java
index 983ebbf392f..a3c04c4cbde 100644
---
a/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/JaegerPluginE2EIT.java
+++
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/JaegerPluginE2EIT.java
@@ -18,47 +18,51 @@
package org.apache.shardingsphere.test.e2e.agent.jaeger;
import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.test.e2e.agent.common.BasePluginE2EIT;
import org.apache.shardingsphere.test.e2e.agent.common.env.E2ETestEnvironment;
-import org.apache.shardingsphere.test.e2e.agent.common.util.OkHttpUtils;
-import
org.apache.shardingsphere.test.e2e.agent.jaeger.result.JaegerTraceResult;
+import org.apache.shardingsphere.test.e2e.agent.jaeger.asserts.SpanAssert;
+import
org.apache.shardingsphere.test.e2e.agent.jaeger.cases.IntegrationTestCasesLoader;
+import org.apache.shardingsphere.test.e2e.agent.jaeger.cases.SpanTestCase;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
import java.io.IOException;
+import java.util.Collection;
import java.util.Properties;
-import static org.junit.Assert.assertFalse;
-
+@Slf4j
+@RunWith(Parameterized.class)
public final class JaegerPluginE2EIT extends BasePluginE2EIT {
+ private final SpanTestCase spanTestCase;
+
private Properties props;
private String url;
- private String serviceName;
+ public JaegerPluginE2EIT(final SpanTestCase spanTestCase) {
+ this.spanTestCase = spanTestCase;
+ }
+
+ @Parameters
+ public static Collection<SpanTestCase> getTestParameters() {
+ return
IntegrationTestCasesLoader.getInstance().loadIntegrationTestCases();
+ }
@Before
public void before() {
props = E2ETestEnvironment.getInstance().getProps();
url = props.getProperty("jaeger.url");
- serviceName = props.getProperty("jaeger.servername");
}
- @Ignore
@SneakyThrows(IOException.class)
@Test
public void assertProxyWithAgent() {
super.assertProxyWithAgent();
- assertTraces();
- }
-
- @SneakyThrows(IOException.class)
- private void assertTraces() {
- String traceURL = url + "traces?service=" + serviceName;
- JaegerTraceResult jaegerTraceResult =
OkHttpUtils.getInstance().get(traceURL, JaegerTraceResult.class);
- assertFalse("Jaeger should have tracing data.",
jaegerTraceResult.getData().isEmpty());
- jaegerTraceResult.getData().forEach(each -> assertFalse("Jaeger should
have span data.", each.getSpans().isEmpty()));
+ SpanAssert.assertIs(url, spanTestCase);
}
}
diff --git
a/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/asserts/SpanAssert.java
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/asserts/SpanAssert.java
new file mode 100644
index 00000000000..b523f375a18
--- /dev/null
+++
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/asserts/SpanAssert.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.agent.jaeger.asserts;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.test.e2e.agent.common.util.OkHttpUtils;
+import org.apache.shardingsphere.test.e2e.agent.jaeger.cases.SpanTestCase;
+import org.apache.shardingsphere.test.e2e.agent.jaeger.cases.TagAssertion;
+import org.apache.shardingsphere.test.e2e.agent.jaeger.result.SpanResult;
+import org.apache.shardingsphere.test.e2e.agent.jaeger.result.TagResult;
+import org.apache.shardingsphere.test.e2e.agent.jaeger.result.TraceResult;
+import org.apache.shardingsphere.test.e2e.agent.jaeger.result.TraceResults;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.Collection;
+import java.util.stream.Collectors;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Span assert.
+ */
+@Slf4j
+public final class SpanAssert {
+
+ /**
+ * Assert span is correct with expected result.
+ *
+ * @param baseUrl jaeger query url
+ * @param expected expected span
+ */
+ public static void assertIs(final String baseUrl, final SpanTestCase
expected) {
+ assertTagKey(baseUrl, expected);
+
expected.getTagCases().stream().filter(TagAssertion::isNeedAssertValue).forEach(each
-> assertTagValue(baseUrl, expected, each));
+ }
+
+ private static void assertTagKey(final String baseUrl, final SpanTestCase
expected) {
+ String urlWithParameter =
String.format("%s/api/traces?service=%s&operation=%s&limit=%s", baseUrl,
+ getEncodeValue(expected.getServiceName()),
getEncodeValue(expected.getSpanName()), 1000);
+ Collection<TraceResult> traceResults =
getTraceResults(urlWithParameter);
+ assertNotNull(traceResults);
+ SpanResult spanResult = traceResults.stream().flatMap(each ->
each.getSpans().stream())
+ .filter(each ->
expected.getSpanName().equalsIgnoreCase(each.getOperationName())).findFirst().orElse(null);
+ assertNotNull(spanResult);
+ Collection<String> actualTags =
spanResult.getTags().stream().map(TagResult::getKey).collect(Collectors.toSet());
+ Collection<String> expectedTags =
expected.getTagCases().stream().map(TagAssertion::getTagKey).collect(Collectors.toSet());
+ Collection<String> nonExistentTags = expectedTags.stream().filter(each
-> !actualTags.contains(each)).collect(Collectors.toSet());
+ assertTrue(String.format("The tags `%s` does not exist in `%s` span",
nonExistentTags, expected.getSpanName()), nonExistentTags.isEmpty());
+ }
+
+ private static void assertTagValue(final String baseUrl, final
SpanTestCase expected, final TagAssertion expectedTagCase) {
+ String urlWithParameter =
String.format("%s/api/traces?service=%s&operation=%s&tags=%s&limit=%s",
baseUrl, getEncodeValue(expected.getServiceName()),
+ getEncodeValue(expected.getSpanName()), getEncodeValue(new
Gson().toJson(ImmutableMap.of(expectedTagCase.getTagKey(),
expectedTagCase.getTagValue()))), 1000);
+ Collection<TraceResult> traceResults =
getTraceResults(urlWithParameter);
+ assertFalse(String.format("The tag `%s`=`%s` does not exist in `%s`
span", expectedTagCase.getTagKey(), expectedTagCase.getTagValue(),
expected.getSpanName()), traceResults.isEmpty());
+ }
+
+ @SneakyThrows(UnsupportedEncodingException.class)
+ private static String getEncodeValue(final String value) {
+ return URLEncoder.encode(value, "UTF-8");
+ }
+
+ @SneakyThrows(IOException.class)
+ private static Collection<TraceResult> getTraceResults(final String url) {
+ TraceResults result = new
Gson().fromJson(OkHttpUtils.getInstance().get(url), new
TypeToken<TraceResults>() {
+ }.getType());
+ assertNotNull(result);
+ return result.getData();
+ }
+}
diff --git
a/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/cases/IntegrationTestCases.java
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/cases/IntegrationTestCases.java
new file mode 100644
index 00000000000..3b9cf9ff587
--- /dev/null
+++
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/cases/IntegrationTestCases.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.agent.jaeger.cases;
+
+import lombok.Getter;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.Collection;
+import java.util.LinkedList;
+
+/**
+ * Integration test cases.
+ */
+@Getter
+@XmlRootElement(name = "integration-test-cases")
+public final class IntegrationTestCases {
+
+ @XmlElement(name = "test-case")
+ private final Collection<SpanTestCase> testCases = new LinkedList<>();
+}
diff --git
a/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/cases/IntegrationTestCasesLoader.java
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/cases/IntegrationTestCasesLoader.java
new file mode 100644
index 00000000000..c76e14544e4
--- /dev/null
+++
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/cases/IntegrationTestCasesLoader.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.agent.jaeger.cases;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import lombok.SneakyThrows;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Objects;
+
+/**
+ * Integration test cases loader.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class IntegrationTestCasesLoader {
+
+ private static final String FILE_EXTENSION = ".xml";
+
+ private static final IntegrationTestCasesLoader INSTANCE = new
IntegrationTestCasesLoader();
+
+ private Collection<SpanTestCase> integrationTestCases;
+
+ /**
+ * Get singleton instance.
+ *
+ * @return singleton instance
+ */
+ public static IntegrationTestCasesLoader getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Load integration test cases.
+ *
+ * @return integration test cases
+ */
+ @SneakyThrows({IOException.class, URISyntaxException.class,
JAXBException.class})
+ public Collection<SpanTestCase> loadIntegrationTestCases() {
+ if (null != integrationTestCases) {
+ return integrationTestCases;
+ }
+ integrationTestCases = new LinkedList<>();
+ URL url =
Objects.requireNonNull(IntegrationTestCasesLoader.class.getClassLoader().getResource("cases/"));
+ Collection<File> files = getFiles(url);
+ for (File each : files) {
+
integrationTestCases.addAll(unmarshal(each.getPath()).getTestCases());
+ }
+ return integrationTestCases;
+ }
+
+ private static Collection<File> getFiles(final URL url) throws
IOException, URISyntaxException {
+ Collection<File> result = new LinkedList<>();
+ Files.walkFileTree(Paths.get(url.toURI()), new
SimpleFileVisitor<Path>() {
+
+ @Override
+ public FileVisitResult visitFile(final Path file, final
BasicFileAttributes basicFileAttributes) {
+ if (file.getFileName().toString().endsWith(FILE_EXTENSION)) {
+ result.add(file.toFile());
+ }
+ return FileVisitResult.CONTINUE;
+ }
+ });
+ return result;
+ }
+
+ private static IntegrationTestCases unmarshal(final String
integrateCasesFile) throws IOException, JAXBException {
+ try (FileReader reader = new FileReader(integrateCasesFile)) {
+ return (IntegrationTestCases)
JAXBContext.newInstance(IntegrationTestCases.class).createUnmarshaller().unmarshal(reader);
+ }
+ }
+}
diff --git
a/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/cases/SpanTestCase.java
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/cases/SpanTestCase.java
new file mode 100644
index 00000000000..796481bb201
--- /dev/null
+++
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/cases/SpanTestCase.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.agent.jaeger.cases;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import java.util.Collection;
+
+/**
+ * Span test case.
+ */
+@Getter
+@Setter
+@XmlAccessorType(XmlAccessType.FIELD)
+public final class SpanTestCase {
+
+ @XmlAttribute(name = "service-name")
+ private String serviceName;
+
+ @XmlAttribute(name = "span-name")
+ private String spanName;
+
+ @XmlElement(name = "tag-assertion")
+ private Collection<TagAssertion> tagCases;
+}
diff --git
a/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/cases/TagAssertion.java
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/cases/TagAssertion.java
new file mode 100644
index 00000000000..f286ecc08b2
--- /dev/null
+++
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/cases/TagAssertion.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.agent.jaeger.cases;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+
+/**
+ * Tag assertion.
+ */
+@Getter
+@Setter
+@XmlAccessorType(XmlAccessType.FIELD)
+public final class TagAssertion {
+
+ @XmlAttribute(name = "key")
+ private String tagKey;
+
+ @XmlAttribute(name = "value")
+ private String tagValue;
+
+ @XmlAttribute(name = "need-assert-value")
+ private boolean needAssertValue;
+}
diff --git
a/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/result/SpanResult.java
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/result/SpanResult.java
new file mode 100644
index 00000000000..c5dce6d9e00
--- /dev/null
+++
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/result/SpanResult.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.agent.jaeger.result;
+
+import com.google.gson.annotations.SerializedName;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Collection;
+
+@Getter
+@Setter
+public final class SpanResult {
+
+ @SerializedName("traceID")
+ private String traceId;
+
+ @SerializedName("spanID")
+ private String spanId;
+
+ private String operationName;
+
+ private Collection<TagResult> tags;
+}
diff --git
a/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/result/TagResult.java
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/result/TagResult.java
new file mode 100644
index 00000000000..b994f9b1f16
--- /dev/null
+++
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/result/TagResult.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.agent.jaeger.result;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public final class TagResult {
+
+ private String key;
+
+ private String type;
+
+ private String value;
+}
diff --git
a/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/result/TraceResult.java
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/result/TraceResult.java
new file mode 100644
index 00000000000..9108d6ee82f
--- /dev/null
+++
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/result/TraceResult.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.agent.jaeger.result;
+
+import com.google.gson.annotations.SerializedName;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Collection;
+
+@Getter
+@Setter
+public final class TraceResult {
+
+ @SerializedName("traceID")
+ private String traceId;
+
+ private Collection<SpanResult> spans;
+}
diff --git
a/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/result/TraceResults.java
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/result/TraceResults.java
new file mode 100644
index 00000000000..6a944922f8e
--- /dev/null
+++
b/test/e2e/agent/plugins/tracing/jaeger/src/test/java/org/apache/shardingsphere/test/e2e/agent/jaeger/result/TraceResults.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.e2e.agent.jaeger.result;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Collection;
+
+@Getter
+@Setter
+public final class TraceResults {
+
+ private Collection<TraceResult> data;
+}
diff --git
a/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/execute_sql.xml
b/test/e2e/agent/plugins/tracing/jaeger/src/test/resources/cases/execute_sql.xml
similarity index 67%
copy from
test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/execute_sql.xml
copy to
test/e2e/agent/plugins/tracing/jaeger/src/test/resources/cases/execute_sql.xml
index 1418e786f19..872ca5de4b3 100644
---
a/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/execute_sql.xml
+++
b/test/e2e/agent/plugins/tracing/jaeger/src/test/resources/cases/execute_sql.xml
@@ -17,20 +17,15 @@
-->
<integration-test-cases>
- <test-case service-name="shardingsphere"
span-name="/shardingsphere/executesql/">
+ <test-case service-name="shardingsphere"
span-name="/ShardingSphere/executeSQL/">
<tag-assertion key="component" value="ShardingSphere"
need-assert-value="true" />
<tag-assertion key="span.kind" value="client" need-assert-value="true"
/>
<tag-assertion key="db.type" value="MySQL" need-assert-value="true" />
- <tag-assertion key="peer.hostname"
value="mysql.agent.tracing.zipkin.host" need-assert-value="true" />
+ <tag-assertion key="peer.hostname"
value="mysql.agent.tracing.jaeger.host" need-assert-value="true" />
<tag-assertion key="peer.port" value="3306" need-assert-value="true" />
<tag-assertion key="db.instance" value="ds_0" need-assert-value="true"
/>
<tag-assertion key="db.instance" value="ds_1" need-assert-value="true"
/>
<tag-assertion key="db.bind_vars" />
<tag-assertion key="db.statement" />
- <tag-assertion key="db.statement" value="SELECT * FROM
non_existent_table" need-assert-value="true" />
- <tag-assertion key="db.statement" value="SELECT * FROM t_order"
need-assert-value="true" />
- <tag-assertion key="db.statement" value="INSERT INTO t_order
(order_id, user_id, status) VALUES (10, 10, 'INSERT_TEST')"
need-assert-value="true" />
- <tag-assertion key="db.statement" value="DELETE FROM t_order WHERE
order_id=10" need-assert-value="true" />
- <tag-assertion key="db.statement" value="UPDATE t_order SET status =
'ROLL_BACK' WHERE order_id =1000" need-assert-value="true" />
</test-case>
</integration-test-cases>
diff --git
a/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/execute_sql.xml
b/test/e2e/agent/plugins/tracing/jaeger/src/test/resources/cases/parse_sql.xml
similarity index 72%
copy from
test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/execute_sql.xml
copy to
test/e2e/agent/plugins/tracing/jaeger/src/test/resources/cases/parse_sql.xml
index 1418e786f19..4a2c952fc4b 100644
---
a/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/execute_sql.xml
+++
b/test/e2e/agent/plugins/tracing/jaeger/src/test/resources/cases/parse_sql.xml
@@ -17,15 +17,9 @@
-->
<integration-test-cases>
- <test-case service-name="shardingsphere"
span-name="/shardingsphere/executesql/">
+ <test-case service-name="shardingsphere"
span-name="/ShardingSphere/parseSQL/">
<tag-assertion key="component" value="ShardingSphere"
need-assert-value="true" />
- <tag-assertion key="span.kind" value="client" need-assert-value="true"
/>
- <tag-assertion key="db.type" value="MySQL" need-assert-value="true" />
- <tag-assertion key="peer.hostname"
value="mysql.agent.tracing.zipkin.host" need-assert-value="true" />
- <tag-assertion key="peer.port" value="3306" need-assert-value="true" />
- <tag-assertion key="db.instance" value="ds_0" need-assert-value="true"
/>
- <tag-assertion key="db.instance" value="ds_1" need-assert-value="true"
/>
- <tag-assertion key="db.bind_vars" />
+ <tag-assertion key="span.kind" value="internal"
need-assert-value="true" />
<tag-assertion key="db.statement" />
<tag-assertion key="db.statement" value="SELECT * FROM
non_existent_table" need-assert-value="true" />
<tag-assertion key="db.statement" value="SELECT * FROM t_order"
need-assert-value="true" />
diff --git
a/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/root_invoke.xml
b/test/e2e/agent/plugins/tracing/jaeger/src/test/resources/cases/root_invoke.xml
similarity index 92%
copy from
test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/root_invoke.xml
copy to
test/e2e/agent/plugins/tracing/jaeger/src/test/resources/cases/root_invoke.xml
index 201d836a772..e11fb08fa9d 100644
---
a/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/root_invoke.xml
+++
b/test/e2e/agent/plugins/tracing/jaeger/src/test/resources/cases/root_invoke.xml
@@ -17,7 +17,7 @@
-->
<integration-test-cases>
- <test-case service-name="shardingsphere"
span-name="/shardingsphere/rootinvoke/">
+ <test-case service-name="shardingsphere"
span-name="/ShardingSphere/rootInvoke/">
<tag-assertion key="component" value="ShardingSphere"
need-assert-value="true" />
<tag-assertion key="span.kind" value="client" need-assert-value="true"
/>
</test-case>
diff --git
a/test/e2e/agent/plugins/tracing/jaeger/src/test/resources/docker/docker-compose.yml
b/test/e2e/agent/plugins/tracing/jaeger/src/test/resources/docker/docker-compose.yml
index 41a1fdf3231..ca517290e7e 100644
---
a/test/e2e/agent/plugins/tracing/jaeger/src/test/resources/docker/docker-compose.yml
+++
b/test/e2e/agent/plugins/tracing/jaeger/src/test/resources/docker/docker-compose.yml
@@ -35,6 +35,8 @@ services:
ports:
- "14317:4317"
- "26686:16686"
+ environment:
+ - COLLECTOR_OTLP_ENABLED=true
shardingsphere-proxy-agent-tracing:
image: apache/shardingsphere-proxy-agent-tracing-jaeger-test
diff --git
a/test/e2e/agent/plugins/tracing/jaeger/src/test/resources/env/engine-env.properties
b/test/e2e/agent/plugins/tracing/jaeger/src/test/resources/env/engine-env.properties
index 995e9befddd..bc08b8cd95d 100644
---
a/test/e2e/agent/plugins/tracing/jaeger/src/test/resources/env/engine-env.properties
+++
b/test/e2e/agent/plugins/tracing/jaeger/src/test/resources/env/engine-env.properties
@@ -22,5 +22,5 @@
proxy.url=jdbc:mysql://127.0.0.1:43071/agent-tracing-jaeger-db?serverTimezone=UT
proxy.username=root
proxy.password=root
-jaeger.url=http://127.0.0.1:26686/api/
-jaeger.servername=shardingsphere
+jaeger.url=http://127.0.0.1:26686
+collect.data.wait.milliseconds=5000
diff --git
a/test/e2e/agent/plugins/tracing/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/ZipkinPluginE2EIT.java
b/test/e2e/agent/plugins/tracing/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/ZipkinPluginE2EIT.java
index 6ad02999d19..8411e86aa4b 100644
---
a/test/e2e/agent/plugins/tracing/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/ZipkinPluginE2EIT.java
+++
b/test/e2e/agent/plugins/tracing/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/ZipkinPluginE2EIT.java
@@ -32,7 +32,6 @@ import org.junit.runners.Parameterized.Parameters;
import java.io.IOException;
import java.util.Collection;
import java.util.Properties;
-import java.util.concurrent.TimeUnit;
@RunWith(Parameterized.class)
public final class ZipkinPluginE2EIT extends BasePluginE2EIT {
@@ -59,10 +58,9 @@ public final class ZipkinPluginE2EIT extends BasePluginE2EIT
{
}
@Test
- @SneakyThrows({IOException.class, InterruptedException.class})
+ @SneakyThrows(IOException.class)
public void assertProxyWithAgent() {
super.assertProxyWithAgent();
- TimeUnit.SECONDS.sleep(5);
SpanAssert.assertIs(url, spanTestCase);
}
}
diff --git
a/test/e2e/agent/plugins/tracing/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/asserts/SpanAssert.java
b/test/e2e/agent/plugins/tracing/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/asserts/SpanAssert.java
index d6552c67509..e8f087e0180 100644
---
a/test/e2e/agent/plugins/tracing/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/asserts/SpanAssert.java
+++
b/test/e2e/agent/plugins/tracing/zipkin/src/test/java/org/apache/shardingsphere/test/e2e/agent/zipkin/asserts/SpanAssert.java
@@ -28,12 +28,14 @@ import
org.apache.shardingsphere.test.e2e.agent.zipkin.result.SpanResult;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
/**
* Span assert.
@@ -47,36 +49,38 @@ public final class SpanAssert {
* @param expected expected span
*/
public static void assertIs(final String baseUrl, final SpanTestCase
expected) {
- for (TagAssertion each : expected.getTagCases()) {
- assertSpan(baseUrl, expected, each);
- }
+ assertTagKey(baseUrl, expected);
+
expected.getTagCases().stream().filter(TagAssertion::isNeedAssertValue).forEach(each
-> assertTagValue(baseUrl, expected, each));
}
- private static void assertSpan(final String baseUrl, final SpanTestCase
expected, final TagAssertion expectedTagCase) {
- String tracesApiUrl = getTraceApiUrl(baseUrl, expected,
expectedTagCase);
- List<List<SpanResult>> spanResults = null;
- try {
- spanResults = new
Gson().fromJson(OkHttpUtils.getInstance().get(tracesApiUrl), new
TypeToken<List<List<SpanResult>>>() {
- }.getType());
- } catch (final IOException ignored) {
- }
- assertNotNull(spanResults);
- List<SpanResult> spanList =
spanResults.stream().findFirst().orElse(Collections.emptyList()).stream()
- .filter(each ->
expected.getSpanName().equalsIgnoreCase(each.getName())).collect(Collectors.toList());
- assertFalse(expectedTagCase.isNeedAssertValue()
- ? String.format("The tag `%s`=`%s` does not exist in `%s`
span", expectedTagCase.getTagKey(), expectedTagCase.getTagValue(),
expected.getSpanName())
- : String.format("The tag `%s` does not exist in `%s` span",
expectedTagCase.getTagKey(), expected.getSpanName()), spanList.isEmpty());
+ private static void assertTagKey(final String baseUrl, final SpanTestCase
expected) {
+ String baseTraceApiUrl =
String.format("%s/api/v2/traces?serviceName=%s&spanName=%s&limit=%s", baseUrl,
getEncodeValue(expected.getServiceName()),
+ getEncodeValue(expected.getSpanName()), 1000);
+ Collection<SpanResult> spanResults = getSpanResults(expected,
baseTraceApiUrl);
+ Collection<String> actualTags = spanResults.stream().flatMap(each ->
each.getTags().keySet().stream()).collect(Collectors.toSet());
+ Collection<String> expectedTags =
expected.getTagCases().stream().map(TagAssertion::getTagKey).collect(Collectors.toSet());
+ Collection<String> nonExistentTags = expectedTags.stream().filter(each
-> !actualTags.contains(each)).collect(Collectors.toSet());
+ assertTrue(String.format("The tags `%s` does not exist in `%s` span",
nonExistentTags, expected.getSpanName()), nonExistentTags.isEmpty());
}
- private static String getTraceApiUrl(final String baseUrl, final
SpanTestCase expected, final TagAssertion expectedTagCase) {
- String baseTraceApiUrl =
String.format("%s/api/v2/traces?serviceName=%s&spanName=%s", baseUrl,
getEncodeValue(expected.getServiceName()),
getEncodeValue(expected.getSpanName()));
- return expectedTagCase.isNeedAssertValue()
- ? String.format("%s&annotationQuery=%s", baseTraceApiUrl,
getEncodeValue(String.format("%s=%s", expectedTagCase.getTagKey(),
expectedTagCase.getTagValue())))
- : String.format("%s&annotationQuery=%s", baseTraceApiUrl,
getEncodeValue(expectedTagCase.getTagKey()));
+ private static void assertTagValue(final String baseUrl, final
SpanTestCase expected, final TagAssertion expectedTagCase) {
+ String baseTraceApiUrl =
String.format("%s/api/v2/traces?serviceName=%s&spanName=%s&annotationQuery=%s&limit=%s",
baseUrl, getEncodeValue(expected.getServiceName()),
+ getEncodeValue(expected.getSpanName()),
getEncodeValue(String.format("%s=%s", expectedTagCase.getTagKey(),
expectedTagCase.getTagValue())), 1000);
+ Collection<SpanResult> spanResults = getSpanResults(expected,
baseTraceApiUrl);
+ assertFalse(String.format("The tag `%s`=`%s` does not exist in `%s`
span", expectedTagCase.getTagKey(), expectedTagCase.getTagValue(),
expected.getSpanName()), spanResults.isEmpty());
}
@SneakyThrows(UnsupportedEncodingException.class)
private static String getEncodeValue(final String value) {
return URLEncoder.encode(value, "UTF-8");
}
+
+ @SneakyThrows(IOException.class)
+ private static Collection<SpanResult> getSpanResults(final SpanTestCase
expected, final String url) {
+ List<List<SpanResult>> result = new
Gson().fromJson(OkHttpUtils.getInstance().get(url), new
TypeToken<List<List<SpanResult>>>() {
+ }.getType());
+ assertNotNull(result);
+ return
result.stream().findFirst().orElse(Collections.emptyList()).stream()
+ .filter(each ->
expected.getSpanName().equalsIgnoreCase(each.getName())).collect(Collectors.toList());
+ }
}
diff --git
a/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/execute_sql.xml
b/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/execute_sql.xml
index 1418e786f19..3210f252d9e 100644
---
a/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/execute_sql.xml
+++
b/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/execute_sql.xml
@@ -17,7 +17,7 @@
-->
<integration-test-cases>
- <test-case service-name="shardingsphere"
span-name="/shardingsphere/executesql/">
+ <test-case service-name="shardingsphere"
span-name="/ShardingSphere/executeSQL/">
<tag-assertion key="component" value="ShardingSphere"
need-assert-value="true" />
<tag-assertion key="span.kind" value="client" need-assert-value="true"
/>
<tag-assertion key="db.type" value="MySQL" need-assert-value="true" />
@@ -27,10 +27,5 @@
<tag-assertion key="db.instance" value="ds_1" need-assert-value="true"
/>
<tag-assertion key="db.bind_vars" />
<tag-assertion key="db.statement" />
- <tag-assertion key="db.statement" value="SELECT * FROM
non_existent_table" need-assert-value="true" />
- <tag-assertion key="db.statement" value="SELECT * FROM t_order"
need-assert-value="true" />
- <tag-assertion key="db.statement" value="INSERT INTO t_order
(order_id, user_id, status) VALUES (10, 10, 'INSERT_TEST')"
need-assert-value="true" />
- <tag-assertion key="db.statement" value="DELETE FROM t_order WHERE
order_id=10" need-assert-value="true" />
- <tag-assertion key="db.statement" value="UPDATE t_order SET status =
'ROLL_BACK' WHERE order_id =1000" need-assert-value="true" />
</test-case>
</integration-test-cases>
diff --git
a/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/parse_sql.xml
b/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/parse_sql.xml
index 85e492d73e0..4a2c952fc4b 100644
---
a/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/parse_sql.xml
+++
b/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/parse_sql.xml
@@ -17,9 +17,14 @@
-->
<integration-test-cases>
- <test-case service-name="shardingsphere"
span-name="/shardingsphere/parsesql/">
+ <test-case service-name="shardingsphere"
span-name="/ShardingSphere/parseSQL/">
<tag-assertion key="component" value="ShardingSphere"
need-assert-value="true" />
<tag-assertion key="span.kind" value="internal"
need-assert-value="true" />
<tag-assertion key="db.statement" />
+ <tag-assertion key="db.statement" value="SELECT * FROM
non_existent_table" need-assert-value="true" />
+ <tag-assertion key="db.statement" value="SELECT * FROM t_order"
need-assert-value="true" />
+ <tag-assertion key="db.statement" value="INSERT INTO t_order
(order_id, user_id, status) VALUES (10, 10, 'INSERT_TEST')"
need-assert-value="true" />
+ <tag-assertion key="db.statement" value="DELETE FROM t_order WHERE
order_id=10" need-assert-value="true" />
+ <tag-assertion key="db.statement" value="UPDATE t_order SET status =
'ROLL_BACK' WHERE order_id =1000" need-assert-value="true" />
</test-case>
</integration-test-cases>
diff --git
a/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/root_invoke.xml
b/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/root_invoke.xml
index 201d836a772..e11fb08fa9d 100644
---
a/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/root_invoke.xml
+++
b/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/cases/root_invoke.xml
@@ -17,7 +17,7 @@
-->
<integration-test-cases>
- <test-case service-name="shardingsphere"
span-name="/shardingsphere/rootinvoke/">
+ <test-case service-name="shardingsphere"
span-name="/ShardingSphere/rootInvoke/">
<tag-assertion key="component" value="ShardingSphere"
need-assert-value="true" />
<tag-assertion key="span.kind" value="client" need-assert-value="true"
/>
</test-case>
diff --git
a/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/env/engine-env.properties
b/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/env/engine-env.properties
index e139488ed22..324579109a8 100644
---
a/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/env/engine-env.properties
+++
b/test/e2e/agent/plugins/tracing/zipkin/src/test/resources/env/engine-env.properties
@@ -23,3 +23,4 @@ proxy.username=root
proxy.password=root
zipkin.url=http://127.0.0.1:19411
+collect.data.wait.milliseconds=5000