forked from mchandramouli/blobs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from ExpediaDotCom/zipkin-blobs
Adding a module for Zipkin-Blobs
- Loading branch information
Showing
8 changed files
with
308 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
haystack-blobs/src/test/scala/com/expedia/www/haystack/client/MockSpanBuilder.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.expedia.www.haystack.client | ||
|
||
import java.util | ||
|
||
object MockSpanBuilder { | ||
def mockSpan(tracer: Tracer, clock: Clock, operationName: String, context: SpanContext, | ||
startTime: Long, tags: util.Map[String, Object], references: util.List[Reference]) : Span = { | ||
new Span(tracer, clock, "span-name", context, | ||
System.currentTimeMillis(), tags, new util.ArrayList[Reference]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>blobs</artifactId> | ||
<groupId>com.expedia.www</groupId> | ||
<version>1.1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>zipkin-blobs</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<zipkin.version>5.9.0</zipkin.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.expedia.www</groupId> | ||
<artifactId>blobs-core</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.zipkin.brave</groupId> | ||
<artifactId>brave</artifactId> | ||
<version>${zipkin.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
</dependency> | ||
|
||
<!-- test --> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-log4j12</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.easymock</groupId> | ||
<artifactId>easymock</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.scala-lang</groupId> | ||
<artifactId>scala-library</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.scala-lang</groupId> | ||
<artifactId>scala-reflect</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.scalatest</groupId> | ||
<artifactId>scalatest_${scala.major.minor.version}</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.pegdown</groupId> | ||
<artifactId>pegdown</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.scalatest</groupId> | ||
<artifactId>scalatest-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>test</id> | ||
<goals> | ||
<goal>test</goal> | ||
</goals> | ||
<configuration> | ||
<tagsToExclude>com.expedia.test.IntegrationSuite</tagsToExclude> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>integration-test</id> | ||
<phase>integration-test</phase> | ||
<goals> | ||
<goal>test</goal> | ||
</goals> | ||
<configuration> | ||
<tagsToInclude>com.expedia.test.IntegrationSuite</tagsToInclude> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>net.alchim31.maven</groupId> | ||
<artifactId>scala-maven-plugin</artifactId> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.scalastyle</groupId> | ||
<artifactId>scalastyle-maven-plugin</artifactId> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
<configuration> | ||
<haltOnFailure>true</haltOnFailure> | ||
<rules> | ||
<rule> | ||
<element>CLASS</element> | ||
<limits> | ||
<limit> | ||
<counter>LINE</counter> | ||
<value>COVEREDRATIO</value> | ||
<minimum>0.00</minimum> | ||
</limit> | ||
</limits> | ||
</rule> | ||
</rules> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
62 changes: 62 additions & 0 deletions
62
zipkin-blobs/src/main/java/brave/blobs/SpanBlobContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package brave.blobs; | ||
|
||
import brave.Span; | ||
import com.expedia.blobs.core.BlobContext; | ||
import com.expedia.blobs.core.BlobType; | ||
import com.expedia.blobs.core.BlobWriter; | ||
import org.apache.commons.lang3.Validate; | ||
|
||
/** | ||
* Class representing a {@link BlobContext} associated with {@link BlobWriter} and uses {@link Span} | ||
* to save blob key produced to be used again for reading | ||
*/ | ||
|
||
public class SpanBlobContext implements BlobContext { | ||
|
||
private final Span span; | ||
private final String remoteServiceName; | ||
private final static String PARTIAL_BLOB_KEY = "-blob"; | ||
private final String name; | ||
|
||
/** | ||
* constructor | ||
* @param span span object | ||
* @param remoteServiceName for a specific service name, can't be null or empty | ||
* @param name for a specific operation name | ||
*/ | ||
public SpanBlobContext(Span span, String remoteServiceName, String name) { | ||
Validate.notNull(span, "span cannot be null in context"); | ||
Validate.notEmpty(remoteServiceName, "remoteServiceName name cannot be null or empty in context"); | ||
Validate.notEmpty(name, "name cannot be null or empty in context"); | ||
|
||
this.span = span; | ||
this.remoteServiceName = remoteServiceName; | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String getOperationName() { | ||
return this.name; | ||
} | ||
|
||
@Override | ||
public String getServiceName() { | ||
return this.remoteServiceName; | ||
} | ||
|
||
@Override | ||
public String getOperationId() { | ||
return String.valueOf(this.span.context().spanId()); | ||
} | ||
|
||
/** | ||
* This will be used to add the key produced inside the span | ||
* for it to be used during the time of reading the blob through the span | ||
* @param blobKey created from {@link SpanBlobContext#makeKey(BlobType)} | ||
* @param blobType value of {@link BlobType} | ||
*/ | ||
@Override | ||
public void onBlobKeyCreate(String blobKey, BlobType blobType) { | ||
span.tag(String.format("%s%s", blobType.getType(), PARTIAL_BLOB_KEY), blobKey); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
zipkin-blobs/src/test/scala/brave/blobs/SpanBlobContextSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package brave.blobs | ||
|
||
import brave.Span | ||
import brave.propagation.TraceContext | ||
import com.expedia.blobs.core.BlobType | ||
import org.easymock.EasyMock.{replay, verify} | ||
import org.scalatest.easymock.EasyMockSugar | ||
import org.scalatest.{FunSpec, Matchers} | ||
|
||
class SpanBlobContextSpec extends FunSpec with Matchers with EasyMockSugar { | ||
|
||
describe("brave.blobs.SpanBlobContext") { | ||
|
||
it("should throw an error if span is not present") { | ||
val catchExpection = intercept[Exception] { | ||
val _ = new SpanBlobContext(null, "", "") | ||
} | ||
|
||
catchExpection.getMessage shouldEqual "span cannot be null in context" | ||
} | ||
|
||
it("should throw an error if serviceName is not present") { | ||
val catchExpection = intercept[Exception] { | ||
val _ = new SpanBlobContext(mock[Span], "", "") | ||
} | ||
|
||
catchExpection.getMessage shouldEqual "remoteServiceName name cannot be null or empty in context" | ||
} | ||
|
||
it("should throw an error if name is not present") { | ||
val catchExpection = intercept[Exception] { | ||
val _ = new SpanBlobContext(mock[Span], "remote-service", "") | ||
} | ||
|
||
catchExpection.getMessage shouldEqual "name cannot be null or empty in context" | ||
} | ||
|
||
it("should add a tag to the Span when onBlobKeyCreate is invoked") { | ||
val span = mock[Span] | ||
val traceContext = TraceContext.newBuilder().traceId(2345678901L).spanId(1234567890L).build() | ||
val spanBlobContext = new SpanBlobContext(span, "remote-service", "span-name") | ||
|
||
expecting { | ||
span.tag("request-blob", "remote-service_span-name_1234567890_request").andReturn(span).once() | ||
span.context().andReturn(traceContext).once() | ||
} | ||
replay(span) | ||
|
||
|
||
spanBlobContext.onBlobKeyCreate(spanBlobContext.makeKey(BlobType.REQUEST), BlobType.REQUEST) | ||
|
||
verify(span) | ||
} | ||
} | ||
} |