Skip to content

Commit 43d3daa

Browse files
authored
Merge pull request #16 from ExpediaDotCom/blob-key-updates
use opentracing span in blob makekey
2 parents e38ac99 + 419a41d commit 43d3daa

File tree

7 files changed

+45
-38
lines changed

7 files changed

+45
-38
lines changed

core/src/main/java/com/expedia/blobs/core/BlobContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ default String getOperationId() {
4949
* @return string
5050
*/
5151
default String makeKey(BlobType type) {
52-
return String.format("%s_%s_%s_%s_%s",
52+
return String.format("%s_%s_%s_%s",
5353
getServiceName(),
5454
getOperationName(),
5555
getOperationId(),
56-
type.getType(), UUID.randomUUID().toString());
56+
type.getType());
5757
}
5858

5959
/**

core/src/test/scala/com/expedia/blobs/core/BlobWriterImplSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class BlobWriterImplSpec extends FunSpec with GivenWhenThen with BeforeAndAfter
2828
captured.hasCaptured should be (true)
2929
And("blob's key is generated as expected")
3030
val capturedBlob = captured.getValue
31-
"""service1_operation1_.*_request_.*""".r.pattern.matcher(capturedBlob.build.getKey).matches() should be (true)
31+
"""service1_operation1_.*_request""".r.pattern.matcher(capturedBlob.build.getKey).matches() should be (true)
3232
}
3333
it("should call store to with a blob object that invokes the callback to serialize blob only " +
3434
"the first time when data is fetched") {

core/src/test/scala/com/expedia/blobs/core/io/AsyncSupportSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class AsyncSupportSpec extends FunSpec with GivenWhenThen with BeforeAndAfter wi
6868
}
6969

7070
it("should store a blob") {
71-
Given(" a simple blob")
71+
Given("a simple blob")
7272
val blob = Support.newBlob()
7373
val blobBuilder = mock[BlobWriterImpl.BlobBuilder]
7474

haystack-blobs/blobs-agent-server/src/main/java/com/expedia/www/haystack/agent/blobs/server/api/BlobAgentGrpcServer.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@
4242
import java.io.ByteArrayInputStream;
4343
import java.io.InputStream;
4444
import java.io.StringWriter;
45-
import java.util.Arrays;
46-
import java.util.List;
47-
import java.util.Map;
48-
import java.util.Optional;
45+
import java.util.*;
4946

5047
public class BlobAgentGrpcServer extends BlobAgentGrpc.BlobAgentImplBase {
5148
private final Logger LOGGER = LoggerFactory.getLogger(BlobAgentGrpcServer.class);
@@ -158,7 +155,7 @@ public void readBlobAsString(final BlobSearch blobSearch, final StreamObserver<F
158155
String parseBlob(ByteString content, String contentType) {
159156
String blob = null;
160157
try {
161-
if (contentType == ContentType.FAST_INFOSET.getType()) {
158+
if (Objects.equals(contentType, ContentType.FAST_INFOSET.getType())) {
162159
blob = parseFastInfosetToString(content);
163160
} else {
164161
blob = IOUtils.toString(content.toByteArray());

haystack-blobs/span-blob-context/pom.xml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,20 @@
1111
<artifactId>span-blob-context</artifactId>
1212
<packaging>jar</packaging>
1313

14+
<properties>
15+
<opentracing.version>0.31.0</opentracing.version>
16+
</properties>
17+
1418
<dependencies>
1519
<dependency>
1620
<groupId>com.expedia.www</groupId>
1721
<artifactId>blobs-core</artifactId>
1822
<version>${parent.version}</version>
1923
</dependency>
2024
<dependency>
21-
<groupId>com.expedia.www</groupId>
22-
<artifactId>haystack-client-core</artifactId>
23-
<version>${haystack-client-core.version}</version>
25+
<groupId>io.opentracing</groupId>
26+
<artifactId>opentracing-api</artifactId>
27+
<version>${opentracing.version}</version>
2428
</dependency>
2529

2630
<!--Test-->
@@ -94,6 +98,21 @@
9498
<plugin>
9599
<groupId>org.jacoco</groupId>
96100
<artifactId>jacoco-maven-plugin</artifactId>
101+
<configuration>
102+
<haltOnFailure>true</haltOnFailure>
103+
<rules>
104+
<rule>
105+
<element>CLASS</element>
106+
<limits>
107+
<limit>
108+
<counter>LINE</counter>
109+
<value>COVEREDRATIO</value>
110+
<minimum>0.00</minimum>
111+
</limit>
112+
</limits>
113+
</rule>
114+
</rules>
115+
</configuration>
97116
</plugin>
98117
</plugins>
99118
</build>

haystack-blobs/span-blob-context/src/main/java/com/expedia/blobs/core/SpanBlobContext.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.expedia.blobs.core;
22

3-
import com.expedia.www.haystack.client.Span;
3+
import io.opentracing.Span;
44
import org.apache.commons.lang3.Validate;
55

66
/**
@@ -9,27 +9,35 @@
99
*/
1010

1111
public class SpanBlobContext implements BlobContext {
12-
private Span span;
12+
13+
private final Span span;
14+
private final String serviceName;
1315
private final static String PARTIAL_BLOB_KEY = "-blob";
16+
private final String operationName;
1417

1518
/**
1619
* constructor
17-
* @param span for a specific service operation
20+
* @param span span object
21+
* @param serviceName for a specific service name, can't be null or empty
22+
* @param operationName for a specific operation name
1823
*/
24+
public SpanBlobContext(Span span, String serviceName, String operationName) {
25+
Validate.notNull(span, "span cannot be null in context");
26+
Validate.notEmpty(serviceName, "service name cannot be null in context");
1927

20-
public SpanBlobContext(Span span) {
21-
Validate.notNull(span, "Span cannot be null in context");
2228
this.span = span;
29+
this.serviceName = serviceName;
30+
this.operationName = operationName;
2331
}
2432

2533
@Override
2634
public String getOperationName() {
27-
return span.getOperationName();
35+
return operationName;
2836
}
2937

3038
@Override
3139
public String getServiceName() {
32-
return span.getServiceName();
40+
return serviceName;
3341
}
3442

3543
/**
Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,18 @@
11
package com.expedia.blobs.core
22

3-
import com.expedia.www.haystack.client.Tracer
4-
import com.expedia.www.haystack.client.dispatchers.NoopDispatcher
5-
import com.expedia.www.haystack.client.metrics.NoopMetricsRegistry
6-
import org.junit.Assert
73
import org.scalatest.easymock.EasyMockSugar
84
import org.scalatest.{FunSpec, Matchers}
95

106
class SpanBlobContextSpec extends FunSpec with Matchers with EasyMockSugar {
117

12-
private val tracer = new Tracer.Builder(new NoopMetricsRegistry, "TestService", new NoopDispatcher).build()
13-
private val span = tracer.buildSpan("TestOperation").start
14-
158
describe("com.expedia.blobs.core.SpanBlobContext") {
169

1710
it("should throw an error if span is not present") {
1811
val catchExpection = intercept[Exception] {
19-
val spanBlobContext: SpanBlobContext = new SpanBlobContext(null)
12+
val _ = new SpanBlobContext(null, "", "")
2013
}
2114

22-
catchExpection.getMessage shouldEqual "Span cannot be null in context"
23-
}
24-
25-
it("should return the correct operation name") {
26-
val operationName = new SpanBlobContext(span).getOperationName
27-
Assert.assertEquals("TestOperation", operationName)
28-
}
29-
30-
it("should return the correct service name") {
31-
val serviceName = new SpanBlobContext(span).getServiceName
32-
Assert.assertEquals("TestService", serviceName)
15+
catchExpection.getMessage shouldEqual "span cannot be null in context"
3316
}
3417
}
3518
}

0 commit comments

Comments
 (0)