Support for the remote debugging of local E2E testing framework (#5198)

This commit is contained in:
CoderGang 2020-08-07 21:19:10 +08:00 committed by GitHub
parent bdef778e53
commit 4b441f06c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 218 additions and 2 deletions

View File

@ -20,15 +20,17 @@ package org.apache.skywalking.e2e;
import com.google.common.base.Strings;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
@ -99,6 +101,9 @@ public final class SkyWalkingAnnotations {
? (System.getenv("GITHUB_WORKSPACE") + "/logs") : "/tmp/skywalking/logs";
private static final Path LOG_DIR = Paths.get(LOG_DIR_ENV);
private static final List<String> REMOTE_SERVICE_NAMES = new LinkedList<>();
private static final int REMOTE_DEBUG_PORT = 5005;
static {
LOGGER.info("IDENTIFIER={}", IDENTIFIER);
LOGGER.info("LOG_DIR={}", LOG_DIR);
@ -164,6 +169,17 @@ public final class SkyWalkingAnnotations {
field.set(testClass, HostAndPort.builder().host(host).port(port).build());
}
}
if (!IS_CI) {
File portFile = new File("remote_real_port");
portFile.createNewFile();
FileWriter fileWriter = new FileWriter(portFile.getName());
for (String service : REMOTE_SERVICE_NAMES) {
fileWriter.write(String.format("%s-%s:%s\n", service, compose.getServiceHost(service, REMOTE_DEBUG_PORT),
compose.getServicePort(service, REMOTE_DEBUG_PORT)));
}
fileWriter.flush();
fileWriter.close();
}
}
private static Optional<DockerComposeContainer<?>> initDockerComposeField(final Object testClass) throws Exception {
@ -186,6 +202,25 @@ public final class SkyWalkingAnnotations {
.map(File::new).collect(Collectors.toList());
final DockerComposeContainer<?> compose = new DockerComposeContainer<>(IDENTIFIER, files);
if (!IS_CI) {
files.forEach(file -> {
try {
DockerComposeFile dockerComposeFile = DockerComposeFile.getAllConfigInfo(
file.getAbsolutePath());
LOGGER.info(file.getAbsolutePath());
dockerComposeFile.getServices().forEach(
(service, ignored) -> {
if (dockerComposeFile.isExposedPort(service, REMOTE_DEBUG_PORT)) {
REMOTE_SERVICE_NAMES.add(service);
compose.withExposedService(service, REMOTE_DEBUG_PORT, Wait.forListeningPort());
}
});
} catch (IOException | InterruptedException e) {
LOGGER.error(e.getMessage(), e);
}
});
}
for (final Field field : fields) {
if (field.isAnnotationPresent(ContainerHost.class) && field.isAnnotationPresent(ContainerPort.class)) {
throw new RuntimeException(

View File

@ -18,12 +18,52 @@
package org.apache.skywalking.e2e.docker;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import lombok.Data;
import static org.apache.skywalking.e2e.utils.Yamls.load;
@Data
public final class DockerComposeFile {
private String version;
private Map<String, Map<String, Object>> services;
private Map<String, Map<String, Object>> networks;
public static DockerComposeFile getAllConfigInfo(String composeFile) throws IOException, InterruptedException {
String shStr = String.format("docker-compose -f %s config", composeFile);
Process process = Runtime.getRuntime().exec(shStr, null, null);
InputStreamReader ir = new InputStreamReader(process.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
String line;
StringBuilder result = new StringBuilder();
process.waitFor();
while ((line = input.readLine()) != null) {
result.append(line).append("\n");
}
return load(result).as(DockerComposeFile.class);
}
public List<String> getServiceExposedPorts(String serviceName) {
Map<String, Object> service = services.get(serviceName);
List tmp = (List) service.get("expose");
if (tmp == null) {
return new LinkedList<>();
}
List<String> ports = new LinkedList<>();
for (Object item: tmp) {
ports.add(item.toString());
}
return ports;
}
public boolean isExposedPort(String serviceName, Integer port) {
List<String> ports = getServiceExposedPorts(serviceName);
return ports.contains(String.valueOf(port));
}
}

View File

@ -59,4 +59,13 @@ public final class Yamls {
}
};
}
public static AsTypeBuilder load(final StringBuilder content) {
return new AsTypeBuilder() {
@Override
public <T> T as(final Class<T> klass) {
return new Yaml().loadAs(content.toString(), klass);
}
};
}
}

View File

@ -0,0 +1,66 @@
/*
* 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.skywalking.e2e.docker;
import org.apache.skywalking.e2e.utils.Yamls;
import org.junit.Assert;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
class DockerComposeFileTest {
private static DockerComposeFile COMPOSE_FILE = null;
@BeforeAll
static void setUp() throws Exception {
COMPOSE_FILE = Yamls.load("docker-compose.yml").as(DockerComposeFile.class);
}
@Test
void getAllConfigInfo() throws IOException, InterruptedException, URISyntaxException {
File file = new File(DockerComposeFileTest.class
.getClassLoader()
.getResource("docker-compose.yml")
.toURI());
DockerComposeFile testFile = DockerComposeFile.getAllConfigInfo(file.getAbsolutePath());
Assert.assertNotNull(testFile);
Assert.assertNotNull(testFile.getServices());
Assert.assertEquals(COMPOSE_FILE.getServices().size(), testFile.getServices().size());
Assert.assertEquals(COMPOSE_FILE.getVersion(), testFile.getVersion());
}
@Test
void getServiceExposedPort() {
List<String> ports = COMPOSE_FILE.getServiceExposedPorts("oap");
Assert.assertNotNull(ports);
Assert.assertEquals(3, ports.size());
}
@Test
void isExposedPort() {
boolean result = COMPOSE_FILE.isExposedPort("oap", 5005);
Assert.assertTrue(result);
result = COMPOSE_FILE.isExposedPort("oap", 5006);
Assert.assertFalse(result);
}
}

View File

@ -0,0 +1,44 @@
# 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.
version: '2.1'
services:
oap:
image: skywalking/oap:latest
expose:
- 11800
- 12800
- 5005
networks:
- e2e
restart: on-failure
environment:
SW_CLUSTER_ZK_HOST_PORT: zk:2181
SW_STORAGE_ES_CLUSTER_NODES: es:9200
SW_JDBC_URL: jdbc:mysql://mysql:3306/swtest
SW_STORAGE_INFLUXDB_URL: http://influxdb:8086
JAVA_OPTS: >-
-javaagent:/jacoco/jacocoagent.jar=classdumpdir=/jacoco/classes/oap,destfile=/jacoco/oap.exec,includes=org.apache.skywalking.*,excludes=org.apache.skywalking.oap.query.*:org.apache.skywalking.oap.server.core.query.*
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
healthcheck:
test: ["CMD", "sh", "-c", "nc -zn 127.0.0.1 11800"]
interval: 5s
timeout: 60s
retries: 120
networks:
e2e: {}

View File

@ -21,6 +21,7 @@ services:
expose:
- 11800
- 12800
- 5005
networks:
- e2e
restart: on-failure
@ -34,6 +35,7 @@ services:
SW_STORAGE_INFLUXDB_URL: http://influxdb:8086
JAVA_OPTS: >-
-javaagent:/jacoco/jacocoagent.jar=classdumpdir=/jacoco/classes/oap,destfile=/jacoco/oap.exec,includes=org.apache.skywalking.*,excludes=org.apache.skywalking.oap.query.*:org.apache.skywalking.oap.server.core.query.*
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
healthcheck:
test: ["CMD", "sh", "-c", "nc -zn 127.0.0.1 11800"]
interval: 5s
@ -45,6 +47,7 @@ services:
expose:
- 11800
- 12800
- 5005
networks:
- e2e
restart: on-failure
@ -58,6 +61,7 @@ services:
SW_STORAGE_INFLUXDB_URL: http://influxdb:8086
JAVA_OPTS: >-
-javaagent:/jacoco/jacocoagent.jar=classdumpdir=/jacoco/classes/oap,destfile=/jacoco/oap.exec,includes=org.apache.skywalking.*,excludes=org.apache.skywalking.oap.query.*:org.apache.skywalking.oap.server.core.query.*
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
healthcheck:
test: ["CMD", "sh", "-c", "nc -zn 127.0.0.1 11800"]
interval: 5s
@ -83,6 +87,7 @@ services:
- e2e
expose:
- 9090
- 5005
volumes:
- ../../../jacoco:/jacoco
environment:
@ -90,6 +95,7 @@ services:
JAVA_OPTS: >-
-javaagent:/jacoco/jacocoagent.jar=classdumpdir=/jacoco/classes/provider,destfile=/jacoco/provider.exec,includes=org.apache.skywalking.*,excludes=org.apache.skywalking.apm.dependencies.*
-javaagent:/skywalking/agent/skywalking-agent.jar=logging.output=CONSOLE
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
healthcheck:
test: ["CMD", "sh", "-c", "nc -nz 127.0.0.1 9090"]
interval: 5s
@ -106,6 +112,7 @@ services:
- e2e
expose:
- 9092
- 5005
volumes:
- ../../../jacoco:/jacoco
environment:
@ -113,6 +120,7 @@ services:
JAVA_OPTS: >-
-javaagent:/jacoco/jacocoagent.jar=classdumpdir=/jacoco/classes/consumer,destfile=/jacoco/consumer.exec,includes=org.apache.skywalking.*,excludes=org.apache.skywalking.apm.dependencies.*
-javaagent:/skywalking/agent/skywalking-agent.jar=logging.output=CONSOLE
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
healthcheck:
test: ["CMD", "sh", "-c", "nc -nz 127.0.0.1 9092"]
interval: 5s

View File

@ -38,6 +38,7 @@ services:
JAVA_OPTS: >-
-javaagent:/jacoco/jacocoagent.jar=classdumpdir=/jacoco/classes/provider1,destfile=/jacoco/provider1.exec,includes=org.apache.skywalking.*,excludes=org.apache.skywalking.apm.dependencies.*
-javaagent:/skywalking/agent/skywalking-agent.jar=logging.output=CONSOLE,agent.instance_name=provider1
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
depends_on:
oap1:
condition: service_healthy
@ -52,6 +53,7 @@ services:
JAVA_OPTS: >-
-javaagent:/jacoco/jacocoagent.jar=classdumpdir=/jacoco/classes/provider2,destfile=/jacoco/provider2.exec,includes=org.apache.skywalking.*,excludes=org.apache.skywalking.apm.dependencies.*
-javaagent:/skywalking/agent/skywalking-agent.jar=logging.output=CONSOLE,agent.instance_name=provider2
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
depends_on:
oap2:
condition: service_healthy
@ -67,6 +69,7 @@ services:
JAVA_OPTS: >-
-javaagent:/jacoco/jacocoagent.jar=classdumpdir=/jacoco/classes/consumer,destfile=/jacoco/consumer.exec,includes=org.apache.skywalking.*,excludes=org.apache.skywalking.apm.dependencies.*
-javaagent:/skywalking/agent/skywalking-agent.jar=logging.output=CONSOLE,agent.instance_name=consumer
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
depends_on:
oap1:
condition: service_healthy

View File

@ -40,6 +40,7 @@ services:
SW_STORAGE: elasticsearch
JAVA_OPTS: >-
-javaagent:/jacoco/jacocoagent.jar=classdumpdir=/jacoco/classes/oap1,destfile=/jacoco/oap1.exec,includes=org.apache.skywalking.*,excludes=org.apache.skywalking.oap.query.*:org.apache.skywalking.oap.server.core.query.*
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
depends_on:
zk:
condition: service_healthy
@ -55,6 +56,7 @@ services:
SW_STORAGE: elasticsearch
JAVA_OPTS: >-
-javaagent:/jacoco/jacocoagent.jar=classdumpdir=/jacoco/classes/oap2,destfile=/jacoco/oap2.exec,includes=org.apache.skywalking.*,excludes=org.apache.skywalking.oap.query.*:org.apache.skywalking.oap.server.core.query.*
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
depends_on:
zk:
condition: service_healthy

View File

@ -40,6 +40,7 @@ services:
SW_STORAGE: elasticsearch7
JAVA_OPTS: >-
-javaagent:/jacoco/jacocoagent.jar=classdumpdir=/jacoco/classes/oap1,destfile=/jacoco/oap1.exec,includes=org.apache.skywalking.*,excludes=org.apache.skywalking.oap.query.*:org.apache.skywalking.oap.server.core.query.*
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
depends_on:
zk:
condition: service_healthy
@ -55,6 +56,7 @@ services:
SW_STORAGE: elasticsearch7
JAVA_OPTS: >-
-javaagent:/jacoco/jacocoagent.jar=classdumpdir=/jacoco/classes/oap2,destfile=/jacoco/oap2.exec,includes=org.apache.skywalking.*,excludes=org.apache.skywalking.oap.query.*:org.apache.skywalking.oap.server.core.query.*
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
depends_on:
zk:
condition: service_healthy

View File

@ -37,6 +37,7 @@ services:
SW_STORAGE: influxdb
JAVA_OPTS: >-
-javaagent:/jacoco/jacocoagent.jar=classdumpdir=/jacoco/classes/oap1,destfile=/jacoco/oap1.exec,includes=org.apache.skywalking.*,excludes=org.apache.skywalking.oap.query.*:org.apache.skywalking.oap.server.core.query.*
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
depends_on:
zk:
condition: service_healthy
@ -52,6 +53,7 @@ services:
SW_STORAGE: influxdb
JAVA_OPTS: >-
-javaagent:/jacoco/jacocoagent.jar=classdumpdir=/jacoco/classes/oap2,destfile=/jacoco/oap2.exec,includes=org.apache.skywalking.*,excludes=org.apache.skywalking.oap.query.*:org.apache.skywalking.oap.server.core.query.*
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
depends_on:
zk:
condition: service_healthy

View File

@ -41,6 +41,7 @@ services:
SW_STORAGE: mysql
JAVA_OPTS: >-
-javaagent:/jacoco/jacocoagent.jar=classdumpdir=/jacoco/classes/oap1,destfile=/jacoco/oap1.exec,includes=org.apache.skywalking.*,excludes=org.apache.skywalking.oap.query.*:org.apache.skywalking.oap.server.core.query.*
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
entrypoint: ['sh', '-c', '/download-mysql.sh && /skywalking/docker-entrypoint.sh']
depends_on:
zk:
@ -57,6 +58,7 @@ services:
SW_STORAGE: mysql
JAVA_OPTS: >-
-javaagent:/jacoco/jacocoagent.jar=classdumpdir=/jacoco/classes/oap2,destfile=/jacoco/oap2.exec,includes=org.apache.skywalking.*,excludes=org.apache.skywalking.oap.query.*:org.apache.skywalking.oap.server.core.query.*
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
entrypoint: ['sh', '-c', '/download-mysql.sh && /skywalking/docker-entrypoint.sh']
depends_on:
zk:

View File

@ -52,6 +52,7 @@ services:
SW_STORAGE: elasticsearch
JAVA_OPTS: >-
-javaagent:/jacoco/jacocoagent.jar=classdumpdir=/jacoco/classes/oap1,destfile=/jacoco/oap1.exec,includes=org.apache.skywalking.*,excludes=org.apache.skywalking.oap.query.*:org.apache.skywalking.oap.server.core.query.*
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
volumes:
- ./gateways.yml:/skywalking/config/gateways.yml
depends_on:
@ -69,6 +70,7 @@ services:
SW_STORAGE: elasticsearch
JAVA_OPTS: >-
-javaagent:/jacoco/jacocoagent.jar=classdumpdir=/jacoco/classes/oap2,destfile=/jacoco/oap2.exec,includes=org.apache.skywalking.*,excludes=org.apache.skywalking.oap.query.*:org.apache.skywalking.oap.server.core.query.*
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
volumes:
- ./gateways.yml:/skywalking/config/gateways.yml
depends_on:

View File

@ -41,6 +41,7 @@ services:
JAVA_OPTS: >-
-javaagent:/jacoco/jacocoagent.jar=classdumpdir=/jacoco/classes/provider,destfile=/jacoco/provider.exec,includes=org.apache.skywalking.*,excludes=org.apache.skywalking.apm.dependencies.*
-javaagent:/skywalking/agent/skywalking-agent.jar=logging.output=CONSOLE,agent.authentication=test-token
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
depends_on:
oap:
condition: service_healthy