zipkin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adrianc...@apache.org
Subject [incubator-zipkin] branch collector-normalization updated: backfills scribe metrics assertions
Date Wed, 01 May 2019 04:16:52 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/collector-normalization by this push:
     new 51c4f91  backfills scribe metrics assertions
51c4f91 is described below

commit 51c4f911ff38b56b55b45581466abde073e97c5b
Author: Adrian Cole <acole@pivotal.io>
AuthorDate: Wed May 1 12:16:41 2019 +0800

    backfills scribe metrics assertions
---
 .../collector/scribe/ScribeSpanConsumerTest.java   | 102 +++++++++++++--------
 .../main/java/zipkin2/junit/ZipkinDispatcher.java  |  28 +++---
 .../test/java/zipkin2/junit/ZipkinRuleTest.java    |  13 +--
 3 files changed, 80 insertions(+), 63 deletions(-)

diff --git a/zipkin-collector/scribe/src/test/java/zipkin2/collector/scribe/ScribeSpanConsumerTest.java
b/zipkin-collector/scribe/src/test/java/zipkin2/collector/scribe/ScribeSpanConsumerTest.java
index 10fa92b..567b87f 100644
--- a/zipkin-collector/scribe/src/test/java/zipkin2/collector/scribe/ScribeSpanConsumerTest.java
+++ b/zipkin-collector/scribe/src/test/java/zipkin2/collector/scribe/ScribeSpanConsumerTest.java
@@ -19,9 +19,7 @@ package zipkin2.collector.scribe;
 import java.util.Arrays;
 import java.util.Base64;
 import java.util.concurrent.ExecutionException;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import zipkin2.Call;
 import zipkin2.Callback;
 import zipkin2.CheckResult;
@@ -39,11 +37,9 @@ import zipkin2.v1.V1SpanConverter;
 import static com.google.common.base.Charsets.UTF_8;
 import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.core.Is.isA;
+import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;
 
 public class ScribeSpanConsumerTest {
-
-  @Rule public ExpectedException thrown = ExpectedException.none();
   // scope to scribe as we aren't creating the consumer with the builder.
   InMemoryCollectorMetrics scribeMetrics = new InMemoryCollectorMetrics().forTransport("scribe");
 
@@ -98,16 +94,17 @@ public class ScribeSpanConsumerTest {
     assertThat(storage.getTraces()).containsExactly(asList(v2));
 
     assertThat(scribeMetrics.messages()).isEqualTo(1);
+    assertThat(scribeMetrics.messagesDropped()).isZero();
     assertThat(scribeMetrics.bytes()).isEqualTo(bytes.length);
     assertThat(scribeMetrics.spans()).isEqualTo(1);
+    assertThat(scribeMetrics.spansDropped()).isZero();
   }
 
   @Test
   public void entriesWithoutSpansAreSkipped() throws Exception {
-    SpanConsumer consumer =
-        (callback) -> {
-          throw new AssertionError(); // as we shouldn't get here.
-        };
+    SpanConsumer consumer = (callback) -> {
+      throw new AssertionError(); // as we shouldn't get here.
+    };
 
     ScribeSpanConsumer scribe = newScribeSpanConsumer("zipkin", consumer);
 
@@ -117,8 +114,11 @@ public class ScribeSpanConsumerTest {
 
     scribe.log(asList(entry)).get();
 
+    assertThat(scribeMetrics.messages()).isEqualTo(1);
+    assertThat(scribeMetrics.messagesDropped()).isZero();
     assertThat(scribeMetrics.bytes()).isZero();
     assertThat(scribeMetrics.spans()).isZero();
+    assertThat(scribeMetrics.spansDropped()).isZero();
   }
 
   @Test
@@ -129,10 +129,18 @@ public class ScribeSpanConsumerTest {
     entry.category = "zipkin";
     entry.message = "notbase64";
 
-    thrown.expect(ExecutionException.class); // from dereferenced future
-    thrown.expectCause(isA(IllegalArgumentException.class));
+    try {
+      scribe.log(asList(entry)).get();
+      failBecauseExceptionWasNotThrown(ExecutionException.class);
+    } catch (ExecutionException e) {
+      assertThat(e.getCause()).isInstanceOf(IllegalArgumentException.class);
+    }
 
-    scribe.log(asList(entry)).get();
+    assertThat(scribeMetrics.messages()).isEqualTo(1);
+    assertThat(scribeMetrics.messagesDropped()).isEqualTo(1);
+    assertThat(scribeMetrics.bytes()).isZero();
+    assertThat(scribeMetrics.spans()).isZero();
+    assertThat(scribeMetrics.spansDropped()).isZero();
   }
 
   @Test
@@ -147,10 +155,18 @@ public class ScribeSpanConsumerTest {
     entry.category = "zipkin";
     entry.message = encodedSpan;
 
-    thrown.expect(ExecutionException.class); // from dereferenced future
-    thrown.expectMessage("endpoint was null");
+    try {
+      scribe.log(asList(entry)).get();
+      failBecauseExceptionWasNotThrown(ExecutionException.class);
+    } catch (ExecutionException e) {
+      assertThat(e.getCause()).hasMessage("endpoint was null");
+    }
 
-    scribe.log(asList(entry)).get();
+    assertThat(scribeMetrics.messages()).isEqualTo(1);
+    assertThat(scribeMetrics.messagesDropped()).isZero();
+    assertThat(scribeMetrics.bytes()).isEqualTo(bytes.length);
+    assertThat(scribeMetrics.spans()).isEqualTo(1);
+    assertThat(scribeMetrics.spansDropped()).isEqualTo(1);
   }
 
   /**
@@ -182,6 +198,10 @@ public class ScribeSpanConsumerTest {
 
     scribe.log(asList(entry)).get();
 
+    assertThat(scribeMetrics.messages()).isEqualTo(1);
+    assertThat(scribeMetrics.messagesDropped()).isZero();
+    assertThat(scribeMetrics.bytes()).isEqualTo(bytes.length);
+    assertThat(scribeMetrics.spans()).isEqualTo(1);
     assertThat(scribeMetrics.spansDropped()).isEqualTo(1);
   }
 
@@ -197,34 +217,36 @@ public class ScribeSpanConsumerTest {
     newScribeSpanConsumer(entry.category, consumer).log(asList(entry)).get();
 
     assertThat(storage.getTraces()).containsExactly(asList(v2));
+
+    assertThat(scribeMetrics.messages()).isEqualTo(1);
+    assertThat(scribeMetrics.messagesDropped()).isZero();
+    assertThat(scribeMetrics.bytes())
+      .isEqualTo(Base64.getMimeDecoder().decode(entry.message).length);
+    assertThat(scribeMetrics.spans()).isEqualTo(1);
+    assertThat(scribeMetrics.spansDropped()).isZero();
   }
 
   ScribeSpanConsumer newScribeSpanConsumer(String category, SpanConsumer consumer) {
     return new ScribeSpanConsumer(
-        ScribeCollector.newBuilder()
-            .category(category)
-            .metrics(scribeMetrics)
-            .storage(
-                new StorageComponent() {
-                  @Override
-                  public SpanStore spanStore() {
-                    throw new AssertionError();
-                  }
-
-                  @Override
-                  public SpanConsumer spanConsumer() {
-                    return consumer;
-                  }
-
-                  @Override
-                  public CheckResult check() {
-                    return CheckResult.OK;
-                  }
-
-                  @Override
-                  public void close() {
-                    throw new AssertionError();
-                  }
-                }));
+      ScribeCollector.newBuilder()
+        .category(category)
+        .metrics(scribeMetrics)
+        .storage(new StorageComponent() {
+          @Override public SpanStore spanStore() {
+            throw new AssertionError();
+          }
+
+          @Override public SpanConsumer spanConsumer() {
+            return consumer;
+          }
+
+          @Override public CheckResult check() {
+            return CheckResult.OK;
+          }
+
+          @Override public void close() {
+            throw new AssertionError();
+          }
+        }));
   }
 }
diff --git a/zipkin-junit/src/main/java/zipkin2/junit/ZipkinDispatcher.java b/zipkin-junit/src/main/java/zipkin2/junit/ZipkinDispatcher.java
index 7f1ccda..a79d22b 100644
--- a/zipkin-junit/src/main/java/zipkin2/junit/ZipkinDispatcher.java
+++ b/zipkin-junit/src/main/java/zipkin2/junit/ZipkinDispatcher.java
@@ -66,8 +66,8 @@ final class ZipkinDispatcher extends Dispatcher {
   }
 
   MockResponse acceptSpans(RecordedRequest request, SpanBytesDecoder decoder) {
-    metrics.incrementMessages();
     byte[] body = request.getBody().readByteArray();
+    metrics.incrementMessages();
     String encoding = request.getHeader("Content-Encoding");
     if (encoding != null && encoding.contains("gzip")) {
       try {
@@ -80,23 +80,21 @@ final class ZipkinDispatcher extends Dispatcher {
         return new MockResponse().setResponseCode(400).setBody("Cannot gunzip spans");
       }
     }
+    metrics.incrementBytes(body.length);
 
     final MockResponse result = new MockResponse();
-    consumer.acceptSpans(
-        body,
-        decoder,
-        new Callback<Void>() {
-          @Override
-          public void onSuccess(Void value) {
-            result.setResponseCode(202);
-          }
+    if (body.length == 0) return result.setResponseCode(202); // lenient on empty
 
-          @Override
-          public void onError(Throwable t) {
-            String message = t.getMessage();
-            result.setBody(message).setResponseCode(message.startsWith("Cannot store") ?
500 : 400);
-          }
-        });
+    consumer.acceptSpans(body, decoder, new Callback<Void>() {
+      @Override public void onSuccess(Void value) {
+        result.setResponseCode(202);
+      }
+
+      @Override public void onError(Throwable t) {
+        String message = t.getMessage();
+        result.setBody(message).setResponseCode(message.startsWith("Cannot store") ? 500
: 400);
+      }
+    });
     return result;
   }
 }
diff --git a/zipkin-junit/src/test/java/zipkin2/junit/ZipkinRuleTest.java b/zipkin-junit/src/test/java/zipkin2/junit/ZipkinRuleTest.java
index 0e01c38..be379c7 100644
--- a/zipkin-junit/src/test/java/zipkin2/junit/ZipkinRuleTest.java
+++ b/zipkin-junit/src/test/java/zipkin2/junit/ZipkinRuleTest.java
@@ -178,14 +178,11 @@ public class ZipkinRuleTest {
     gzipSink.close();
     ByteString gzippedJson = sink.readByteString();
 
-    client
-        .newCall(
-            new Request.Builder()
-                .url(zipkin.httpUrl() + "/api/v1/spans")
-                .addHeader("Content-Encoding", "gzip")
-                .post(RequestBody.create(MediaType.parse("application/json"), gzippedJson))
-                .build())
-        .execute();
+    client.newCall(new Request.Builder()
+      .url(zipkin.httpUrl() + "/api/v1/spans")
+      .addHeader("Content-Encoding", "gzip")
+      .post(RequestBody.create(MediaType.parse("application/json"), gzippedJson))
+      .build()).execute();
 
     assertThat(zipkin.collectorMetrics().bytes()).isEqualTo(spansInJson.length);
   }


Mime
View raw message