From 419a41da85c9561f018f27850e392f95d5ab40c6 Mon Sep 17 00:00:00 2001 From: Ashish Date: Mon, 9 Sep 2019 16:12:20 +0530 Subject: [PATCH] blob-makekey-updates --- .../com/expedia/blobs/core/BlobContext.java | 4 +-- .../blobs/core/BlobWriterImplSpec.scala | 2 +- .../blobs/core/io/AsyncSupportSpec.scala | 2 +- .../blobs/server/api/BlobAgentGrpcServer.java | 7 ++---- haystack-blobs/span-blob-context/pom.xml | 25 ++++++++++++++++--- .../expedia/blobs/core/SpanBlobContext.java | 22 ++++++++++------ .../blobs/core/SpanBlobContextSpec.scala | 21 ++-------------- 7 files changed, 45 insertions(+), 38 deletions(-) diff --git a/core/src/main/java/com/expedia/blobs/core/BlobContext.java b/core/src/main/java/com/expedia/blobs/core/BlobContext.java index 7dee234..cd56cbb 100644 --- a/core/src/main/java/com/expedia/blobs/core/BlobContext.java +++ b/core/src/main/java/com/expedia/blobs/core/BlobContext.java @@ -49,11 +49,11 @@ default String getOperationId() { * @return string */ default String makeKey(BlobType type) { - return String.format("%s_%s_%s_%s_%s", + return String.format("%s_%s_%s_%s", getServiceName(), getOperationName(), getOperationId(), - type.getType(), UUID.randomUUID().toString()); + type.getType()); } /** diff --git a/core/src/test/scala/com/expedia/blobs/core/BlobWriterImplSpec.scala b/core/src/test/scala/com/expedia/blobs/core/BlobWriterImplSpec.scala index 639b943..4c3dd29 100644 --- a/core/src/test/scala/com/expedia/blobs/core/BlobWriterImplSpec.scala +++ b/core/src/test/scala/com/expedia/blobs/core/BlobWriterImplSpec.scala @@ -28,7 +28,7 @@ class BlobWriterImplSpec extends FunSpec with GivenWhenThen with BeforeAndAfter captured.hasCaptured should be (true) And("blob's key is generated as expected") val capturedBlob = captured.getValue - """service1_operation1_.*_request_.*""".r.pattern.matcher(capturedBlob.build.getKey).matches() should be (true) + """service1_operation1_.*_request""".r.pattern.matcher(capturedBlob.build.getKey).matches() should be (true) } it("should call store to with a blob object that invokes the callback to serialize blob only " + "the first time when data is fetched") { diff --git a/core/src/test/scala/com/expedia/blobs/core/io/AsyncSupportSpec.scala b/core/src/test/scala/com/expedia/blobs/core/io/AsyncSupportSpec.scala index 078d389..9d01ae8 100644 --- a/core/src/test/scala/com/expedia/blobs/core/io/AsyncSupportSpec.scala +++ b/core/src/test/scala/com/expedia/blobs/core/io/AsyncSupportSpec.scala @@ -68,7 +68,7 @@ class AsyncSupportSpec extends FunSpec with GivenWhenThen with BeforeAndAfter wi } it("should store a blob") { - Given(" a simple blob") + Given("a simple blob") val blob = Support.newBlob() val blobBuilder = mock[BlobWriterImpl.BlobBuilder] diff --git a/haystack-blobs/blobs-agent-server/src/main/java/com/expedia/www/haystack/agent/blobs/server/api/BlobAgentGrpcServer.java b/haystack-blobs/blobs-agent-server/src/main/java/com/expedia/www/haystack/agent/blobs/server/api/BlobAgentGrpcServer.java index fe9abf9..c619d73 100644 --- a/haystack-blobs/blobs-agent-server/src/main/java/com/expedia/www/haystack/agent/blobs/server/api/BlobAgentGrpcServer.java +++ b/haystack-blobs/blobs-agent-server/src/main/java/com/expedia/www/haystack/agent/blobs/server/api/BlobAgentGrpcServer.java @@ -42,10 +42,7 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.StringWriter; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; public class BlobAgentGrpcServer extends BlobAgentGrpc.BlobAgentImplBase { private final Logger LOGGER = LoggerFactory.getLogger(BlobAgentGrpcServer.class); @@ -158,7 +155,7 @@ public void readBlobAsString(final BlobSearch blobSearch, final StreamObserverspan-blob-context jar + + 0.31.0 + + com.expedia.www @@ -18,9 +22,9 @@ ${parent.version} - com.expedia.www - haystack-client-core - ${haystack-client-core.version} + io.opentracing + opentracing-api + ${opentracing.version} @@ -94,6 +98,21 @@ org.jacoco jacoco-maven-plugin + + true + + + CLASS + + + LINE + COVEREDRATIO + 0.00 + + + + + diff --git a/haystack-blobs/span-blob-context/src/main/java/com/expedia/blobs/core/SpanBlobContext.java b/haystack-blobs/span-blob-context/src/main/java/com/expedia/blobs/core/SpanBlobContext.java index 5f8793d..28a4a27 100644 --- a/haystack-blobs/span-blob-context/src/main/java/com/expedia/blobs/core/SpanBlobContext.java +++ b/haystack-blobs/span-blob-context/src/main/java/com/expedia/blobs/core/SpanBlobContext.java @@ -1,6 +1,6 @@ package com.expedia.blobs.core; -import com.expedia.www.haystack.client.Span; +import io.opentracing.Span; import org.apache.commons.lang3.Validate; /** @@ -9,27 +9,35 @@ */ public class SpanBlobContext implements BlobContext { - private Span span; + + private final Span span; + private final String serviceName; private final static String PARTIAL_BLOB_KEY = "-blob"; + private final String operationName; /** * constructor - * @param span for a specific service operation + * @param span span object + * @param serviceName for a specific service name, can't be null or empty + * @param operationName for a specific operation name */ + public SpanBlobContext(Span span, String serviceName, String operationName) { + Validate.notNull(span, "span cannot be null in context"); + Validate.notEmpty(serviceName, "service name cannot be null in context"); - public SpanBlobContext(Span span) { - Validate.notNull(span, "Span cannot be null in context"); this.span = span; + this.serviceName = serviceName; + this.operationName = operationName; } @Override public String getOperationName() { - return span.getOperationName(); + return operationName; } @Override public String getServiceName() { - return span.getServiceName(); + return serviceName; } /** diff --git a/haystack-blobs/span-blob-context/src/test/scala/com/expedia/blobs/core/SpanBlobContextSpec.scala b/haystack-blobs/span-blob-context/src/test/scala/com/expedia/blobs/core/SpanBlobContextSpec.scala index 8a7d9c1..a0d0f2d 100644 --- a/haystack-blobs/span-blob-context/src/test/scala/com/expedia/blobs/core/SpanBlobContextSpec.scala +++ b/haystack-blobs/span-blob-context/src/test/scala/com/expedia/blobs/core/SpanBlobContextSpec.scala @@ -1,35 +1,18 @@ package com.expedia.blobs.core -import com.expedia.www.haystack.client.Tracer -import com.expedia.www.haystack.client.dispatchers.NoopDispatcher -import com.expedia.www.haystack.client.metrics.NoopMetricsRegistry -import org.junit.Assert import org.scalatest.easymock.EasyMockSugar import org.scalatest.{FunSpec, Matchers} class SpanBlobContextSpec extends FunSpec with Matchers with EasyMockSugar { - private val tracer = new Tracer.Builder(new NoopMetricsRegistry, "TestService", new NoopDispatcher).build() - private val span = tracer.buildSpan("TestOperation").start - describe("com.expedia.blobs.core.SpanBlobContext") { it("should throw an error if span is not present") { val catchExpection = intercept[Exception] { - val spanBlobContext: SpanBlobContext = new SpanBlobContext(null) + val _ = new SpanBlobContext(null, "", "") } - catchExpection.getMessage shouldEqual "Span cannot be null in context" - } - - it("should return the correct operation name") { - val operationName = new SpanBlobContext(span).getOperationName - Assert.assertEquals("TestOperation", operationName) - } - - it("should return the correct service name") { - val serviceName = new SpanBlobContext(span).getServiceName - Assert.assertEquals("TestService", serviceName) + catchExpection.getMessage shouldEqual "span cannot be null in context" } } }