Skip to content

Commit a334516

Browse files
Ashish AggarwalAshish Aggarwal
authored andcommitted
refactoring for backward compatiblity
1 parent 5cddbec commit a334516

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

commons/src/main/java/com/expedia/www/haystack/client/dispatchers/clients/BaseGrpcClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.util.Arrays;
3131
import java.util.concurrent.TimeUnit;
3232

33-
abstract public class BaseGrpcClient {
33+
abstract public class BaseGrpcClient<R> implements Client<R> {
3434
private static final Logger LOGGER = LoggerFactory.getLogger(BaseGrpcClient.class);
3535

3636
protected final ManagedChannel channel;
@@ -140,7 +140,7 @@ public void onNext(DispatchResult value) {
140140
}
141141
}
142142

143-
public static class Builder {
143+
public static abstract class Builder {
144144
protected StreamObserver<DispatchResult> observer;
145145

146146
protected Metrics metrics;
@@ -228,5 +228,7 @@ protected ManagedChannel buildManagedChannel() {
228228
.negotiationType(negotiationType)
229229
.build();
230230
}
231+
232+
public abstract BaseGrpcClient build();
231233
}
232234
}

commons/src/main/java/com/expedia/www/haystack/client/dispatchers/clients/GRPCAgentProtoClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import io.grpc.ManagedChannel;
2727
import io.grpc.stub.StreamObserver;
2828

29-
public class GRPCAgentProtoClient extends BaseGrpcClient implements Client<Span> {
29+
public class GRPCAgentProtoClient extends BaseGrpcClient<Span> {
3030
public GRPCAgentProtoClient(Metrics metrics,
3131
ManagedChannel channel,
3232
SpanAgentStub stub,

core/src/main/java/com/expedia/www/haystack/client/Tracer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public class Tracer implements io.opentracing.Tracer {
6262
private final Timer extractTimer;
6363
private final Counter extractFailureCounter;
6464

65+
public Tracer(String serviceName, ScopeManager scopeManager, Clock clock,
66+
Dispatcher dispatcher, PropagationRegistry registry, Metrics metrics) {
67+
this(serviceName, scopeManager, clock, dispatcher, registry, metrics, false);
68+
69+
}
6570
public Tracer(String serviceName, ScopeManager scopeManager, Clock clock,
6671
Dispatcher dispatcher, PropagationRegistry registry, Metrics metrics, boolean dualSpanMode) {
6772
this.serviceName = serviceName;
@@ -266,15 +271,15 @@ boolean isServerSpan() {
266271
return Tags.SPAN_KIND_SERVER.equals(tags.get(Tags.SPAN_KIND.getKey()));
267272
}
268273

269-
SpanContext createNewContext() {
274+
protected SpanContext createNewContext() {
270275
return createContext(UUID.randomUUID(), UUID.randomUUID(), null, Collections.emptyMap());
271276
}
272277

273-
SpanContext createContext(UUID traceId, UUID spanId, UUID parentId, Map<String, String> baggage) {
278+
protected SpanContext createContext(UUID traceId, UUID spanId, UUID parentId, Map<String, String> baggage) {
274279
return new SpanContext(traceId, spanId, parentId, baggage, false);
275280
}
276281

277-
SpanContext createDependentContext() {
282+
protected SpanContext createDependentContext() {
278283
Reference parent = references.get(0);
279284
for (Reference reference : references) {
280285
if (References.CHILD_OF.equals(reference.getReferenceType())) {

core/src/main/java/com/expedia/www/haystack/client/dispatchers/clients/GRPCAgentClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import io.grpc.ManagedChannel;
2929
import io.grpc.stub.StreamObserver;
3030

31-
public class GRPCAgentClient extends BaseGrpcClient implements com.expedia.www.haystack.client.dispatchers.clients.Client<Span> {
31+
public class GRPCAgentClient extends BaseGrpcClient<Span> {
3232
private final Format<com.expedia.open.tracing.Span> format;
3333

3434
public GRPCAgentClient(Metrics metrics, Format<com.expedia.open.tracing.Span> format, ManagedChannel channel, SpanAgentStub stub, StreamObserver<DispatchResult> observer, long shutdownTimeoutMS) {

integrations/opencensus/src/test/scala/com/www/expedia/opencensus/exporter/trace/HaystackExporterIntegrationSpec.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class HaystackExporterIntegrationSpec extends FunSpec with GivenWhenThen with Ma
5050
HaystackTraceExporter.unregister()
5151
}
5252

53-
private def generateTrace(tracer: Tracer, startTimeInMillis: Long) = {
53+
private def generateTrace(tracer: Tracer) = {
5454
val spanBuilder = tracer.spanBuilder(OPERATION_NAME).setRecordEvents(true).setSampler(Samplers.alwaysSample())
5555
val spanDurationInMillis = new Random().nextInt(10) + 1
5656

@@ -72,14 +72,12 @@ class HaystackExporterIntegrationSpec extends FunSpec with GivenWhenThen with Ma
7272

7373
describe("Integration Test with haystack and opencensus") {
7474
it ("should dispatch the spans to haystack-agent") {
75-
val startTimeMillis = System.currentTimeMillis()
7675
HaystackTraceExporter.createAndRegister(new GrpcAgentDispatcherConfig("haystack-agent", 35000), SERVICE_NAME)
77-
7876
val tracer = Tracing.getTracer
7977

80-
generateTrace(tracer, startTimeMillis)
78+
generateTrace(tracer)
8179
Thread.sleep(2000)
82-
generateTrace(tracer, startTimeMillis)
80+
generateTrace(tracer)
8381

8482
// wait for few sec to let the span reach kafka
8583
Thread.sleep(10000)
@@ -89,7 +87,6 @@ class HaystackExporterIntegrationSpec extends FunSpec with GivenWhenThen with Ma
8987
val record = records.iterator().next()
9088
val protoSpan = com.expedia.open.tracing.Span.parseFrom(record.value())
9189
protoSpan.getTraceId shouldEqual record.key()
92-
protoSpan.getStartTime should (be >= startTimeMillis * 1000 and be <= System.currentTimeMillis() * 1000) // micros
9390
protoSpan.getServiceName shouldEqual SERVICE_NAME
9491
protoSpan.getOperationName shouldEqual OPERATION_NAME
9592
protoSpan.getTagsCount shouldBe 2

0 commit comments

Comments
 (0)