From cc51e6cf0b0dade258b47f3c9d984280fe7d205f Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 24 May 2016 22:55:17 -0400 Subject: [PATCH] Removes tracegen (#1118) Tracegen was a tool we used to use to populate zipkin when someone had no instrumented apps. It would create a number of traces based on latin words. Since then, we have increasingly sophisticated and relevant self-tracing setup, which in the java project extends all the way to cassandra. Moreover, we have spigo, which now includes zipkin scripts to create large amounts of realistic traces, and instrumentation-specific examples from Brave and Sleuth. Considering the better alternatives, we should stop maintaining tracegen https://github.com/adrianco/spigo https://github.com/openzipkin/brave-resteasy-example https://github.com/spring-cloud-samples/brewery --- README.md | 12 +- bin/tracegen | 2 - gradle.properties | 4 - settings.gradle | 3 - zipkin-tracegen/README.md | 11 -- zipkin-tracegen/build.gradle | 13 -- .../com/twitter/zipkin/tracegen/Main.scala | 133 ---------------- .../twitter/zipkin/tracegen/TraceGen.scala | 146 ------------------ 8 files changed, 3 insertions(+), 321 deletions(-) delete mode 100755 bin/tracegen delete mode 100644 zipkin-tracegen/README.md delete mode 100644 zipkin-tracegen/build.gradle delete mode 100644 zipkin-tracegen/src/main/scala/com/twitter/zipkin/tracegen/Main.scala delete mode 100644 zipkin-tracegen/src/main/scala/com/twitter/zipkin/tracegen/TraceGen.scala diff --git a/README.md b/README.md index 3a23e003dac..99f61cc10c4 100644 --- a/README.md +++ b/README.md @@ -34,16 +34,10 @@ Here's how to start zipkin using the default file-based backend and view traces. ```bash # get the zipkin source and change to its directory $ git clone https://github.com/openzipkin/zipkin; cd zipkin -# start the query server in a new terminal session or tab +# start the query server $ ./bin/query -# start the collector server in a new terminal session or tab -$ ./bin/collector -# start the web server in a new terminal session or tab -$ ./bin/web -# create dummy traces -$ ./bin/tracegen -# open the ui and look at them! -$ open http://localhost:8080/ +$ open http://localhost:9411/ +# While you browse, self-tracing will populate traces for you to view ``` ## Full documentation diff --git a/bin/tracegen b/bin/tracegen deleted file mode 100755 index 2588db46d8b..00000000000 --- a/bin/tracegen +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -./gradlew :zipkin-tracegen:run -PtracegenDest=${1:-localhost} diff --git a/gradle.properties b/gradle.properties index c348bd8d550..e983a7fd295 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,10 +23,6 @@ org.gradle.jvmargs=-XX\:+UseConcMarkSweepGC -Xms2G -Xmx2G -Xss512k # Other values include, but aren't limited to "cassandra" configKey=dev -# tracegenDest allows you to generate traces to something besides localhost. -# Ex. `bin/tracegen 192.168.99.100` for Docker Machine. -tracegenDest=localhost - # dbEngine applies to zipkin-(collector|query)-service when config == dev # # dbEngine names ending in "-persistent" need to share db files. Since these diff --git a/settings.gradle b/settings.gradle index 7cb98509d11..29b4fb76a41 100644 --- a/settings.gradle +++ b/settings.gradle @@ -58,7 +58,4 @@ def includes = [ 'zipkin-sampler' ] -if (System.getenv('PUBLISHING') == null) { - includes.add('zipkin-tracegen') -} include includes.toArray(new String[0]) diff --git a/zipkin-tracegen/README.md b/zipkin-tracegen/README.md deleted file mode 100644 index 61a6b73bd4e..00000000000 --- a/zipkin-tracegen/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Testing -This module is for non unit tests. - -So far there's just a very basic, and somewhat hacky, program that generates -fake traces and sends those off to the server and reads them back. - -There is also a SQL dump of test aggregate dependency data, which can be used if you -want to test the aggregate dependency graph feature in the Web UI without running the -zipkin-dependency Hadoop job first. In order to use it, start up Zipkin -configured with a SQL database backend, and dump the data into that database. -The aggregate dependency graph should then show up in the Zipkin Web UI. diff --git a/zipkin-tracegen/build.gradle b/zipkin-tracegen/build.gradle deleted file mode 100644 index 51e22fa8efd..00000000000 --- a/zipkin-tracegen/build.gradle +++ /dev/null @@ -1,13 +0,0 @@ -task run(type:JavaExec) { - main = 'com.twitter.zipkin.tracegen.Main' - classpath = sourceSets.main.runtimeClasspath - args '-scribeDest', "${tracegenDest}:9410", '-queryDest', "${tracegenDest}:9411" -} - -dependencies { - compile project(':zipkin-common') - compile project(':zipkin-receiver-scribe') - compile "com.twitter.finatra:finatra-httpclient_${scalaInterfaceVersion}:${commonVersions.finatra}" - compile "ch.qos.logback:logback-core:${commonVersions.logback}" - compile "ch.qos.logback:logback-classic:${commonVersions.logback}" -} diff --git a/zipkin-tracegen/src/main/scala/com/twitter/zipkin/tracegen/Main.scala b/zipkin-tracegen/src/main/scala/com/twitter/zipkin/tracegen/Main.scala deleted file mode 100644 index ab641925d83..00000000000 --- a/zipkin-tracegen/src/main/scala/com/twitter/zipkin/tracegen/Main.scala +++ /dev/null @@ -1,133 +0,0 @@ -package com.twitter.zipkin.tracegen - -/* - * Copyright 2014 Twitter Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -import ch.qos.logback.classic.{Level, Logger} -import com.twitter.app.App -import com.twitter.finagle.http.Request -import com.twitter.finagle.tracing.SpanId -import com.twitter.finagle.{Http, Thrift, param} -import com.twitter.finatra.httpclient.HttpClient -import com.twitter.finatra.json.FinatraObjectMapper -import com.twitter.scrooge.BinaryThriftStructSerializer -import com.twitter.util.{Await, Future} -import com.twitter.zipkin.common.Span -import com.twitter.zipkin.conversions.thrift._ -import com.twitter.zipkin.json.{JsonSpan, ZipkinJson} -import com.twitter.zipkin.thriftscala -import org.slf4j.LoggerFactory - -trait ZipkinSpanGenerator { self: App => - val genTraces = flag("genTraces", 5, "Number of traces to generate") - val maxDepth = flag("maxDepth", 7, "Max depth of generated traces") - - def generateTraces(store: Seq[Span] => Future[Unit]): Future[Unit] = { - val traceGen = new TraceGen(genTraces(), maxDepth()) - store(traceGen()) - } -} - -object Main extends App with ZipkinSpanGenerator { - val scribeDest = flag("scribeDest", "localhost:9410", "Destination of the collector") - val queryDest = flag("queryDest", "localhost:9411", "Destination of the query service") - val generateOnly = flag("generateOnly", false, "Only generate date, do not request it back") - - /** - * Initialize a json-aware Finatra client, targeting the query host. Lazy to ensure - * we get the host after the [[queryDest]] flag has been parsed. - */ - lazy val queryClient = new HttpClient( - httpService = Http.client.configured(param.Label("zipkin-tracegen")) - .newClient(queryDest()).toService, - defaultHeaders = Map( - "Host" -> queryDest(), - "Accept-Encoding" -> "gzip" - ), - mapper = new FinatraObjectMapper(ZipkinJson) - ) - - LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME) - .asInstanceOf[Logger].setLevel(Level.DEBUG) - - private[this] val serializer = new BinaryThriftStructSerializer[thriftscala.Span] { def codec = thriftscala.Span } - - def main() { - val scribe = Thrift.newIface[thriftscala.Scribe.FutureIface](scribeDest()) - val store = { spans: Seq[Span] => - scribe.log(spans.map { span => thriftscala.LogEntry("zipkin", serializer.toString(span.toThrift)) }).unit - } - Await.result(generateTraces(store)) - - if (!generateOnly()) { - Await.result { - querySpan( - "vitae", - "velit", - "some custom annotation".replace(" ", "%20"), - "key", "value", - 10) - } - } - } - - private[this] def printTraces(traces: Seq[List[Span]])= { - for (trace <- traces; span <- trace) yield - println("Got span: " + span) - } - - private[this] def querySpan( - service: String, - span: String, - annotation: String, - key: String, - value: String, - limit: Int - ): Future[Unit] = { - println(s"Querying for service name: $service and span name $span") - for { - ts1 <- getTraces(s"/api/v1/traces?serviceName=$service&spanName=$span&limit=$limit") - _ = printTraces(ts1) - - _ = println(s"Querying for service name: $service") - ts2 <- getTraces(s"/api/v1/traces?serviceName=$service&limit=$limit") - _ = printTraces(ts2) - - _ = println(s"Querying for annotation: $annotation") - ts3 <- getTraces(s"/api/v1/traces?serviceName=$service&annotationQuery=$annotation&limit=$limit") - _ = printTraces(ts3) - - _ = println(s"Querying for kv annotation: $key -> $value") - ts4 <- getTraces(s"/api/v1/traces?serviceName=$service&annotationQuery=$key=$value&limit=$limit") - _ = printTraces(ts4) - - traceId = ts2.map(t => t.head.traceId).head // map first id to hex - trace <- queryClient.executeJson[List[JsonSpan]](Request("/api/v1/trace/" + SpanId.toString(traceId))) - .map(_.map(JsonSpan.invert)) - _ = printTraces(Seq(trace)) - - svcNames <- queryClient.executeJson[Seq[String]](Request("/api/v1/services")) - _ = println(s"Service names: $svcNames") - - spanNames <- queryClient.executeJson[Seq[String]](Request(s"/api/v1/spans?serviceName=$service")) - _ = println(s"Span names for $service: $spanNames") - } yield () - } - - def getTraces(uri: String) = queryClient.executeJson[Seq[List[JsonSpan]]](Request(uri)) - .map(traces => traces.map(_.map(JsonSpan.invert))) -} diff --git a/zipkin-tracegen/src/main/scala/com/twitter/zipkin/tracegen/TraceGen.scala b/zipkin-tracegen/src/main/scala/com/twitter/zipkin/tracegen/TraceGen.scala deleted file mode 100644 index 813207e5a7b..00000000000 --- a/zipkin-tracegen/src/main/scala/com/twitter/zipkin/tracegen/TraceGen.scala +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright 2014 Twitter Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package com.twitter.zipkin.tracegen - -import collection.mutable.ListBuffer -import com.twitter.conversions.time._ -import com.twitter.util.Time -import com.twitter.zipkin.common._ -import com.twitter.zipkin.{Constants, thriftscala} -import java.nio.ByteBuffer -import scala.util.Random - -private object TraceGen { - val rnd = new Random - - val serviceNames = - """vitae ipsum felis lorem magna dolor porta donec augue tortor auctor - mattis ligula mollis aenean montes semper magnis rutrum turpis sociis - lectus mauris congue libero rhoncus dapibus natoque gravida viverra egestas - lacinia feugiat pulvinar accumsan sagittis ultrices praesent vehicula nascetur - pharetra maecenas consequat ultricies ridiculus malesuada curabitur convallis - facilisis hendrerit penatibus imperdiet tincidunt parturient adipiscing - consectetur pellentesque - """.split("""\s+""") - - def rndSvcName: String = serviceNames(rnd.nextInt(serviceNames.size)) - - val rpcNames = - """vivamus fermentum semper porta nunc diam velit adipiscing ut tristique vitae - """.split("""\s+""") - - def rndRpcName: String = rpcNames(rnd.nextInt(rpcNames.size)) -} - -class TraceGen(traces: Int, maxDepth: Int) { - import TraceGen._ - - def apply(): Seq[Span] = - (0 until traces) flatMap { _ => - val start = (rnd.nextInt(8) + 1).hours.ago - val trace = new GenTrace - withEndpoint(doRpc(trace, start, rnd.nextInt(maxDepth), rndRpcName, _)) - trace.spans.toSeq - } - - private class GenTrace { - val traceId = rnd.nextLong - val spans = new ListBuffer[Span]() - def addSpan(name: String, id: Long, parentId: Option[Long], timestamp: Long, duration: Long, - annos: List[Annotation], binAnnos: List[BinaryAnnotation]) { - spans += Span(traceId, name, id, parentId, Some(timestamp), Some(duration), annos, binAnnos) - } - } - - private[this] var upstreamServices = Set.empty[String] - private[this] def withEndpoint[T](f: Endpoint => T): T = { - // attempt to get a service name without introducing a loop in the trace DAG - var svcName = rndSvcName - var attempts = serviceNames.size - while (attempts > 0 && upstreamServices.contains(svcName)) { - svcName = rndSvcName - attempts -= 1 - } - - // couldn't find one. create a new one with a random suffix - if (attempts == 0) - svcName += (rnd.nextInt(8000) + 1000) - - upstreamServices += svcName - val ret = f(Endpoint(rnd.nextInt(), (rnd.nextInt(8000) + 1000).toShort, svcName)) - upstreamServices -= svcName - - ret - } - - private[this] def doRpc( - trace: GenTrace, - time: Time, - depth: Int, - spanName: String, - ep: Endpoint, - spanId: Long = rnd.nextLong, - parentSpanId: Option[Long] = None - ): Time = { - var curTime = time + 1.millisecond - - val svrAnnos = new ListBuffer[Annotation]() - svrAnnos += Annotation(curTime.inMicroseconds, Constants.ServerRecv, Some(ep)) - - val svrBinAnnos = (0 to rnd.nextInt(3)) map { _ => - BinaryAnnotation(rndSvcName, rndSvcName, Some(ep)) - } toList - - // simulate some amount of work - curTime += rnd.nextInt(10).milliseconds - - val times = (0 to (rnd.nextInt(5) + 1)) map { _ => - svrAnnos += Annotation(curTime.inMicroseconds, rndSvcName, Some(ep)) - curTime += rnd.nextInt(5).milliseconds - } - - if (depth > 0) { - // parallel calls to downstream services - val times = (0 to (rnd.nextInt(depth) + 1)) map { _ => - withEndpoint { nextEp => - val thisSpanId = rnd.nextLong - val thisParentId = Some(spanId) - val rpcName = rndRpcName - val annos = new ListBuffer[Annotation]() - val binAnnos = new ListBuffer[BinaryAnnotation]() - - val delay = (if (rnd.nextInt(10) > 6) rnd.nextInt(10) else 0).microseconds - annos += Annotation((curTime + delay).inMicroseconds, thriftscala.Constants.CLIENT_SEND, Some(ep)) - val time = doRpc(trace, curTime, rnd.nextInt(depth), rpcName, nextEp, thisSpanId, thisParentId) + 1.millisecond - annos += Annotation(time.inMicroseconds, thriftscala.Constants.CLIENT_RECV, Some(ep)) - val timestamp = annos(0).timestamp - val duration = annos(1).timestamp - annos(0).timestamp - trace.addSpan(rpcName, thisSpanId, thisParentId, timestamp, duration, annos.toList, binAnnos.toList) - - time - } - } - curTime = times.max - } - - svrAnnos += Annotation(curTime.inMicroseconds, thriftscala.Constants.SERVER_SEND, Some(ep)) - val timestamp = svrAnnos(0).timestamp - val duration = svrAnnos(1).timestamp - svrAnnos(0).timestamp - trace.addSpan(spanName, spanId, parentSpanId, timestamp, duration, svrAnnos.toList, svrBinAnnos.toList) - curTime - } -}