zipkin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adrianc...@apache.org
Subject [incubator-zipkin-brave-cassandra] branch master updated: Fixes integration test setup and propagation bug (#20)
Date Mon, 18 Mar 2019 05:00:13 GMT
This is an automated email from the ASF dual-hosted git repository.

adriancole pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-zipkin-brave-cassandra.git


The following commit(s) were added to refs/heads/master by this push:
     new 228c18f  Fixes integration test setup and propagation bug (#20)
228c18f is described below

commit 228c18f3c93a90a867c2778130359d51ccbcf278
Author: Adrian Cole <adriancole@users.noreply.github.com>
AuthorDate: Mon Mar 18 13:00:07 2019 +0800

    Fixes integration test setup and propagation bug (#20)
    
    There was a propagation bug that resulted in cassandra server not
    continuing inbound traces. This was hidden by incorrect integration
    test setup.
---
 Jenkinsfile                                        |  2 +-
 .../brave/cassandra/driver/ITTracingSession.java   | 23 +++++----
 .../src/main/java/brave/cassandra/Tracing.java     |  5 +-
 .../src/test/java/brave/cassandra/ITTracing.java   |  5 +-
 .../src/test/java/brave/cassandra/TracingTest.java | 56 ++++++++++++++++++++++
 pom.xml                                            | 44 ++++++++++++++++-
 6 files changed, 118 insertions(+), 17 deletions(-)

diff --git a/Jenkinsfile b/Jenkinsfile
index 599f06d..c107b02 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -69,7 +69,7 @@ pipeline {
 
     post {
         always {
-            junit '**/target/surefire-reports/*.xml'
+            junit '**/target/surefire-reports/*.xml **/target/failsafe-reports/*.xml'
             deleteDir()
         }
 
diff --git a/cassandra-driver/src/test/java/brave/cassandra/driver/ITTracingSession.java b/cassandra-driver/src/test/java/brave/cassandra/driver/ITTracingSession.java
index f28f40e..67d69c3 100644
--- a/cassandra-driver/src/test/java/brave/cassandra/driver/ITTracingSession.java
+++ b/cassandra-driver/src/test/java/brave/cassandra/driver/ITTracingSession.java
@@ -19,6 +19,7 @@ package brave.cassandra.driver;
 import brave.SpanCustomizer;
 import brave.Tracer;
 import brave.Tracing;
+import brave.propagation.B3SingleFormat;
 import brave.propagation.StrictScopeDecorator;
 import brave.propagation.ThreadLocalCurrentTraceContext;
 import brave.sampler.Sampler;
@@ -29,8 +30,7 @@ import com.datastax.driver.core.ResultSet;
 import com.datastax.driver.core.ResultSetFuture;
 import com.datastax.driver.core.Session;
 import com.datastax.driver.core.Statement;
-import com.datastax.driver.core.exceptions.NoHostAvailableException;
-import java.nio.ByteBuffer;
+import com.datastax.driver.core.exceptions.DriverInternalError;
 import java.util.Collections;
 import java.util.concurrent.ConcurrentLinkedDeque;
 import org.junit.After;
@@ -40,6 +40,7 @@ import org.junit.Test;
 import zipkin2.Endpoint;
 import zipkin2.Span;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.entry;
 import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;
@@ -106,8 +107,7 @@ public class ITTracingSession {
 
     session.execute("SELECT * from system.schema_keyspaces");
 
-    assertThat(CustomPayloadCaptor.ref.get().keySet())
-        .containsExactly("X-B3-SpanId", "X-B3-Sampled", "X-B3-TraceId");
+    assertThat(CustomPayloadCaptor.ref.get().keySet()).containsOnly("b3");
   }
 
   @Test
@@ -118,8 +118,7 @@ public class ITTracingSession {
 
     invokeBoundStatement();
 
-    assertThat(CustomPayloadCaptor.ref.get().keySet())
-        .containsExactly("X-B3-SpanId", "X-B3-Sampled", "X-B3-TraceId");
+    assertThat(CustomPayloadCaptor.ref.get().keySet()).containsOnly("b3");
   }
 
   @Test
@@ -141,9 +140,9 @@ public class ITTracingSession {
 
     invokeBoundStatement();
 
-    assertThat(CustomPayloadCaptor.ref.get().get("X-B3-Sampled"))
-        .extracting(ByteBuffer::get)
-        .isEqualTo((byte) '0');
+    assertThat(CustomPayloadCaptor.ref.get().get("b3"))
+        .extracting(b -> B3SingleFormat.parseB3SingleFormat(UTF_8.decode(b)).sampled())
+        .isEqualTo(Boolean.FALSE);
   }
 
   @Test
@@ -166,8 +165,8 @@ public class ITTracingSession {
 
     try {
       invokeBoundStatement();
-      failBecauseExceptionWasNotThrown(NoHostAvailableException.class);
-    } catch (NoHostAvailableException e) {
+      failBecauseExceptionWasNotThrown(DriverInternalError.class);
+    } catch (DriverInternalError e) {
     }
 
     assertThat(spans).hasSize(1);
@@ -179,7 +178,7 @@ public class ITTracingSession {
 
     assertThat(spans)
         .flatExtracting(s -> s.tags().entrySet())
-        .containsOnlyOnce(entry("error", "All host(s) tried for query failed (no host was
tried)"));
+        .containsOnlyOnce(entry("error", "Could not send request, session is closed"));
   }
 
   @Test
diff --git a/cassandra/src/main/java/brave/cassandra/Tracing.java b/cassandra/src/main/java/brave/cassandra/Tracing.java
index 1cb9c1e..224f247 100644
--- a/cassandra/src/main/java/brave/cassandra/Tracing.java
+++ b/cassandra/src/main/java/brave/cassandra/Tracing.java
@@ -33,6 +33,7 @@ import zipkin2.reporter.AsyncReporter;
 import zipkin2.reporter.urlconnection.URLConnectionSender;
 
 import static brave.Span.Kind.SERVER;
+import static java.nio.charset.StandardCharsets.UTF_8;
 
 /**
  * This creates Zipkin server spans for incoming cassandra requests. Spans are created when
there's
@@ -96,9 +97,9 @@ public class Tracing extends org.apache.cassandra.tracing.Tracing {
 
   /** This extracts the RPC span encoded in the custom payload, or starts a new trace */
   Span spanFromPayload(Tracer tracer, @Nullable Map<String, ByteBuffer> payload) {
-    ByteBuffer b3 = payload.get("b3");
+    ByteBuffer b3 = payload != null ? payload.get("b3") : null;
     if (b3 == null) return tracer.nextSpan();
-    TraceContextOrSamplingFlags extracted = B3SingleFormat.parseB3SingleFormat(b3.asCharBuffer());
+    TraceContextOrSamplingFlags extracted = B3SingleFormat.parseB3SingleFormat(UTF_8.decode(b3));
     if (extracted == null) return tracer.nextSpan();
     return tracer.nextSpan(extracted);
   }
diff --git a/cassandra/src/test/java/brave/cassandra/ITTracing.java b/cassandra/src/test/java/brave/cassandra/ITTracing.java
index d8e3ce7..e35b51e 100644
--- a/cassandra/src/test/java/brave/cassandra/ITTracing.java
+++ b/cassandra/src/test/java/brave/cassandra/ITTracing.java
@@ -17,6 +17,7 @@
 package brave.cassandra;
 
 import brave.ScopedSpan;
+import brave.cassandra.driver.CassandraClientTracing;
 import brave.cassandra.driver.TracingSession;
 import brave.propagation.StrictScopeDecorator;
 import brave.propagation.ThreadLocalCurrentTraceContext;
@@ -153,11 +154,13 @@ public class ITTracing {
   }
 
   void executeTraced(Function<Session, Statement> statement) {
+    CassandraClientTracing withPropagation = CassandraClientTracing.newBuilder(tracing)
+        .propagationEnabled(true).build();
     try (Cluster cluster =
             Cluster.builder()
                 .addContactPointsWithPorts(Collections.singleton(cassandra.contactPoint()))
                 .build();
-        Session session = TracingSession.create(tracing, cluster.connect())) {
+        Session session = TracingSession.create(withPropagation, cluster.connect())) {
       session.execute(statement.apply(session));
     }
   }
diff --git a/cassandra/src/test/java/brave/cassandra/TracingTest.java b/cassandra/src/test/java/brave/cassandra/TracingTest.java
new file mode 100644
index 0000000..b6eb216
--- /dev/null
+++ b/cassandra/src/test/java/brave/cassandra/TracingTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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 brave.cassandra;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.junit.After;
+import org.junit.Test;
+import zipkin2.Span;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class TracingTest {
+  List<Span> spans = new ArrayList<>();
+  brave.Tracing tracing = brave.Tracing.newBuilder()
+      .spanReporter(spans::add)
+      .build();
+  Tracing cassandraTracing = new Tracing(tracing);
+
+  @After public void tearDown() {
+    tracing.close();
+  }
+
+  @Test public void spanFromPayload_startsTraceOnNullPayload() {
+    assertThat(cassandraTracing.spanFromPayload(tracing.tracer(), null))
+        .isNotNull();
+  }
+
+  @Test public void spanFromPayload_startsTraceOnAbsentB3SingleEntry() {
+    assertThat(cassandraTracing.spanFromPayload(tracing.tracer(), Collections.emptyMap()))
+        .isNotNull();
+  }
+
+  @Test public void spanFromPayload_resumesTraceOnB3SingleEntry() {
+    assertThat(cassandraTracing.spanFromPayload(tracing.tracer(), Collections.singletonMap("b3",
+        ByteBuffer.wrap(new byte[] {'0'}))))
+        .extracting(b -> b.isNoop())
+        .isEqualTo(Boolean.TRUE);
+  }
+}
diff --git a/pom.xml b/pom.xml
index 0b4493a..e9a3ad5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,6 +48,8 @@
     <main.basedir>${project.basedir}</main.basedir>
     <brave.version>5.6.3</brave.version>
 
+    <log4j.version>2.11.2</log4j.version>
+
     <!-- override to set exclusions per-project -->
     <errorprone.args />
     <errorprone.version>2.3.3</errorprone.version>
@@ -145,6 +147,12 @@
           </exclusion>
         </exclusions>
       </dependency>
+      <!-- Override until Cassandra 4.0 per CASSANDRA-9608 -->
+      <dependency>
+        <groupId>com.github.jbellis</groupId>
+        <artifactId>jamm</artifactId>
+        <version>0.3.3</version>
+      </dependency>
       <dependency>
         <groupId>com.datastax.cassandra</groupId>
         <artifactId>cassandra-driver-core</artifactId>
@@ -160,6 +168,22 @@
         <artifactId>assertj-core</artifactId>
         <version>3.12.1</version>
       </dependency>
+      <dependency>
+        <groupId>org.apache.logging.log4j</groupId>
+        <artifactId>log4j-core</artifactId>
+        <version>${log4j.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.logging.log4j</groupId>
+        <artifactId>log4j-slf4j-impl</artifactId>
+        <version>${log4j.version}</version>
+        <exclusions>
+          <exclusion>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+          </exclusion>
+        </exclusions>
+      </dependency>
     </dependencies>
   </dependencyManagement>
 
@@ -179,9 +203,13 @@
       <artifactId>assertj-core</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-slf4j-impl</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
-
   <build>
     <pluginManagement>
       <plugins>
@@ -251,6 +279,20 @@
       <plugin>
         <artifactId>maven-failsafe-plugin</artifactId>
         <version>${maven-failsafe-plugin.version}</version>
+        <executions>
+          <execution>
+            <id>integration-test</id>
+            <goals>
+              <goal>integration-test</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>verify</id>
+            <goals>
+              <goal>verify</goal>
+            </goals>
+          </execution>
+        </executions>
       </plugin>
 
       <plugin>


Mime
View raw message