Merge pull request #311 from spring-cloud/renaming_child_server_span
Renaming child server span
This commit is contained in:
@@ -103,7 +103,8 @@ public class MessagingApplicationTests extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
private void thenAllSpansHaveTraceIdEqualTo(long traceId) {
|
||||
then(this.integrationTestSpanCollector.hashedSpans.stream().allMatch(span -> span.traceId == traceId)).isTrue();
|
||||
then(this.integrationTestSpanCollector.hashedSpans.stream()
|
||||
.allMatch(span -> span.traceId == traceId)).describedAs("All spans have same trace id").isTrue();
|
||||
}
|
||||
|
||||
private void thenTheSpansHaveProperParentStructure() {
|
||||
@@ -112,20 +113,17 @@ public class MessagingApplicationTests extends AbstractIntegrationTest {
|
||||
Optional<Span> eventSentSpan = findSpanWithAnnotation(Constants.SERVER_SEND);
|
||||
Optional<Span> eventReceivedSpan = findSpanWithAnnotation(Constants.CLIENT_RECV);
|
||||
Optional<Span> lastHttpSpansParent = findLastHttpSpansParent();
|
||||
thenAllSpansArePresent(firstHttpSpan, eventSpans, lastHttpSpansParent, eventSentSpan, eventReceivedSpan);
|
||||
// "http:/parent/" -> "http:/" -> "message:messages" -> "http:/foo" (CS + CR) -> "http:/foo" (SS) -> "http:/foo"
|
||||
// "http:/parent/" -> "home" -> "message:messages" -> "http:/foo" (CS + CR) -> "http:/foo" (SS) -> "foo"
|
||||
Collections.sort(this.integrationTestSpanCollector.hashedSpans, (s1, s2) -> s1.timestamp.compareTo(s2.timestamp));
|
||||
then(this.integrationTestSpanCollector.hashedSpans).hasSize(6);
|
||||
for (int i=0; i<this.integrationTestSpanCollector.hashedSpans.size(); i++) {
|
||||
if (i - 1 >= 0) {
|
||||
Span parent = this.integrationTestSpanCollector.hashedSpans.get(i - 1);
|
||||
Span current = this.integrationTestSpanCollector.hashedSpans.get(i);
|
||||
// there is a pair of spans having cs/cr and ss/sr
|
||||
if (current.id != parent.id) {
|
||||
then(current.parentId).isEqualTo(parent.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
thenAllSpansArePresent(firstHttpSpan, eventSpans, lastHttpSpansParent, eventSentSpan, eventReceivedSpan);
|
||||
then(this.integrationTestSpanCollector.hashedSpans).as("There were 6 spans").hasSize(6);
|
||||
log.info("Checking the parent child structure");
|
||||
List<Optional<Span>> parentChild = this.integrationTestSpanCollector.hashedSpans.stream()
|
||||
.filter(span -> span.parentId != null)
|
||||
.map(span -> this.integrationTestSpanCollector.hashedSpans.stream().filter(span1 -> span1.id == span.parentId).findAny()
|
||||
).collect(Collectors.toList());
|
||||
log.info("List of parents and children " + parentChild);
|
||||
then(parentChild.stream().allMatch(Optional::isPresent)).isTrue();
|
||||
}
|
||||
|
||||
private Optional<Span> findLastHttpSpansParent() {
|
||||
@@ -148,12 +146,21 @@ public class MessagingApplicationTests extends AbstractIntegrationTest {
|
||||
|
||||
private Optional<Span> findFirstHttpRequestSpan() {
|
||||
return this.integrationTestSpanCollector.hashedSpans.stream()
|
||||
.filter(span -> "http:/".equals(span.name) && span.parentId != null).findFirst();
|
||||
// home is the name of the method
|
||||
.filter(span -> "home".equals(span.name)).findFirst();
|
||||
}
|
||||
|
||||
private void thenAllSpansArePresent(Optional<Span> firstHttpSpan,
|
||||
List<Span> eventSpans, Optional<Span> lastHttpSpan,
|
||||
Optional<Span> eventSentSpan, Optional<Span> eventReceivedSpan) {
|
||||
log.info("Found following spans");
|
||||
log.info("First http span " + firstHttpSpan);
|
||||
log.info("Event spans " + eventSpans);
|
||||
log.info("Event sent span " + eventSentSpan);
|
||||
log.info("Event received span " + eventReceivedSpan);
|
||||
log.info("Last http span " + lastHttpSpan);
|
||||
log.info("All found spans \n" + this.integrationTestSpanCollector.hashedSpans
|
||||
.stream().map(Span::toString).collect(Collectors.joining("\n")));
|
||||
then(firstHttpSpan.isPresent()).isTrue();
|
||||
then(eventSpans).isNotEmpty();
|
||||
then(eventSentSpan.isPresent()).isTrue();
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package tools;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -23,6 +24,9 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.jayway.awaitility.Awaitility;
|
||||
import com.jayway.awaitility.core.ConditionFactory;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.After;
|
||||
@@ -35,9 +39,6 @@ import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.jayway.awaitility.Awaitility;
|
||||
import com.jayway.awaitility.core.ConditionFactory;
|
||||
|
||||
import zipkin.Codec;
|
||||
import zipkin.Span;
|
||||
|
||||
@@ -49,7 +50,7 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
*/
|
||||
public abstract class AbstractIntegrationTest {
|
||||
|
||||
private static final Log log = LogFactory.getLog(AbstractIntegrationTest.class);
|
||||
protected static final Log log = LogFactory.getLog(MethodHandles.lookup().lookupClass());
|
||||
|
||||
protected static final int POLL_INTERVAL = 1;
|
||||
protected static final int TIMEOUT = 20;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package integration;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -22,6 +23,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@@ -33,8 +35,10 @@ import org.springframework.cloud.sleuth.zipkin.ZipkinProperties;
|
||||
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
import integration.ZipkinTests.WaitUntilZipkinIsUpConfig;
|
||||
import sample.SampleZipkinApplication;
|
||||
@@ -52,13 +56,22 @@ public class ZipkinTests extends AbstractIntegrationTest {
|
||||
@Value("${local.server.port}")
|
||||
private int port = 3380;
|
||||
private String sampleAppUrl = "http://localhost:" + this.port;
|
||||
@Autowired ZipkinProperties zipkinProperties;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
ZipkinServer.main(new String[] { "--server.port=9411" });
|
||||
ZipkinServer.main(new String[] { "--server.port=" + getPortFromProps() });
|
||||
await().until(zipkinQueryServerIsUp());
|
||||
}
|
||||
|
||||
@Override protected int getZipkinServerPort() {
|
||||
return getPortFromProps();
|
||||
}
|
||||
|
||||
private int getPortFromProps() {
|
||||
return URI.create(this.zipkinProperties.getBaseUrl()).getPort();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_propagate_spans_to_zipkin() {
|
||||
long traceId = new Random().nextLong();
|
||||
@@ -79,6 +92,15 @@ public class ZipkinTests extends AbstractIntegrationTest {
|
||||
|
||||
private static final Log log = LogFactory.getLog(WaitUntilZipkinIsUpConfig.class);
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
ZipkinProperties testZipkinProperties() {
|
||||
int freePort = SocketUtils.findAvailableTcpPort();
|
||||
ZipkinProperties zipkinProperties = new ZipkinProperties();
|
||||
zipkinProperties.setBaseUrl("http://localhost:" + freePort);
|
||||
return zipkinProperties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ZipkinSpanReporter spanCollector(final ZipkinProperties zipkin,
|
||||
final SpanMetricReporter spanMetricReporter) {
|
||||
|
||||
Reference in New Issue
Block a user