Permalink
Browse files

Replace ThriftQueryAdapter with implicits

Author: @franklinhu
Fixes #183
URL: #183
  • Loading branch information...
1 parent 17ad96c commit 21e43167840e4d6c8632363c55bd46eaeb5ebd23 @franklinhu franklinhu committed with Franklin Hu Oct 19, 2012
@@ -20,12 +20,12 @@ import com.codahale.jerkson.Json
import com.twitter.finatra.{Response, Controller, View, Request}
import com.twitter.logging.Logger
import com.twitter.util.Future
-import com.twitter.zipkin.adapter.ThriftQueryAdapter
import com.twitter.zipkin.gen
import com.twitter.zipkin.config.ZipkinWebConfig
import java.text.SimpleDateFormat
import java.util.Calendar
import com.twitter.zipkin.conversions.json._
+import com.twitter.zipkin.conversions.thrift._
import com.twitter.zipkin.common.json.JsonTraceSummary
import com.twitter.zipkin.query.QueryRequest
@@ -122,7 +122,7 @@ class App(config: ZipkinWebConfig, client: gen.ZipkinQuery.FinagledClient) exten
def query(queryRequest: QueryRequest, request: Request, retryLimit: Int = 10): Future[Seq[JsonTraceSummary]] = {
log.debug(queryRequest.toString)
/* Get trace ids */
- val response = client.getTraceIds(ThriftQueryAdapter(queryRequest)).map { ThriftQueryAdapter(_) }
+ val response = client.getTraceIds(queryRequest.toThrift).map { _.toQueryResponse }
val adjusters = getAdjusters(request)
response.map { resp =>
@@ -139,7 +139,7 @@ class App(config: ZipkinWebConfig, client: gen.ZipkinQuery.FinagledClient) exten
case ids @ _ => {
client.getTraceSummariesByIds(ids, adjusters).map {
_.map { summary =>
- ThriftQueryAdapter(summary).toJson
+ summary.toTraceSummary.toJson
}
}
}
@@ -232,7 +232,7 @@ class App(config: ZipkinWebConfig, client: gen.ZipkinQuery.FinagledClient) exten
val ids = Seq(request.params("id").toLong)
log.debug(ids.toString())
- client.getTraceCombosByIds(ids, adjusters).map { _.map { ThriftQueryAdapter(_) }.head }.map { combo =>
+ client.getTraceCombosByIds(ids, adjusters).map { _.map { _.toTraceCombo }.head }.map { combo =>
render.json(combo.toJson)
}
}
@@ -245,7 +245,7 @@ class App(config: ZipkinWebConfig, client: gen.ZipkinQuery.FinagledClient) exten
client.getTraceCombosByIds(ids, adjusters).map {
_.map {
- ThriftQueryAdapter(_).trace
+ _.toTraceCombo.trace
}.head
}.map { trace =>
render.json(trace.toJson)
@@ -22,7 +22,7 @@ import com.twitter.finagle.tracing.{Trace => FTrace}
import com.twitter.logging.Logger
import com.twitter.ostrich.admin.Service
import com.twitter.util.Future
-import com.twitter.zipkin.adapter.ThriftQueryAdapter
+import com.twitter.zipkin.conversions.thrift._
import com.twitter.zipkin.gen
import com.twitter.zipkin.query.adjusters.Adjuster
import com.twitter.zipkin.storage._
@@ -293,7 +293,7 @@ class QueryService(storage: Storage, index: Index, aggregates: Aggregates, adjus
storage.getSpansByTraceIds(traceIds).map { traces =>
traces.map { spans =>
val trace = Trace(spans)
- ThriftQueryAdapter(adjusters.foldLeft(trace)((t, adjuster) => adjuster.adjust(t)))
+ adjusters.foldLeft(trace)((t, adjuster) => adjuster.adjust(t)).toThrift
}
}
}
@@ -309,7 +309,7 @@ class QueryService(storage: Storage, index: Index, aggregates: Aggregates, adjus
storage.getSpansByTraceIds(traceIds).map { traces =>
traces.flatMap { spans =>
val trace = Trace(spans)
- TraceTimeline(adjusters.foldLeft(trace)((t, adjuster) => adjuster.adjust(t))).map(ThriftQueryAdapter(_))
+ TraceTimeline(adjusters.foldLeft(trace)((t, adjuster) => adjuster.adjust(t))).map(_.toThrift)
}
}
}
@@ -325,7 +325,7 @@ class QueryService(storage: Storage, index: Index, aggregates: Aggregates, adjus
storage.getSpansByTraceIds(traceIds.toList).map { traces =>
traces.flatMap { spans =>
val trace = Trace(spans)
- TraceSummary(adjusters.foldLeft(trace)((t, adjuster) => adjuster.adjust(t))).map(ThriftQueryAdapter(_))
+ TraceSummary(adjusters.foldLeft(trace)((t, adjuster) => adjuster.adjust(t))).map(_.toThrift)
}
}
}
@@ -340,7 +340,7 @@ class QueryService(storage: Storage, index: Index, aggregates: Aggregates, adjus
storage.getSpansByTraceIds(traceIds).map { traces =>
traces.map { spans =>
val trace = Trace(spans)
- ThriftQueryAdapter(TraceCombo(adjusters.foldLeft(trace)((t, adjuster) => adjuster.adjust(t))))
+ TraceCombo(adjusters.foldLeft(trace)((t, adjuster) => adjuster.adjust(t))).toThrift
}
}
}
@@ -17,7 +17,6 @@
package com.twitter.zipkin.query
import com.twitter.util.Future
-import com.twitter.zipkin.adapter.{ThriftQueryAdapter}
import com.twitter.zipkin.common._
import com.twitter.zipkin.conversions.thrift._
import com.twitter.zipkin.gen
@@ -167,7 +166,7 @@ class QueryServiceSpec extends Specification with JMocker with ClassMocker {
one(storage).getSpansByTraceIds(List(traceId)) willReturn Future(List(spans1))
}
- val ts = List(ThriftQueryAdapter(TraceSummary(1, 100, 150, 50, Map("service1" -> 1), List(ep1))))
+ val ts = List(TraceSummary(1, 100, 150, 50, Map("service1" -> 1), List(ep1)).toThrift)
ts mustEqual qs.getTraceSummariesByIds(List(traceId), List())()
}
@@ -182,9 +181,9 @@ class QueryServiceSpec extends Specification with JMocker with ClassMocker {
expect {
one(storage).getSpansByTraceIds(List(traceId)) willReturn Future(List(spans1))
}
- val trace = ThriftQueryAdapter(trace1)
- val summary = ThriftQueryAdapter(TraceSummary(1, 100, 150, 50, Map("service1" -> 1), List(ep1)))
- val timeline = TraceTimeline(trace1).map(ThriftQueryAdapter(_))
+ val trace = trace1.toThrift
+ val summary = TraceSummary(1, 100, 150, 50, Map("service1" -> 1), List(ep1)).toThrift
+ val timeline = TraceTimeline(trace1) map { _.toThrift }
val combo = gen.TraceCombo(trace, Some(summary), timeline, Some(Map(666L -> 1)))
Seq(combo) mustEqual qs.getTraceCombosByIds(List(traceId), List())()
}
@@ -240,7 +239,7 @@ class QueryServiceSpec extends Specification with JMocker with ClassMocker {
1.of(storage).getSpansByTraceIds(List(1L)) willReturn Future(List(spans1))
}
- val expected = List(ThriftQueryAdapter(trace1))
+ val expected = List(trace1.toThrift)
val actual = qs.getTracesByIds(List(1L), List())()
expected mustEqual actual
}
@@ -1,168 +0,0 @@
-/*
- * Copyright 2012 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.adapter
-
-import com.twitter.zipkin.conversions.thrift._
-import com.twitter.zipkin.gen
-import com.twitter.zipkin.query._
-
-object ThriftQueryAdapter extends QueryAdapter {
- type timelineAnnotationType = gen.TimelineAnnotation
- type traceTimelineType = gen.TraceTimeline
- type traceComboType = gen.TraceCombo
- type traceSummaryType = gen.TraceSummary
- type traceType = gen.Trace
-
- type queryRequestType = gen.QueryRequest
- type queryResponseType = gen.QueryResponse
-
- type orderType = gen.Order
-
- /* TimelineAnnotation from Thrift */
- def apply(t: timelineAnnotationType): TimelineAnnotation = {
- TimelineAnnotation(
- t.`timestamp`,
- t.`value`,
- t.`host`.toEndpoint,
- t.`spanId`,
- t.`parentId`,
- t.`serviceName`,
- t.`spanName`)
- }
-
- /* TimelineAnnotation to Thrift */
- def apply(t: TimelineAnnotation): timelineAnnotationType = {
- gen.TimelineAnnotation(
- t.timestamp,
- t.value,
- t.host.toThrift,
- t.spanId,
- t.parentId,
- t.serviceName,
- t.spanName)
- }
-
- /* TraceTimeline from Thrift */
- def apply(t: traceTimelineType): TraceTimeline = {
- TraceTimeline(
- t.`traceId`,
- t.`rootMostSpanId`,
- t.`annotations`.map { ThriftQueryAdapter(_) },
- t.`binaryAnnotations`.map { _.toBinaryAnnotation })
- }
-
- /* TraceTimeline to Thrift */
- def apply(t: TraceTimeline): traceTimelineType = {
- gen.TraceTimeline(
- t.traceId,
- t.rootSpanId,
- t.annotations.map { ThriftQueryAdapter(_) },
- t.binaryAnnotations.map { _.toThrift })
- }
-
- /* TraceCombo from Thrift */
- def apply(t: traceComboType): TraceCombo = {
- TraceCombo(
- ThriftQueryAdapter(t.`trace`),
- t.`summary`.map(ThriftQueryAdapter(_)),
- t.`timeline`.map(ThriftQueryAdapter(_)),
- t.`spanDepths`.map(_.toMap))
- }
-
- /* TraceCombo to Thrift */
- def apply(t: TraceCombo): traceComboType = {
- gen.TraceCombo(
- ThriftQueryAdapter(t.trace),
- t.traceSummary.map(ThriftQueryAdapter(_)),
- t.traceTimeline.map(ThriftQueryAdapter(_)),
- t.spanDepths)
- }
-
- /* TraceSummary from Thrift */
- def apply(t: traceSummaryType): TraceSummary = {
- new TraceSummary(t.traceId, t.startTimestamp, t.endTimestamp,
- t.durationMicro, t.serviceCounts,
- t.endpoints.map { _.toEndpoint }.toList)
- }
-
- /* TraceSummary to Thrift */
- def apply(t: TraceSummary): traceSummaryType = {
- gen.TraceSummary(t.traceId, t.startTimestamp, t.endTimestamp,
- t.durationMicro, t.serviceCounts, t.endpoints.map { _.toThrift })
- }
-
- /* Trace from Thrift */
- def apply(t: traceType): Trace = {
- Trace(t.spans.map { _.toSpan })
- }
-
- /* Trace to Thrift */
- def apply(t: Trace): traceType = {
- gen.Trace(t.spans.map{ _.toThrift })
- }
-
- /* QueryRequest */
- def apply(q: queryRequestType): QueryRequest = {
- QueryRequest(
- q.`serviceName`,
- q.`spanName`,
- q.`annotations`,
- q.`binaryAnnotations`.map {
- _.map { _.toBinaryAnnotation }
- },
- q.`endTs`,
- q.`limit`,
- ThriftQueryAdapter(q.`order`))
- }
- def apply(q: QueryRequest): queryRequestType = {
- gen.QueryRequest(
- q.serviceName,
- q.spanName,
- q.annotations,
- q.binaryAnnotations.map {
- _.map { _.toThrift }
- },
- q.endTs,
- q.limit,
- ThriftQueryAdapter(q.order))
- }
-
- /* QueryResponse */
- def apply(q: queryResponseType): QueryResponse =
- QueryResponse(q.`traceIds`, q.`startTs`, q.`endTs`)
- def apply(q: QueryResponse): queryResponseType =
- gen.QueryResponse(q.traceIds, q.startTs, q.endTs)
-
- /* Order */
- def apply(o: orderType): Order = {
- o match {
- case gen.Order.DurationDesc => Order.DurationDesc
- case gen.Order.DurationAsc => Order.DurationAsc
- case gen.Order.TimestampDesc => Order.TimestampDesc
- case gen.Order.TimestampAsc => Order.TimestampAsc
- case gen.Order.None => Order.None
- }
- }
- def apply(o: Order): orderType = {
- o match {
- case Order.DurationDesc => gen.Order.DurationDesc
- case Order.DurationAsc => gen.Order.DurationAsc
- case Order.TimestampDesc => gen.Order.TimestampDesc
- case Order.TimestampAsc => gen.Order.TimestampAsc
- case Order.None => gen.Order.None
- }
- }
-}
Oops, something went wrong.

0 comments on commit 21e4316

Please sign in to comment.