Add go2sky correlation context E2E test (#6590)
This commit is contained in:
parent
9b4766e491
commit
fdab7f06a1
|
|
@ -33,6 +33,14 @@
|
|||
|
||||
<artifactId>e2e-service-consumer</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.skywalking</groupId>
|
||||
<artifactId>apm-toolkit-trace</artifactId>
|
||||
<version>${sw.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
|
|
|||
|
|
@ -19,11 +19,8 @@
|
|||
package org.apache.skywalking.e2e.controller;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.skywalking.apm.toolkit.trace.TraceContext;
|
||||
import org.apache.skywalking.e2e.E2EConfiguration;
|
||||
import org.apache.skywalking.e2e.User;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
|
@ -32,6 +29,11 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class UserController {
|
||||
|
|
@ -67,6 +69,16 @@ public class UserController {
|
|||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@PostMapping("/correlation")
|
||||
public String correlation() throws InterruptedException {
|
||||
Thread.sleep(randomSleepLong(sleepMin, sleepMax));
|
||||
TraceContext.putCorrelation("CONSUMER_KEY", "consumer");
|
||||
|
||||
String baseUrl = configuration.getProviderBaseUrl();
|
||||
ResponseEntity<String> resp = restTemplate.postForEntity(baseUrl + "/correlation", null, String.class);
|
||||
return resp.getBody();
|
||||
}
|
||||
|
||||
private long randomSleepLong(int min, int max) {
|
||||
Random rand = new Random();
|
||||
int randomNumber = rand.nextInt((max - min) + 1) + min;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
package org.apache.skywalking.e2e.controller;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.skywalking.apm.toolkit.trace.TraceContext;
|
||||
import org.apache.skywalking.e2e.User;
|
||||
import org.apache.skywalking.e2e.UserRepo;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
|
@ -47,6 +48,15 @@ public class UserController {
|
|||
return userRepo.save(user);
|
||||
}
|
||||
|
||||
@PostMapping("/correlation")
|
||||
public String correlation() throws InterruptedException {
|
||||
Thread.sleep(randomSleepLong(sleepMin, sleepMax));
|
||||
TraceContext.putCorrelation("PROVIDER_KEY", "provider");
|
||||
return TraceContext.getCorrelation("CONSUMER_KEY").orElse("") + "_"
|
||||
+ TraceContext.getCorrelation("MIDDLE_KEY").orElse("") + "_"
|
||||
+ TraceContext.getCorrelation("PROVIDER_KEY").orElse("");
|
||||
}
|
||||
|
||||
private long randomSleepLong(int min, int max) {
|
||||
Random rand = new Random();
|
||||
int randomNumber = rand.nextInt((max - min) + 1) + min;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
FROM golang:1.12 AS builder
|
||||
|
||||
ARG COMMIT_HASH=38c3b84741dd6c0609965e9df0fcc633915d3ea5
|
||||
ARG COMMIT_HASH=9094186ac3782482a85dbca47978651bec268e97
|
||||
ARG GO2SKY_CODE=${COMMIT_HASH}.tar.gz
|
||||
ARG GO2SKY_CODE_URL=https://github.com/SkyAPM/go2sky/archive/${GO2SKY_CODE}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ services:
|
|||
condition: service_healthy
|
||||
java-provider:
|
||||
condition: service_healthy
|
||||
command: ['--grpc', '--oap-server', 'oap:11800', '--upstream-url', 'http://java-provider:9090/info']
|
||||
command: ['--grpc', '--oap-server', 'oap:11800', '--upstream-url', 'http://java-provider:9090/correlation']
|
||||
healthcheck:
|
||||
test: ["CMD", "sh", "-c", "nc -z 127.0.0.1 8080"]
|
||||
interval: 5s
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
package org.apache.skywalking.e2e;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.skywalking.e2e.annotation.ContainerHostAndPort;
|
||||
import org.apache.skywalking.e2e.annotation.DockerCompose;
|
||||
|
|
@ -50,10 +49,15 @@ import org.apache.skywalking.e2e.topo.Topology;
|
|||
import org.apache.skywalking.e2e.trace.Trace;
|
||||
import org.apache.skywalking.e2e.trace.TracesMatcher;
|
||||
import org.apache.skywalking.e2e.trace.TracesQuery;
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.testcontainers.containers.DockerComposeContainer;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.skywalking.e2e.metrics.MetricsMatcher.verifyMetrics;
|
||||
import static org.apache.skywalking.e2e.metrics.MetricsMatcher.verifyPercentileMetrics;
|
||||
import static org.apache.skywalking.e2e.metrics.MetricsQuery.ALL_ENDPOINT_METRICS;
|
||||
|
|
@ -93,7 +97,7 @@ public class GOE2E extends SkyWalkingTestAdapter {
|
|||
@BeforeAll
|
||||
public void setUp() throws Exception {
|
||||
queryClient(swWebappHostPort);
|
||||
trafficController(javaConsumerHostPort, "/info");
|
||||
trafficController(javaConsumerHostPort, "/correlation");
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
|
|
@ -159,6 +163,16 @@ public class GOE2E extends SkyWalkingTestAdapter {
|
|||
verifyServiceInstanceRelationMetrics(topology.getCalls());
|
||||
}
|
||||
|
||||
@RetryableTest
|
||||
void correlation() throws Exception {
|
||||
final URL url = new URL("http", javaConsumerHostPort.host(), javaConsumerHostPort.port(), "/correlation");
|
||||
|
||||
ResponseEntity<String> resp = restTemplate.postForEntity(url.toURI(), trafficData, String.class);
|
||||
LOGGER.info("verifying correlation: {}", resp);
|
||||
|
||||
Assert.assertEquals("consumer_go2sky_provider", resp.getBody());
|
||||
}
|
||||
|
||||
private Instances verifyServiceInstances(final Service service) throws Exception {
|
||||
final Instances instances = graphql.instances(
|
||||
new InstancesQuery().serviceId(service.getKey()).start(startTime).end(now())
|
||||
|
|
|
|||
|
|
@ -14,5 +14,5 @@
|
|||
# limitations under the License.
|
||||
|
||||
endpoints:
|
||||
- key: ZTJlLXNlcnZpY2UtamF2YS1jb25zdW1lcg==.1_L2luZm8=
|
||||
label: /info
|
||||
- key: ZTJlLXNlcnZpY2UtamF2YS1jb25zdW1lcg==.1_L2NvcnJlbGF0aW9u
|
||||
label: /correlation
|
||||
|
|
@ -14,5 +14,5 @@
|
|||
# limitations under the License.
|
||||
|
||||
endpoints:
|
||||
- key: Z28yc2t5.1_L1BPU1QvaW5mbw==
|
||||
label: /POST/info
|
||||
- key: Z28yc2t5.1_L1BPU1QvY29ycmVsYXRpb24=
|
||||
label: /POST/correlation
|
||||
|
|
@ -14,5 +14,5 @@
|
|||
# limitations under the License.
|
||||
|
||||
endpoints:
|
||||
- key: ZTJlLXNlcnZpY2UtamF2YS1wcm92aWRlcg==.1_L2luZm8=
|
||||
label: /info
|
||||
- key: ZTJlLXNlcnZpY2UtamF2YS1wcm92aWRlcg==.1_L2NvcnJlbGF0aW9u
|
||||
label: /correlation
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
traces:
|
||||
- key: not null
|
||||
endpointNames:
|
||||
- /info
|
||||
- /correlation
|
||||
duration: ge 0
|
||||
start: gt 0
|
||||
isError: false
|
||||
|
|
|
|||
Loading…
Reference in New Issue