Skip to content

Commit a93dffd

Browse files
author
nsahai8
committed
adding certificate, improvisiong the code
1 parent 5d2da23 commit a93dffd

File tree

7 files changed

+97
-28
lines changed

7 files changed

+97
-28
lines changed
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
1+
/*
2+
* Copyright 2018 Expedia, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
117
package com.expedia.www.haystack.client;
218

319
public interface IdGenerator {
4-
public Object generateId();
20+
Object generate();
521
}
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2018 Expedia, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
117
package com.expedia.www.haystack.client;
218

319

@@ -6,7 +22,7 @@
622
public class LongIdGenerator implements IdGenerator {
723

824
@Override
9-
public Long generateId() {
10-
return Math.abs(ThreadLocalRandom.current().nextLong());
25+
public Long generate() {
26+
return ThreadLocalRandom.current().nextLong(Long.MAX_VALUE);
1127
}
1228
}

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

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

66-
public Tracer(String serviceName, ScopeManager scopeManager, Clock clock,
67-
Dispatcher dispatcher, PropagationRegistry registry, Metrics metrics) {
68-
this(serviceName, scopeManager, clock, new UUIDv4Generator(), dispatcher, registry, metrics);
69-
}
70-
public Tracer(String serviceName, ScopeManager scopeManager, Clock clock,
71-
Dispatcher dispatcher, PropagationRegistry registry, Metrics metrics, Boolean dualSpanMode) {
72-
this(serviceName, scopeManager, clock, new UUIDv4Generator(), dispatcher, registry, metrics, dualSpanMode);
73-
}
7466
public Tracer(String serviceName, ScopeManager scopeManager, Clock clock,
7567
IdGenerator idGenerator, Dispatcher dispatcher, PropagationRegistry registry, Metrics metrics) {
7668
this(serviceName, scopeManager, clock, idGenerator, dispatcher, registry, metrics, false);
@@ -283,7 +275,7 @@ boolean isServerSpan() {
283275

284276
protected SpanContext createNewContext() {
285277

286-
return createContext(tracer.idGenerator.generateId(), tracer.idGenerator.generateId(), null, Collections.emptyMap());
278+
return createContext(tracer.idGenerator.generate(), tracer.idGenerator.generate(), null, Collections.emptyMap());
287279
}
288280
//remove
289281
protected SpanContext createContext(UUID traceId, UUID spanId, UUID parentId, Map<String, String> baggage) {
@@ -444,10 +436,8 @@ public Builder withDualSpanMode() {
444436
}
445437

446438
public Tracer build() {
447-
if (idGenerator != null) {
448-
return new Tracer(serviceName, scopeManager, clock, idGenerator, dispatcher, registry, metrics, dualSpanMode);
449-
}
450-
return new Tracer(serviceName, scopeManager, clock, dispatcher, registry, metrics, dualSpanMode);
439+
idGenerator = idGenerator == null ? new LongIdGenerator() : idGenerator;
440+
return new Tracer(serviceName, scopeManager, clock, idGenerator, dispatcher, registry, metrics, dualSpanMode);
451441
}
452442
}
453443
}
Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,41 @@
1+
/*
2+
* Copyright 2018 Expedia, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
117
package com.expedia.www.haystack.client;
218

319
import com.fasterxml.uuid.Generators;
20+
import com.fasterxml.uuid.NoArgGenerator;
421

522
public class UUIDv3Generator implements IdGenerator {
623

24+
private NoArgGenerator generator ;
25+
26+
UUIDv3Generator(String type){
27+
generator = getGeneratorByString(type);
28+
}
29+
30+
public NoArgGenerator getGeneratorByString(String type){
31+
if(type == "time"){
32+
return Generators.timeBasedGenerator();
33+
}
34+
return Generators.randomBasedGenerator();
35+
}
36+
737
@Override
8-
public Object generateId() {
9-
return Generators.timeBasedGenerator().generate();
38+
public Object generate() {
39+
return generator.generate();
1040
}
1141
}
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1+
/*
2+
* Copyright 2018 Expedia, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
117
package com.expedia.www.haystack.client;
218

319
import java.util.UUID;
420

521
public class UUIDv4Generator implements IdGenerator {
622

723
@Override
8-
public UUID generateId() {
24+
public UUID generate() {
925
return UUID.randomUUID();
1026
}
1127
}

core/src/test/java/com/expedia/www/haystack/client/SpanBuilderTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void testChildOfWithDualSpanType() {
6767
//create a client span
6868
final Tracer clientTracer = new Tracer.Builder(new NoopMetricsRegistry(),
6969
"ClientService",
70-
dispatcher).withDualSpanMode().build();
70+
dispatcher).withDualSpanMode().withIdGenerator(new UUIDv4Generator()).build();
7171
final Span clientSpan = clientTracer.buildSpan("Api_call")
7272
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
7373
.start();
@@ -77,7 +77,7 @@ public void testChildOfWithDualSpanType() {
7777
//create a server
7878
final Tracer serverTracer = new Tracer.Builder(new NoopMetricsRegistry(),
7979
"ServerService",
80-
dispatcher).withDualSpanMode().build();
80+
dispatcher).withDualSpanMode().withIdGenerator(new UUIDv4Generator()).build();
8181
final SpanContext wireContext = serverTracer.extract(Format.Builtin.TEXT_MAP, wireData);
8282
final Span serverSpan = serverTracer.buildSpan("Api")
8383
.asChildOf(wireContext)
@@ -97,7 +97,7 @@ public void testChildOfWithSingleSpanType() {
9797
//create a client span
9898
final Tracer clientTracer = new Tracer.Builder(new NoopMetricsRegistry(),
9999
"ClientService",
100-
dispatcher).build();
100+
dispatcher).withIdGenerator(new UUIDv4Generator()).build();
101101
final Span clientSpan = clientTracer.buildSpan("Api_call")
102102
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
103103
.start();
@@ -107,7 +107,7 @@ public void testChildOfWithSingleSpanType() {
107107
//create a server
108108
final Tracer serverTracer = new Tracer.Builder(new NoopMetricsRegistry(),
109109
"ServerService",
110-
dispatcher).build();
110+
dispatcher).withIdGenerator(new UUIDv4Generator()).build();
111111
final SpanContext wireContext = serverTracer.extract(Format.Builtin.TEXT_MAP, wireData);
112112
final Span serverSpan = serverTracer.buildSpan("Api")
113113
.asChildOf(wireContext)
@@ -128,7 +128,8 @@ public void testChildOfWithSingleSpanTypeAndExtractedContext() {
128128
//create a client span
129129
final Tracer clientTracer = new Tracer.Builder(new NoopMetricsRegistry(),
130130
"ClientService",
131-
dispatcher).build();
131+
dispatcher).withIdGenerator(new UUIDv4Generator()).build();
132+
132133
final Span clientSpan = clientTracer.buildSpan("Api_call")
133134
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
134135
.start();
@@ -157,7 +158,7 @@ public void testChildOfSingleSpanTypeWithExtractedContextDoesNotPropagateExtract
157158
//create a client span
158159
final Tracer clientTracer = new Tracer.Builder(new NoopMetricsRegistry(),
159160
"ClientService",
160-
dispatcher).build();
161+
dispatcher).withIdGenerator(new UUIDv4Generator()).build();
161162
final Span clientSpan = clientTracer.buildSpan("Api_call")
162163
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
163164
.start();
@@ -167,7 +168,7 @@ public void testChildOfSingleSpanTypeWithExtractedContextDoesNotPropagateExtract
167168
//create a server
168169
final Tracer serverTracer = new Tracer.Builder(new NoopMetricsRegistry(),
169170
"ServerService",
170-
dispatcher).build();
171+
dispatcher).withIdGenerator(new UUIDv4Generator()).build();
171172
final SpanContext wireContext = serverTracer.extract(Format.Builtin.TEXT_MAP, wireData);
172173
final Span serverSpan = serverTracer.buildSpan("Api")
173174
.asChildOf(wireContext)

core/src/test/java/com/expedia/www/haystack/client/TracerBuildTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.junit.Assert;
66
import org.junit.Test;
77

8-
import static org.junit.Assert.*;
8+
99

1010
public class TracerBuildTest {
1111

@@ -28,7 +28,7 @@ public void testTracerBuildWithoutIdGenerator(){
2828

2929
@Test
3030
public void testTracerBuildUUIDv3IdGenerator(){
31-
IdGenerator idGenerator = new UUIDv3Generator();
31+
IdGenerator idGenerator = new UUIDv3Generator("time");
3232
Tracer.Builder tracerBuild = new Tracer.Builder(new NoopMetricsRegistry(), "TestTracer", new NoopDispatcher());
3333
tracerBuild.withIdGenerator(idGenerator);
3434
Tracer tracer = tracerBuild.build();

0 commit comments

Comments
 (0)