From ea1f5b6e4fb2c545e5f9c7bb6b8a2b1266e0e9ea Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Wed, 1 Aug 2018 13:12:42 +0800 Subject: [PATCH] Renames SpanRecord back to MutableSpan Performance is great, but implications of mutability should be top-level. This renames SpanRecord back to MutableSpan, as it focuses on the important thing. See #557 --- brave/src/main/java/brave/RealScopedSpan.java | 26 +++---- brave/src/main/java/brave/RealSpan.java | 76 +++++++++---------- .../main/java/brave/RealSpanCustomizer.java | 20 ++--- brave/src/main/java/brave/Tracer.java | 40 +++++----- brave/src/main/java/brave/Tracing.java | 10 +-- .../{SpanRecord.java => MutableSpan.java} | 4 +- .../brave/internal/recorder/PendingSpan.java | 23 ++++++ .../internal/recorder/PendingSpanRecord.java | 22 ------ ...dingSpanRecords.java => PendingSpans.java} | 36 ++++----- brave/src/test/java/brave/TracerTest.java | 6 +- ...anRecordTest.java => MutableSpanTest.java} | 26 +++---- ...RecordsTest.java => PendingSpansTest.java} | 32 ++++---- .../spring/beans/TracingFactoryBeanTest.java | 6 +- 13 files changed, 164 insertions(+), 163 deletions(-) rename brave/src/main/java/brave/internal/recorder/{SpanRecord.java => MutableSpan.java} (98%) create mode 100644 brave/src/main/java/brave/internal/recorder/PendingSpan.java delete mode 100644 brave/src/main/java/brave/internal/recorder/PendingSpanRecord.java rename brave/src/main/java/brave/internal/recorder/{PendingSpanRecords.java => PendingSpans.java} (86%) rename brave/src/test/java/brave/internal/recorder/{SpanRecordTest.java => MutableSpanTest.java} (88%) rename brave/src/test/java/brave/internal/recorder/{PendingSpanRecordsTest.java => PendingSpansTest.java} (89%) diff --git a/brave/src/main/java/brave/RealScopedSpan.java b/brave/src/main/java/brave/RealScopedSpan.java index b550e74506..14d8c915e8 100644 --- a/brave/src/main/java/brave/RealScopedSpan.java +++ b/brave/src/main/java/brave/RealScopedSpan.java @@ -1,8 +1,8 @@ package brave; import brave.Tracing.SpanReporter; -import brave.internal.recorder.PendingSpanRecords; -import brave.internal.recorder.SpanRecord; +import brave.internal.recorder.MutableSpan; +import brave.internal.recorder.PendingSpans; import brave.propagation.CurrentTraceContext.Scope; import brave.propagation.TraceContext; @@ -11,25 +11,25 @@ final class RealScopedSpan extends ScopedSpan { final TraceContext context; final Scope scope; - final SpanRecord record; + final MutableSpan state; final Clock clock; - final PendingSpanRecords pendingSpanRecords; + final PendingSpans pendingSpans; final SpanReporter spanReporter; final ErrorParser errorParser; RealScopedSpan( TraceContext context, Scope scope, - SpanRecord record, + MutableSpan state, Clock clock, - PendingSpanRecords pendingSpanRecords, + PendingSpans pendingSpans, SpanReporter spanReporter, ErrorParser errorParser ) { this.context = context; this.scope = scope; - this.pendingSpanRecords = pendingSpanRecords; - this.record = record; + this.pendingSpans = pendingSpans; + this.state = state; this.clock = clock; this.spanReporter = spanReporter; this.errorParser = errorParser; @@ -44,12 +44,12 @@ final class RealScopedSpan extends ScopedSpan { } @Override public ScopedSpan annotate(String value) { - record.annotate(clock.currentTimeMicroseconds(), value); + state.annotate(clock.currentTimeMicroseconds(), value); return this; } @Override public ScopedSpan tag(String key, String value) { - record.tag(key, value); + state.tag(key, value); return this; } @@ -60,9 +60,9 @@ final class RealScopedSpan extends ScopedSpan { @Override public void finish() { scope.close(); - if (!pendingSpanRecords.remove(context)) return; // don't double-report - spanReporter.report(context, record); - record.finishTimestamp(clock.currentTimeMicroseconds()); + if (!pendingSpans.remove(context)) return; // don't double-report + spanReporter.report(context, state); + state.finishTimestamp(clock.currentTimeMicroseconds()); } @Override public boolean equals(Object o) { diff --git a/brave/src/main/java/brave/RealSpan.java b/brave/src/main/java/brave/RealSpan.java index 4ed91bae29..4296bf82f4 100644 --- a/brave/src/main/java/brave/RealSpan.java +++ b/brave/src/main/java/brave/RealSpan.java @@ -1,8 +1,8 @@ package brave; import brave.Tracing.SpanReporter; -import brave.internal.recorder.PendingSpanRecords; -import brave.internal.recorder.SpanRecord; +import brave.internal.recorder.MutableSpan; +import brave.internal.recorder.PendingSpans; import brave.propagation.TraceContext; import zipkin2.Endpoint; @@ -10,24 +10,24 @@ final class RealSpan extends Span { final TraceContext context; - final PendingSpanRecords pendingSpanRecords; - final SpanRecord record; + final PendingSpans pendingSpans; + final MutableSpan state; final Clock clock; final SpanReporter spanReporter; final ErrorParser errorParser; final RealSpanCustomizer customizer; RealSpan(TraceContext context, - PendingSpanRecords pendingSpanRecords, - SpanRecord record, + PendingSpans pendingSpans, + MutableSpan state, Clock clock, SpanReporter spanReporter, ErrorParser errorParser) { this.context = context; - this.pendingSpanRecords = pendingSpanRecords; - this.record = record; + this.pendingSpans = pendingSpans; + this.state = state; this.clock = clock; - this.customizer = new RealSpanCustomizer(context, record, clock); + this.customizer = new RealSpanCustomizer(context, state, clock); this.spanReporter = spanReporter; this.errorParser = errorParser; } @@ -41,7 +41,7 @@ final class RealSpan extends Span { } @Override public SpanCustomizer customizer() { - return new RealSpanCustomizer(context, record, clock); + return new RealSpanCustomizer(context, state, clock); } @Override public Span start() { @@ -49,22 +49,22 @@ final class RealSpan extends Span { } @Override public Span start(long timestamp) { - synchronized (record) { - record.startTimestamp(timestamp); + synchronized (state) { + state.startTimestamp(timestamp); } return this; } @Override public Span name(String name) { - synchronized (record) { - record.name(name); + synchronized (state) { + state.name(name); } return this; } @Override public Span kind(Kind kind) { - synchronized (record) { - record.kind(kind); + synchronized (state) { + state.kind(kind); } return this; } @@ -77,36 +77,36 @@ final class RealSpan extends Span { // Modern instrumentation should not send annotations such as this, but we leniently // accept them rather than fail. This for example allows old bridges like to Brave v3 to work if ("cs".equals(value)) { - synchronized (record) { - record.kind(Span.Kind.CLIENT); - record.startTimestamp(timestamp); + synchronized (state) { + state.kind(Span.Kind.CLIENT); + state.startTimestamp(timestamp); } } else if ("sr".equals(value)) { - synchronized (record) { - record.kind(Span.Kind.SERVER); - record.startTimestamp(timestamp); + synchronized (state) { + state.kind(Span.Kind.SERVER); + state.startTimestamp(timestamp); } } else if ("cr".equals(value)) { - synchronized (record) { - record.kind(Span.Kind.CLIENT); + synchronized (state) { + state.kind(Span.Kind.CLIENT); } finish(timestamp); } else if ("ss".equals(value)) { - synchronized (record) { - record.kind(Span.Kind.SERVER); + synchronized (state) { + state.kind(Span.Kind.SERVER); } finish(timestamp); } else { - synchronized (record) { - record.annotate(timestamp, value); + synchronized (state) { + state.annotate(timestamp, value); } } return this; } @Override public Span tag(String key, String value) { - synchronized (record) { - record.tag(key, value); + synchronized (state) { + state.tag(key, value); } return this; } @@ -117,8 +117,8 @@ final class RealSpan extends Span { } @Override public Span remoteEndpoint(Endpoint remoteEndpoint) { - synchronized (record) { - record.remoteEndpoint(remoteEndpoint); + synchronized (state) { + state.remoteEndpoint(remoteEndpoint); } return this; } @@ -128,20 +128,20 @@ final class RealSpan extends Span { } @Override public void finish(long timestamp) { - if (!pendingSpanRecords.remove(context)) return; - synchronized (record) { - record.finishTimestamp(timestamp); + if (!pendingSpans.remove(context)) return; + synchronized (state) { + state.finishTimestamp(timestamp); } - spanReporter.report(context, record); + spanReporter.report(context, state); } @Override public void abandon() { - pendingSpanRecords.remove(context); + pendingSpans.remove(context); } @Override public void flush() { abandon(); - spanReporter.report(context, record); + spanReporter.report(context, state); } @Override public String toString() { diff --git a/brave/src/main/java/brave/RealSpanCustomizer.java b/brave/src/main/java/brave/RealSpanCustomizer.java index f0f3bfb7e5..eac1ee11a4 100644 --- a/brave/src/main/java/brave/RealSpanCustomizer.java +++ b/brave/src/main/java/brave/RealSpanCustomizer.java @@ -1,39 +1,39 @@ package brave; -import brave.internal.recorder.SpanRecord; +import brave.internal.recorder.MutableSpan; import brave.propagation.TraceContext; /** This wraps the public api and guards access to a mutable span. */ final class RealSpanCustomizer implements SpanCustomizer { final TraceContext context; - final SpanRecord record; + final MutableSpan state; final Clock clock; - RealSpanCustomizer(TraceContext context, SpanRecord record, Clock clock) { + RealSpanCustomizer(TraceContext context, MutableSpan state, Clock clock) { this.context = context; - this.record = record; + this.state = state; this.clock = clock; } @Override public SpanCustomizer name(String name) { - synchronized (record) { - record.name(name); + synchronized (state) { + state.name(name); } return this; } @Override public SpanCustomizer annotate(String value) { long timestamp = clock.currentTimeMicroseconds(); - synchronized (record) { - record.annotate(timestamp, value); + synchronized (state) { + state.annotate(timestamp, value); } return this; } @Override public SpanCustomizer tag(String key, String value) { - synchronized (record) { - record.tag(key, value); + synchronized (state) { + state.tag(key, value); } return this; } diff --git a/brave/src/main/java/brave/Tracer.java b/brave/src/main/java/brave/Tracer.java index 3915b16cfc..d7ebaedc23 100644 --- a/brave/src/main/java/brave/Tracer.java +++ b/brave/src/main/java/brave/Tracer.java @@ -2,9 +2,9 @@ import brave.internal.Nullable; import brave.internal.Platform; -import brave.internal.recorder.PendingSpanRecord; -import brave.internal.recorder.PendingSpanRecords; -import brave.internal.recorder.SpanRecord; +import brave.internal.recorder.MutableSpan; +import brave.internal.recorder.PendingSpan; +import brave.internal.recorder.PendingSpans; import brave.propagation.CurrentTraceContext; import brave.propagation.Propagation; import brave.propagation.SamplingFlags; @@ -64,7 +64,7 @@ public class Tracer { final Clock clock; final Propagation.Factory propagationFactory; final Tracing.SpanReporter spanReporter; // for toString - final PendingSpanRecords pendingSpanRecords; + final PendingSpans pendingSpans; final Sampler sampler; final ErrorParser errorParser; final CurrentTraceContext currentTraceContext; @@ -75,7 +75,7 @@ public class Tracer { Clock clock, Propagation.Factory propagationFactory, Tracing.SpanReporter spanReporter, - PendingSpanRecords pendingSpanRecords, + PendingSpans pendingSpans, Sampler sampler, ErrorParser errorParser, CurrentTraceContext currentTraceContext, @@ -86,7 +86,7 @@ public class Tracer { this.clock = clock; this.propagationFactory = propagationFactory; this.spanReporter = spanReporter; - this.pendingSpanRecords = pendingSpanRecords; + this.pendingSpans = pendingSpans; this.sampler = sampler; this.errorParser = errorParser; this.currentTraceContext = currentTraceContext; @@ -113,7 +113,7 @@ public Tracer withSampler(Sampler sampler) { clock, propagationFactory, spanReporter, - pendingSpanRecords, + pendingSpans, sampler, errorParser, currentTraceContext, @@ -250,11 +250,11 @@ public Span toSpan(TraceContext context) { TraceContext decorated = propagationFactory.decorate(context); if (isNoop(decorated)) return new NoopSpan(decorated); // allocate a mutable span in case multiple threads call this method.. they'll use the same data - PendingSpanRecord pendingSpanRecord = pendingSpanRecords.getOrCreate(decorated); + PendingSpan pendingSpan = pendingSpans.getOrCreate(decorated); return new RealSpan(decorated, - pendingSpanRecords, - pendingSpanRecord.span(), - pendingSpanRecord.clock(), + pendingSpans, + pendingSpan.state(), + pendingSpan.clock(), spanReporter, errorParser ); @@ -319,8 +319,8 @@ public SpanCustomizer currentSpanCustomizer() { // note: we don't need to decorate the context for propagation as it is only used for toString TraceContext context = currentTraceContext.get(); if (context == null || isNoop(context)) return NoopSpanCustomizer.INSTANCE; - PendingSpanRecord pendingSpanRecord = pendingSpanRecords.getOrCreate(context); - return new RealSpanCustomizer(context, pendingSpanRecord.span(), pendingSpanRecord.clock()); + PendingSpan pendingSpan = pendingSpans.getOrCreate(context); + return new RealSpanCustomizer(context, pendingSpan.state(), pendingSpan.clock()); } /** @@ -378,12 +378,12 @@ public ScopedSpan startScopedSpanWithParent(String name, @Nullable TraceContext TraceContext context = propagationFactory.decorate(newContextBuilder(parent, sampler).build()); CurrentTraceContext.Scope scope = currentTraceContext.newScope(context); if (isNoop(context)) return new NoopScopedSpan(context, scope); - PendingSpanRecord pendingSpanRecord = pendingSpanRecords.getOrCreate(context); - Clock clock = pendingSpanRecord.clock(); - SpanRecord record = pendingSpanRecord.span(); - record.name(name); - record.startTimestamp(clock.currentTimeMicroseconds()); - return new RealScopedSpan(context, scope, record, clock, pendingSpanRecords, spanReporter, + PendingSpan pendingSpan = pendingSpans.getOrCreate(context); + Clock clock = pendingSpan.clock(); + MutableSpan state = pendingSpan.state(); + state.name(name); + state.startTimestamp(clock.currentTimeMicroseconds()); + return new RealScopedSpan(context, scope, state, clock, pendingSpans, spanReporter, errorParser); } @@ -409,7 +409,7 @@ public static final class SpanInScope implements Closeable { @Override public String toString() { TraceContext currentSpan = currentTraceContext.get(); - List inFlight = pendingSpanRecords.snapshot(); + List inFlight = pendingSpans.snapshot(); return "Tracer{" + (currentSpan != null ? ("currentSpan=" + currentSpan + ", ") : "") + (inFlight.size() > 0 ? ("inFlight=" + inFlight + ", ") : "") diff --git a/brave/src/main/java/brave/Tracing.java b/brave/src/main/java/brave/Tracing.java index 850362a7e8..6b3eb90a82 100644 --- a/brave/src/main/java/brave/Tracing.java +++ b/brave/src/main/java/brave/Tracing.java @@ -2,8 +2,8 @@ import brave.internal.Nullable; import brave.internal.Platform; -import brave.internal.recorder.PendingSpanRecords; -import brave.internal.recorder.SpanRecord; +import brave.internal.recorder.PendingSpans; +import brave.internal.recorder.MutableSpan; import brave.propagation.B3Propagation; import brave.propagation.CurrentTraceContext; import brave.propagation.Propagation; @@ -71,7 +71,7 @@ public Propagation propagation() { * @param context references a potentially unstarted span you'd like a clock correlated with */ public final Clock clock(TraceContext context) { - return tracer().pendingSpanRecords.getOrCreate(context).clock(); + return tracer().pendingSpans.getOrCreate(context).clock(); } abstract public ErrorParser errorParser(); @@ -300,7 +300,7 @@ static final class Default extends Tracing { builder.clock, builder.propagationFactory, reporter, - new PendingSpanRecords(builder.endpoint, clock, reporter, noop), + new PendingSpans(builder.endpoint, clock, reporter, noop), builder.sampler, builder.errorParser, builder.currentTraceContext, @@ -366,7 +366,7 @@ static final class SpanReporter implements Reporter { this.noop = noop; } - void report(TraceContext context, SpanRecord span) { + void report(TraceContext context, MutableSpan span) { zipkin2.Span.Builder builderWithContextData = zipkin2.Span.newBuilder() .traceId(context.traceIdHigh(), context.traceId()) .parentId(context.parentIdAsLong()) diff --git a/brave/src/main/java/brave/internal/recorder/SpanRecord.java b/brave/src/main/java/brave/internal/recorder/MutableSpan.java similarity index 98% rename from brave/src/main/java/brave/internal/recorder/SpanRecord.java rename to brave/src/main/java/brave/internal/recorder/MutableSpan.java index d7f8e9d915..e7d8061dc3 100644 --- a/brave/src/main/java/brave/internal/recorder/SpanRecord.java +++ b/brave/src/main/java/brave/internal/recorder/MutableSpan.java @@ -14,7 +14,7 @@ *

While in-flight, the data is synchronized where necessary. When exposed to users, it can be * mutated without synchronization. */ -public final class SpanRecord { +public final class MutableSpan { /* * One of these objects is allocated for each in-flight span, so we try to be parsimonious on things * like array allocation and object reference size. @@ -123,6 +123,6 @@ public void writeTo(zipkin2.Span.Builder result) { if (shared) result.shared(true); } - SpanRecord(){ // intentionally hidden + MutableSpan(){ // intentionally hidden } } diff --git a/brave/src/main/java/brave/internal/recorder/PendingSpan.java b/brave/src/main/java/brave/internal/recorder/PendingSpan.java new file mode 100644 index 0000000000..19ee85cd46 --- /dev/null +++ b/brave/src/main/java/brave/internal/recorder/PendingSpan.java @@ -0,0 +1,23 @@ +package brave.internal.recorder; + +import brave.Clock; + +public final class PendingSpan { + final MutableSpan state; + final TickClock clock; + + PendingSpan(MutableSpan state, TickClock clock) { + this.state = state; + this.clock = clock; + } + + /** Returns the state currently accumulated for this trace ID and span ID */ + public MutableSpan state() { + return state; + } + + /** Returns a clock that ensures startTimestamp consistency across the trace */ + public Clock clock() { + return clock; + } +} diff --git a/brave/src/main/java/brave/internal/recorder/PendingSpanRecord.java b/brave/src/main/java/brave/internal/recorder/PendingSpanRecord.java deleted file mode 100644 index 80c2cd9f35..0000000000 --- a/brave/src/main/java/brave/internal/recorder/PendingSpanRecord.java +++ /dev/null @@ -1,22 +0,0 @@ -package brave.internal.recorder; - -import brave.Clock; - -public final class PendingSpanRecord { - final SpanRecord span; - final TickClock clock; - - PendingSpanRecord(SpanRecord span, TickClock clock) { - this.span = span; - this.clock = clock; - } - - public SpanRecord span() { - return span; - } - - /** Returns a clock that ensures startTimestamp consistency across the trace */ - public Clock clock() { - return clock; - } -} diff --git a/brave/src/main/java/brave/internal/recorder/PendingSpanRecords.java b/brave/src/main/java/brave/internal/recorder/PendingSpans.java similarity index 86% rename from brave/src/main/java/brave/internal/recorder/PendingSpanRecords.java rename to brave/src/main/java/brave/internal/recorder/PendingSpans.java index 3a72eaf7c7..72a6bb9133 100644 --- a/brave/src/main/java/brave/internal/recorder/PendingSpanRecords.java +++ b/brave/src/main/java/brave/internal/recorder/PendingSpans.java @@ -26,15 +26,15 @@ *

The internal implementation is derived from WeakConcurrentMap by Rafael Winterhalter. See * https://github.com/raphw/weak-lock-free/blob/master/src/main/java/com/blogspot/mydailyjava/weaklockfree/WeakConcurrentMap.java */ -public final class PendingSpanRecords extends ReferenceQueue { +public final class PendingSpans extends ReferenceQueue { // Eventhough we only put by RealKey, we allow get and remove by LookupKey - final ConcurrentMap delegate = new ConcurrentHashMap<>(64); + final ConcurrentMap delegate = new ConcurrentHashMap<>(64); final Endpoint endpoint; final Clock clock; final Reporter reporter; final AtomicBoolean noop; - public PendingSpanRecords( + public PendingSpans( Endpoint endpoint, Clock clock, Reporter reporter, @@ -46,14 +46,14 @@ public PendingSpanRecords( this.noop = noop; } - @Nullable PendingSpanRecord get(TraceContext context) { + @Nullable PendingSpan get(TraceContext context) { if (context == null) throw new NullPointerException("context == null"); reportOrphanedSpans(); return delegate.get(new LookupKey(context)); } - public PendingSpanRecord getOrCreate(TraceContext context) { - PendingSpanRecord result = get(context); + public PendingSpan getOrCreate(TraceContext context) { + PendingSpan result = get(context); if (result != null) return result; // save overhead calculating time if the parent is in-progress (usually is) @@ -61,11 +61,11 @@ public PendingSpanRecord getOrCreate(TraceContext context) { if (clock == null) { clock = new TickClock(this.clock.currentTimeMicroseconds(), System.nanoTime()); } - SpanRecord data = new SpanRecord(); + MutableSpan data = new MutableSpan(); data.localEndpoint(endpoint); if (context.shared()) data.setShared(); - PendingSpanRecord newSpan = new PendingSpanRecord(data, clock); - PendingSpanRecord previousSpan = delegate.putIfAbsent(new RealKey(context, this), newSpan); + PendingSpan newSpan = new PendingSpan(data, clock); + PendingSpan previousSpan = delegate.putIfAbsent(new RealKey(context, this), newSpan); if (previousSpan != null) return previousSpan; // lost race return newSpan; } @@ -75,7 +75,7 @@ public PendingSpanRecord getOrCreate(TraceContext context) { long parentId = context.parentIdAsLong(); // NOTE: we still look for lookup key even on root span, as a client span can be root, and a // server can share the same ID. Essentially, a shared span is similar to a child. - PendingSpanRecord parent; + PendingSpan parent; if (Boolean.TRUE.equals(context.shared())) { TraceContext.Builder lookupContext = context.toBuilder().shared(false); if (parentId != 0L) lookupContext.spanId(parentId); @@ -89,9 +89,9 @@ public PendingSpanRecord getOrCreate(TraceContext context) { } /** @see brave.Span#abandon() */ - @Nullable public boolean remove(TraceContext context) { + public boolean remove(TraceContext context) { if (context == null) throw new NullPointerException("context == null"); - PendingSpanRecord last = delegate.remove(new LookupKey(context)); + PendingSpan last = delegate.remove(new LookupKey(context)); reportOrphanedSpans(); // also clears the reference relating to the recent remove return last != null; } @@ -106,7 +106,7 @@ void reportOrphanedSpans() { Span.Builder builder = null; long flushTime = 0L; while ((contextKey = (RealKey) poll()) != null) { - PendingSpanRecord value = delegate.remove(contextKey); + PendingSpan value = delegate.remove(contextKey); if (value == null || noop.get() || !contextKey.sampled) continue; if (builder != null) { builder.clear(); @@ -120,7 +120,7 @@ void reportOrphanedSpans() { .id(contextKey.spanId) .addAnnotation(flushTime, "brave.flush"); - value.span.writeTo(builderWithContextData); + value.state.writeTo(builderWithContextData); reporter.report(builderWithContextData.build()); } } @@ -194,10 +194,10 @@ static final class LookupKey { public List snapshot() { List result = new ArrayList<>(); zipkin2.Span.Builder spanBuilder = zipkin2.Span.newBuilder(); - for (Map.Entry entry : delegate.entrySet()) { - PendingSpanRecords.RealKey contextKey = (PendingSpanRecords.RealKey) entry.getKey(); + for (Map.Entry entry : delegate.entrySet()) { + PendingSpans.RealKey contextKey = (PendingSpans.RealKey) entry.getKey(); spanBuilder.clear().traceId(contextKey.traceIdHigh, contextKey.traceId).id(contextKey.spanId); - entry.getValue().span.writeTo(spanBuilder); + entry.getValue().state.writeTo(spanBuilder); result.add(spanBuilder.build()); spanBuilder.clear(); } @@ -205,6 +205,6 @@ public List snapshot() { } @Override public String toString() { - return "PendingSpanRecords" + delegate.keySet(); + return "PendingSpans" + delegate.keySet(); } } diff --git a/brave/src/test/java/brave/TracerTest.java b/brave/src/test/java/brave/TracerTest.java index df2e5cbe43..2f74f96796 100644 --- a/brave/src/test/java/brave/TracerTest.java +++ b/brave/src/test/java/brave/TracerTest.java @@ -88,14 +88,14 @@ public class TracerTest { @Test public void localServiceName() { tracer = Tracing.newBuilder().localServiceName("my-foo").build().tracer(); - assertThat(tracer).extracting("pendingSpanRecords.endpoint.serviceName") + assertThat(tracer).extracting("pendingSpans.endpoint.serviceName") .containsExactly("my-foo"); } @Test public void localServiceName_defaultIsUnknown() { tracer = Tracing.newBuilder().build().tracer(); - assertThat(tracer).extracting("pendingSpanRecords.endpoint.serviceName") + assertThat(tracer).extracting("pendingSpans.endpoint.serviceName") .containsExactly("unknown"); } @@ -103,7 +103,7 @@ public class TracerTest { Endpoint endpoint = Endpoint.newBuilder().serviceName("my-bar").build(); tracer = Tracing.newBuilder().localServiceName("my-foo").endpoint(endpoint).build().tracer(); - assertThat(tracer).extracting("pendingSpanRecords.endpoint") + assertThat(tracer).extracting("pendingSpans.endpoint") .containsExactly(endpoint); } diff --git a/brave/src/test/java/brave/internal/recorder/SpanRecordTest.java b/brave/src/test/java/brave/internal/recorder/MutableSpanTest.java similarity index 88% rename from brave/src/test/java/brave/internal/recorder/SpanRecordTest.java rename to brave/src/test/java/brave/internal/recorder/MutableSpanTest.java index 3bd97d7206..c1881e310a 100644 --- a/brave/src/test/java/brave/internal/recorder/SpanRecordTest.java +++ b/brave/src/test/java/brave/internal/recorder/MutableSpanTest.java @@ -11,9 +11,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; -public class SpanRecordTest { +public class MutableSpanTest { @Test public void minimumDurationIsOne() { - SpanRecord span = new SpanRecord(); + MutableSpan span = new MutableSpan(); span.startTimestamp(1L); span.finishTimestamp(1L); @@ -22,7 +22,7 @@ public class SpanRecordTest { } @Test public void replacesTag() { - SpanRecord span = new SpanRecord(); + MutableSpan span = new MutableSpan(); span.tag("1", "1"); span.tag("foo", "bar"); @@ -39,7 +39,7 @@ public class SpanRecordTest { } @Test public void addsAnnotations() { - SpanRecord span = new SpanRecord(); + MutableSpan span = new MutableSpan(); span.startTimestamp(1L); span.annotate(2L, "foo"); @@ -66,7 +66,7 @@ public class SpanRecordTest { } void finish(Kind braveKind, Span.Kind span2Kind) { - SpanRecord span = new SpanRecord(); + MutableSpan span = new MutableSpan(); span.kind(braveKind); span.startTimestamp(1L); span.finishTimestamp(2L); @@ -95,7 +95,7 @@ void finish(Kind braveKind, Span.Kind span2Kind) { } void flush(Kind braveKind, Span.Kind span2Kind) { - SpanRecord span = new SpanRecord(); + MutableSpan span = new MutableSpan(); span.kind(braveKind); span.startTimestamp(1L); span.finishTimestamp(0L); @@ -108,7 +108,7 @@ void flush(Kind braveKind, Span.Kind span2Kind) { } @Test public void remoteEndpoint() { - SpanRecord span = new SpanRecord(); + MutableSpan span = new MutableSpan(); Endpoint endpoint = Endpoint.newBuilder().serviceName("server").build(); span.kind(CLIENT); @@ -122,7 +122,7 @@ void flush(Kind braveKind, Span.Kind span2Kind) { // This prevents the server startTimestamp from overwriting the client one on the collector @Test public void writeTo_sharedStatus() { - SpanRecord span = new SpanRecord(); + MutableSpan span = new MutableSpan(); span.setShared(); span.startTimestamp(1L); @@ -134,7 +134,7 @@ void flush(Kind braveKind, Span.Kind span2Kind) { } @Test public void flushUnstartedNeitherSetsTimestampNorDuration() { - SpanRecord flushed = new SpanRecord(); + MutableSpan flushed = new MutableSpan(); flushed.finishTimestamp(0L); assertThat(flushed).extracting(s -> s.startTimestamp, s -> s.finishTimestamp) @@ -143,17 +143,17 @@ void flush(Kind braveKind, Span.Kind span2Kind) { /** We can't compute duration unless we started the span in the same tracer. */ @Test public void writeTo_finishUnstartedIsSameAsFlush() { - SpanRecord finishWithTimestamp = new SpanRecord(); + MutableSpan finishWithTimestamp = new MutableSpan(); finishWithTimestamp.finishTimestamp(2L); Span.Builder finishWithTimestampBuilder = Span.newBuilder(); finishWithTimestamp.writeTo(finishWithTimestampBuilder); - SpanRecord finishWithNoTimestamp = new SpanRecord(); + MutableSpan finishWithNoTimestamp = new MutableSpan(); finishWithNoTimestamp.finishTimestamp(0L); Span.Builder finishWithNoTimestampBuilder = Span.newBuilder(); finishWithNoTimestamp.writeTo(finishWithNoTimestampBuilder); - SpanRecord flush = new SpanRecord(); + MutableSpan flush = new MutableSpan(); Span.Builder flushBuilder = Span.newBuilder(); flush.writeTo(flushBuilder); @@ -162,7 +162,7 @@ void flush(Kind braveKind, Span.Kind span2Kind) { .isEqualToComparingFieldByFieldRecursively(flushBuilder); } - Span writeTo(SpanRecord span) { + Span writeTo(MutableSpan span) { Span.Builder result = Span.newBuilder().traceId(0L, 1L).id(1L); span.writeTo(result); return result.build(); diff --git a/brave/src/test/java/brave/internal/recorder/PendingSpanRecordsTest.java b/brave/src/test/java/brave/internal/recorder/PendingSpansTest.java similarity index 89% rename from brave/src/test/java/brave/internal/recorder/PendingSpanRecordsTest.java rename to brave/src/test/java/brave/internal/recorder/PendingSpansTest.java index deefe2c085..588cf293a9 100644 --- a/brave/src/test/java/brave/internal/recorder/PendingSpanRecordsTest.java +++ b/brave/src/test/java/brave/internal/recorder/PendingSpansTest.java @@ -14,17 +14,17 @@ import static org.assertj.core.api.Assertions.assertThat; -public class PendingSpanRecordsTest { +public class PendingSpansTest { Endpoint endpoint = Platform.get().endpoint(); List spans = new ArrayList<>(); TraceContext context = TraceContext.newBuilder().traceId(1).spanId(2).sampled(true).build(); AtomicInteger clock = new AtomicInteger(); - PendingSpanRecords map = new PendingSpanRecords( + PendingSpans map = new PendingSpans( endpoint, () -> clock.incrementAndGet() * 1000L, spans::add, new AtomicBoolean(false)); @Test public void getOrCreate_lazyCreatesASpan() { - PendingSpanRecord span = map.getOrCreate(context); + PendingSpan span = map.getOrCreate(context); assertThat(span).isNotNull(); } @@ -37,10 +37,10 @@ public void getOrCreate_reusesClockFromParent() { TraceContext trace2 = TraceContext.newBuilder().traceId(2L).spanId(2L).build(); TraceContext traceChild = TraceContext.newBuilder().traceId(1L).parentId(2L).spanId(3L).build(); - PendingSpanRecord traceSpan = map.getOrCreate(trace); - PendingSpanRecord traceJoinSpan = map.getOrCreate(traceJoin); - PendingSpanRecord trace2Span = map.getOrCreate(trace2); - PendingSpanRecord traceChildSpan = map.getOrCreate(traceChild); + PendingSpan traceSpan = map.getOrCreate(trace); + PendingSpan traceJoinSpan = map.getOrCreate(traceJoin); + PendingSpan trace2Span = map.getOrCreate(trace2); + PendingSpan traceChildSpan = map.getOrCreate(traceChild); assertThat(traceSpan.clock).isSameAs(traceChildSpan.clock); assertThat(traceSpan.clock).isSameAs(traceJoinSpan.clock); @@ -49,7 +49,7 @@ public void getOrCreate_reusesClockFromParent() { @Test public void getOrCreate_cachesReference() { - PendingSpanRecord span = map.getOrCreate(context); + PendingSpan span = map.getOrCreate(context); assertThat(map.getOrCreate(context)).isSameAs(span); } @@ -221,7 +221,7 @@ public void noop_afterGC() { /** We ensure that the implicit caller of reportOrphanedSpans doesn't crash on report failure */ @Test public void reportOrphanedSpans_whenReporterDies() { - PendingSpanRecords map = new PendingSpanRecords(endpoint, () -> 0, span -> + PendingSpans map = new PendingSpans(endpoint, () -> 0, span -> { throw new RuntimeException("die!"); }, new AtomicBoolean(true)); @@ -248,22 +248,22 @@ public void reportOrphanedSpans_whenReporterDies() { @Test public void toString_saysWhatReferentsAre() { assertThat(map.toString()) - .isEqualTo("PendingSpanRecords[]"); + .isEqualTo("PendingSpans[]"); map.getOrCreate(context); assertThat(map.toString()) - .isEqualTo("PendingSpanRecords[WeakReference(" + context + ")]"); + .isEqualTo("PendingSpans[WeakReference(" + context + ")]"); pretendGCHappened(); assertThat(map.toString()) - .isEqualTo("PendingSpanRecords[ClearedReference()]"); + .isEqualTo("PendingSpans[ClearedReference()]"); } @Test public void realKey_equalToItself() { - PendingSpanRecords.RealKey key = new PendingSpanRecords.RealKey(context, map); + PendingSpans.RealKey key = new PendingSpans.RealKey(context, map); assertThat(key).isEqualTo(key); key.clear(); assertThat(key).isEqualTo(key); @@ -271,8 +271,8 @@ public void realKey_equalToItself() { @Test public void realKey_equalToEquivalent() { - PendingSpanRecords.RealKey key = new PendingSpanRecords.RealKey(context, map); - PendingSpanRecords.RealKey key2 = new PendingSpanRecords.RealKey(context, map); + PendingSpans.RealKey key = new PendingSpans.RealKey(context, map); + PendingSpans.RealKey key2 = new PendingSpans.RealKey(context, map); assertThat(key).isEqualTo(key2); key.clear(); assertThat(key).isNotEqualTo(key2); @@ -282,7 +282,7 @@ public void realKey_equalToEquivalent() { /** In reality, this clears a reference even if it is strongly held by the test! */ void pretendGCHappened() { - ((PendingSpanRecords.RealKey) map.delegate.keySet().iterator().next()).clear(); + ((PendingSpans.RealKey) map.delegate.keySet().iterator().next()).clear(); } static void blockOnGC() { diff --git a/spring-beans/src/test/java/brave/spring/beans/TracingFactoryBeanTest.java b/spring-beans/src/test/java/brave/spring/beans/TracingFactoryBeanTest.java index ef19e7ecf5..63c13a6add 100755 --- a/spring-beans/src/test/java/brave/spring/beans/TracingFactoryBeanTest.java +++ b/spring-beans/src/test/java/brave/spring/beans/TracingFactoryBeanTest.java @@ -49,7 +49,7 @@ public class TracingFactoryBeanTest { ); assertThat(context.getBean("tracing", Tracing.class)) - .extracting("tracer.pendingSpanRecords.endpoint") + .extracting("tracer.pendingSpans.endpoint") .extracting("serviceName") .containsExactly("brave-webmvc-example"); } @@ -68,7 +68,7 @@ public class TracingFactoryBeanTest { ); assertThat(context.getBean("tracing", Tracing.class)) - .extracting("tracer.pendingSpanRecords.endpoint") + .extracting("tracer.pendingSpans.endpoint") .containsExactly(Endpoint.newBuilder() .serviceName("brave-webmvc-example") .ip("1.2.3.4") @@ -89,7 +89,7 @@ public class TracingFactoryBeanTest { ); assertThat(context.getBean("tracing", Tracing.class)) - .extracting("tracer.pendingSpanRecords.endpoint") + .extracting("tracer.pendingSpans.endpoint") .containsExactly(Endpoint.newBuilder() .serviceName("brave-webmvc-example") .ip("1.2.3.4")