From d085b65a82599840236c74183e587d92ce3775fa Mon Sep 17 00:00:00 2001 From: jeffbaker Date: Mon, 1 Oct 2018 12:02:20 -0700 Subject: [PATCH] If the "service" tag exists in the span, send it to ElasticSearch and use it in the auxiliary tags when merging spans, instead of the span's service name. Also clean up pom.xml dependencies to fix some warnings. --- .../ServiceMetadataStatementBuilder.scala | 6 ++++-- .../writers/es/IndexDocumentGenerator.scala | 8 +++++--- pom.xml | 15 --------------- .../trace/reader/readers/utils/SpanMerger.scala | 12 ++++++++---- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/indexer/src/main/scala/com/expedia/www/haystack/trace/indexer/writers/cassandra/ServiceMetadataStatementBuilder.scala b/indexer/src/main/scala/com/expedia/www/haystack/trace/indexer/writers/cassandra/ServiceMetadataStatementBuilder.scala index afb56d01..fec9d0d6 100644 --- a/indexer/src/main/scala/com/expedia/www/haystack/trace/indexer/writers/cassandra/ServiceMetadataStatementBuilder.scala +++ b/indexer/src/main/scala/com/expedia/www/haystack/trace/indexer/writers/cassandra/ServiceMetadataStatementBuilder.scala @@ -22,6 +22,7 @@ import java.time.Instant import com.datastax.driver.core.Statement import com.expedia.open.tracing.Span import com.expedia.www.haystack.trace.commons.clients.cassandra.CassandraSession +import com.expedia.www.haystack.trace.commons.utils.SpanUtils import com.expedia.www.haystack.trace.indexer.config.entities.ServiceMetadataWriteConfiguration import org.apache.commons.lang3.StringUtils @@ -72,8 +73,9 @@ class ServiceMetadataStatementBuilder(cassandra: CassandraSession, def getAndUpdateServiceMetadata(spans: Iterable[Span]): Seq[Statement] = { this.synchronized { spans.foreach(span => { - if (StringUtils.isNotEmpty(span.getServiceName) && StringUtils.isNotEmpty(span.getOperationName)) { - val operationsList = serviceMetadataMap.getOrElseUpdate(span.getServiceName, mutable.Set[String]()) + val serviceName = SpanUtils.getEffectiveServiceName(span) + if (StringUtils.isNotEmpty(serviceName) && StringUtils.isNotEmpty(span.getOperationName)) { + val operationsList = serviceMetadataMap.getOrElseUpdate(serviceName, mutable.Set[String]()) if (operationsList.add(span.getOperationName)) { allOperationCount += 1 } diff --git a/indexer/src/main/scala/com/expedia/www/haystack/trace/indexer/writers/es/IndexDocumentGenerator.scala b/indexer/src/main/scala/com/expedia/www/haystack/trace/indexer/writers/es/IndexDocumentGenerator.scala index 4579d7ce..f8fc8d2b 100644 --- a/indexer/src/main/scala/com/expedia/www/haystack/trace/indexer/writers/es/IndexDocumentGenerator.scala +++ b/indexer/src/main/scala/com/expedia/www/haystack/trace/indexer/writers/es/IndexDocumentGenerator.scala @@ -26,6 +26,7 @@ import com.expedia.www.haystack.trace.commons.clients.es.document.TraceIndexDoc import com.expedia.www.haystack.trace.commons.clients.es.document.TraceIndexDoc.{OPERATION_KEY_NAME, SERVICE_KEY_NAME, TagValue} import com.expedia.www.haystack.trace.commons.config.entities.IndexFieldType.IndexFieldType import com.expedia.www.haystack.trace.commons.config.entities.{IndexFieldType, WhitelistIndexFieldConfiguration} +import com.expedia.www.haystack.trace.commons.utils.SpanUtils import org.apache.commons.lang3.StringUtils import scala.collection.JavaConverters._ @@ -53,11 +54,12 @@ class IndexDocumentGenerator(config: WhitelistIndexFieldConfiguration) extends M traceStartTime = Math.min(traceStartTime, microsToSecondGranularity(span.getStartTime)) if(span.getParentSpanId == null) rootDuration = span.getDuration + val serviceName = SpanUtils.getEffectiveServiceName(span) val spanIndexDoc = spanIndices - .find(sp => sp(OPERATION_KEY_NAME).equals(span.getOperationName) && sp(SERVICE_KEY_NAME).equals(span.getServiceName)) + .find(sp => sp(OPERATION_KEY_NAME).equals(span.getOperationName) && sp(SERVICE_KEY_NAME).equals(serviceName)) .getOrElse({ val newSpanIndexDoc = mutable.Map[String, Any]( - SERVICE_KEY_NAME -> span.getServiceName, + SERVICE_KEY_NAME -> serviceName, OPERATION_KEY_NAME -> span.getOperationName) spanIndices.append(newSpanIndexDoc) newSpanIndexDoc @@ -68,7 +70,7 @@ class IndexDocumentGenerator(config: WhitelistIndexFieldConfiguration) extends M } private def isValidForIndex(span: Span): Boolean = { - StringUtils.isNotEmpty(span.getServiceName) && StringUtils.isNotEmpty(span.getOperationName) + StringUtils.isNotEmpty(SpanUtils.getEffectiveServiceName(span)) && StringUtils.isNotEmpty(span.getOperationName) } /** diff --git a/pom.xml b/pom.xml index 26a64655..fe3a8dbe 100644 --- a/pom.xml +++ b/pom.xml @@ -251,21 +251,6 @@ config - - com.google.protobuf - protobuf-java - - - - io.grpc - grpc-protobuf - - - - io.grpc - grpc-stub - - org.scala-lang scala-library diff --git a/reader/src/main/scala/com/expedia/www/haystack/trace/reader/readers/utils/SpanMerger.scala b/reader/src/main/scala/com/expedia/www/haystack/trace/reader/readers/utils/SpanMerger.scala index f1ada41c..fddbd0eb 100644 --- a/reader/src/main/scala/com/expedia/www/haystack/trace/reader/readers/utils/SpanMerger.scala +++ b/reader/src/main/scala/com/expedia/www/haystack/trace/reader/readers/utils/SpanMerger.scala @@ -53,8 +53,12 @@ object SpanMerger { Span .newBuilder(serverSpan) .setParentSpanId(clientSpan.getParentSpanId) // use the parentSpanId of the client span to stitch in the client's trace tree - .addAllTags((clientSpan.getTagsList.asScala ++ auxiliaryCommonTags(clientSpan, serverSpan) ++ auxiliaryClientTags(clientSpan) ++ auxiliaryServerTags(serverSpan)).asJavaCollection) - .clearLogs().addAllLogs((clientSpan.getLogsList.asScala ++ serverSpan.getLogsList.asScala.sortBy(_.getTimestamp)).asJavaCollection) + .addAllTags((clientSpan.getTagsList.asScala + ++ auxiliaryCommonTags(clientSpan, serverSpan) + ++ auxiliaryClientTags(clientSpan) + ++ auxiliaryServerTags(serverSpan)).asJavaCollection) + .clearLogs().addAllLogs((clientSpan.getLogsList.asScala + ++ serverSpan.getLogsList.asScala.sortBy(_.getTimestamp)).asJavaCollection) .build() } @@ -108,7 +112,7 @@ object SpanMerger { private def auxiliaryClientTags(span: Span): List[Tag] = List( - buildStringTag(AuxiliaryTags.CLIENT_SERVICE_NAME, span.getServiceName), + buildStringTag(AuxiliaryTags.CLIENT_SERVICE_NAME, SpanUtils.getEffectiveServiceName(span)), buildStringTag(AuxiliaryTags.CLIENT_OPERATION_NAME, span.getOperationName), buildStringTag(AuxiliaryTags.CLIENT_INFRASTRUCTURE_PROVIDER, extractTagStringValue(span, AuxiliaryTags.INFRASTRUCTURE_PROVIDER)), buildStringTag(AuxiliaryTags.CLIENT_INFRASTRUCTURE_LOCATION, extractTagStringValue(span, AuxiliaryTags.INFRASTRUCTURE_LOCATION)), @@ -118,7 +122,7 @@ object SpanMerger { private def auxiliaryServerTags(span: Span): List[Tag] = { List( - buildStringTag(AuxiliaryTags.SERVER_SERVICE_NAME, span.getServiceName), + buildStringTag(AuxiliaryTags.SERVER_SERVICE_NAME, SpanUtils.getEffectiveServiceName(span)), buildStringTag(AuxiliaryTags.SERVER_OPERATION_NAME, span.getOperationName), buildStringTag(AuxiliaryTags.SERVER_INFRASTRUCTURE_PROVIDER, extractTagStringValue(span, AuxiliaryTags.INFRASTRUCTURE_PROVIDER)), buildStringTag(AuxiliaryTags.SERVER_INFRASTRUCTURE_LOCATION, extractTagStringValue(span, AuxiliaryTags.INFRASTRUCTURE_LOCATION)),