From f0fdbce258aa3a5653bb4338e7f9ed8999ba1583 Mon Sep 17 00:00:00 2001 From: emeroad Date: Fri, 6 Jan 2023 19:24:33 +0900 Subject: [PATCH] [#9575] Polishing --- .../profiler/context/AsyncChildTrace.java | 6 +- .../profiler/context/AsyncDefaultTrace.java | 46 +++++ .../pinpoint/profiler/context/AsyncTrace.java | 160 ------------------ .../context/DefaultBaseTraceFactory.java | 41 ++--- .../profiler/context/DefaultTrace.java | 14 +- .../recorder/DefaultRecorderFactory.java | 8 +- .../context/recorder/DefaultSpanRecorder.java | 22 +-- .../context/recorder/RecorderFactory.java | 4 +- .../recorder/TraceRootSpanRecorder.java | 7 +- .../profiler/context/DefaultTraceTest.java | 10 +- .../pinpoint/profiler/context/TraceTest.java | 10 +- .../recorder/DefaultSpanRecorderTest.java | 12 +- 12 files changed, 95 insertions(+), 245 deletions(-) create mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncDefaultTrace.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncTrace.java diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncChildTrace.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncChildTrace.java index ef392f7fe8f2..6870177cde72 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncChildTrace.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncChildTrace.java @@ -22,7 +22,6 @@ import com.navercorp.pinpoint.bootstrap.context.TraceId; import com.navercorp.pinpoint.bootstrap.context.scope.TraceScope; import com.navercorp.pinpoint.common.annotations.VisibleForTesting; -import com.navercorp.pinpoint.common.util.Assert; import com.navercorp.pinpoint.exception.PinpointException; import com.navercorp.pinpoint.profiler.context.id.TraceRoot; import com.navercorp.pinpoint.profiler.context.recorder.WrappedSpanEventRecorder; @@ -53,13 +52,12 @@ public class AsyncChildTrace implements Trace { private final TraceRoot traceRoot; private final LocalAsyncId localAsyncId; - public AsyncChildTrace(final TraceRoot traceRoot, CallStack callStack, Storage storage, boolean sampling, - SpanRecorder spanRecorder, WrappedSpanEventRecorder wrappedSpanEventRecorder, final LocalAsyncId localAsyncId) { + public AsyncChildTrace(final TraceRoot traceRoot, CallStack callStack, Storage storage, + SpanRecorder spanRecorder, WrappedSpanEventRecorder wrappedSpanEventRecorder, final LocalAsyncId localAsyncId) { this.traceRoot = Objects.requireNonNull(traceRoot, "traceRoot"); this.callStack = Objects.requireNonNull(callStack, "callStack"); this.storage = Objects.requireNonNull(storage, "storage"); - Assert.isTrue(sampling, "sampling must be true"); this.spanRecorder = Objects.requireNonNull(spanRecorder, "spanRecorder"); this.wrappedSpanEventRecorder = Objects.requireNonNull(wrappedSpanEventRecorder, "wrappedSpanEventRecorder"); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncDefaultTrace.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncDefaultTrace.java new file mode 100644 index 000000000000..ae808bad66a0 --- /dev/null +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncDefaultTrace.java @@ -0,0 +1,46 @@ +package com.navercorp.pinpoint.profiler.context; + +import com.navercorp.pinpoint.bootstrap.context.AsyncState; +import com.navercorp.pinpoint.bootstrap.context.SpanRecorder; +import com.navercorp.pinpoint.profiler.context.recorder.WrappedSpanEventRecorder; +import com.navercorp.pinpoint.profiler.context.storage.Storage; + +import java.util.Objects; + +public class AsyncDefaultTrace extends DefaultTrace { + private final AsyncState asyncState; + + public AsyncDefaultTrace(Span span, + CallStack callStack, + Storage storage, + SpanRecorder spanRecorder, + WrappedSpanEventRecorder wrappedSpanEventRecorder, + AsyncState asyncState) { + super(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, null, null); + this.asyncState = Objects.requireNonNull(asyncState, "asyncState"); + } + + @Override + public void close() { + if (asyncState.await()) { + // flush. + super.flush(); + if (isDebug) { + logger.debug("Flush trace={}, asyncState={}", this, this.asyncState); + } + } else { + // close. + super.close(); + if (isDebug) { + logger.debug("Close trace={}. asyncState={}", this, this.asyncState); + } + } + } + + @Override + public String toString() { + return "AsyncDefaultTrace{" + + "asyncState=" + asyncState + + "} " + super.toString(); + } +} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncTrace.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncTrace.java deleted file mode 100644 index b5e4de4f7696..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncTrace.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright 2015 NAVER Corp. - * - * 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.navercorp.pinpoint.profiler.context; - -import com.navercorp.pinpoint.bootstrap.context.AsyncState; -import com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder; -import com.navercorp.pinpoint.bootstrap.context.SpanRecorder; -import com.navercorp.pinpoint.bootstrap.context.Trace; -import com.navercorp.pinpoint.bootstrap.context.TraceId; -import com.navercorp.pinpoint.bootstrap.context.scope.TraceScope; -import com.navercorp.pinpoint.profiler.context.id.TraceRoot; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.util.Objects; - -public class AsyncTrace implements Trace { - - private static final Logger logger = LogManager.getLogger(AsyncTrace.class.getName()); - private static final boolean isDebug = logger.isDebugEnabled(); - - private final TraceRoot traceRoot; - private final DefaultTrace trace; - - private final AsyncState asyncState; - - public AsyncTrace(final TraceRoot traceRoot, final DefaultTrace trace, final AsyncState asyncState) { - this.traceRoot = Objects.requireNonNull(traceRoot, "traceRoot"); - this.trace = Objects.requireNonNull(trace, "trace"); - this.asyncState = Objects.requireNonNull(asyncState, "asyncState"); - } - - - @Override - public long getId() { - return traceRoot.getLocalTransactionId(); - } - - @Override - public long getStartTime() { - return this.traceRoot.getTraceStartTime(); - } - - - @Override - public TraceId getTraceId() { - return this.traceRoot.getTraceId(); - } - - @Override - public boolean canSampled() { - return trace.canSampled(); - } - - @Override - public boolean isRoot() { - return this.traceRoot.getTraceId().isRoot(); - } - - @Override - public SpanEventRecorder traceBlockBegin() { - return trace.traceBlockBegin(); - } - - @Override - public SpanEventRecorder traceBlockBegin(int stackId) { - return trace.traceBlockBegin(stackId); - } - - @Override - public void traceBlockEnd() { - trace.traceBlockEnd(); - } - - @Override - public void traceBlockEnd(int stackId) { - trace.traceBlockEnd(stackId); - } - - @Override - public boolean isAsync() { - return false; - } - - @Override - public boolean isRootStack() { - return this.trace.isRootStack(); - } - - @Override - public boolean isClosed() { - return this.trace.isClosed(); - } - - @Override - public void close() { - if (asyncState.await()) { - // flush. - this.trace.flush(); - if (isDebug) { - logger.debug("Flush trace={}, asyncState={}", this, this.asyncState); - } - } else { - // close. - this.trace.close(); - if (isDebug) { - logger.debug("Close trace={}. asyncState={}", this, this.asyncState); - } - } - - } - - - @Override - public SpanRecorder getSpanRecorder() { - return trace.getSpanRecorder(); - } - - @Override - public SpanEventRecorder currentSpanEventRecorder() { - return trace.currentSpanEventRecorder(); - } - - @Override - public int getCallStackFrameId() { - return trace.getCallStackFrameId(); - } - - @Override - public TraceScope getScope(String name) { - return trace.getScope(name); - } - - @Override - public TraceScope addScope(String name) { - return trace.addScope(name); - } - - @Override - public String toString() { - return "AsyncTrace{" + - "traceRoot=" + traceRoot + - ", trace=" + trace + - ", asyncState=" + asyncState + - '}'; - } -} \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultBaseTraceFactory.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultBaseTraceFactory.java index f3d5ff0ac618..2f85ab7e046b 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultBaseTraceFactory.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultBaseTraceFactory.java @@ -84,19 +84,18 @@ public Trace continueTraceObject(final TraceId traceId) { // TODO need to consider as a target to sample in case Trace object has a sampling flag (true) marked on previous node. // Check max throughput(permits per seconds) final TraceSampler.State state = traceSampler.isContinueSampled(); - final boolean sampling = state.isSampled(); - if (sampling) { + if (state.isSampled()) { final TraceRoot traceRoot = traceRootFactory.continueTraceRoot(traceId, state.nextId()); final Span span = spanFactory.newSpan(traceRoot); final SpanChunkFactory spanChunkFactory = new DefaultSpanChunkFactory(traceRoot); final Storage storage = storageFactory.createStorage(spanChunkFactory); final CallStack callStack = callStackFactory.newCallStack(); - final SpanRecorder spanRecorder = recorderFactory.newSpanRecorder(span, traceId.isRoot(), sampling); + final SpanRecorder spanRecorder = recorderFactory.newSpanRecorder(span); final WrappedSpanEventRecorder wrappedSpanEventRecorder = recorderFactory.newWrappedSpanEventRecorder(traceRoot); final ActiveTraceHandle handle = registerActiveTrace(traceRoot); - return new DefaultTrace(span, callStack, storage, sampling, spanRecorder, + return new DefaultTrace(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, handle, uriStatStorage); } else { return newLocalTrace(state.nextId()); @@ -125,21 +124,19 @@ public Trace newTraceObject(String urlPath) { } Trace newTraceObject(TraceSampler.State state) { - final boolean sampling = state.isSampled(); - if (sampling) { + if (state.isSampled()) { final TraceRoot traceRoot = traceRootFactory.newTraceRoot(state.nextId()); final Span span = spanFactory.newSpan(traceRoot); final SpanChunkFactory spanChunkFactory = new DefaultSpanChunkFactory(traceRoot); final Storage storage = storageFactory.createStorage(spanChunkFactory); final CallStack callStack = callStackFactory.newCallStack(); - final TraceId traceId = traceRoot.getTraceId(); - final SpanRecorder spanRecorder = recorderFactory.newSpanRecorder(span, traceId.isRoot(), sampling); + final SpanRecorder spanRecorder = recorderFactory.newSpanRecorder(span); final WrappedSpanEventRecorder wrappedSpanEventRecorder = recorderFactory.newWrappedSpanEventRecorder(traceRoot); final ActiveTraceHandle handle = registerActiveTrace(traceRoot); - return new DefaultTrace(span, callStack, storage, sampling, spanRecorder, wrappedSpanEventRecorder, + return new DefaultTrace(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, handle, uriStatStorage); } else { return newLocalTrace(state.nextId()); @@ -155,11 +152,11 @@ public Trace continueAsyncContextTraceObject(TraceRoot traceRoot, LocalAsyncId l final CallStack callStack = callStackFactory.newCallStack(); - final SpanRecorder spanRecorder = recorderFactory.newTraceRootSpanRecorder(traceRoot, sampling); + final SpanRecorder spanRecorder = recorderFactory.newTraceRootSpanRecorder(traceRoot); final WrappedSpanEventRecorder wrappedSpanEventRecorder = recorderFactory.newWrappedSpanEventRecorder(traceRoot); - return new AsyncChildTrace(traceRoot, callStack, storage, sampling, spanRecorder, wrappedSpanEventRecorder, localAsyncId); + return new AsyncChildTrace(traceRoot, callStack, storage, spanRecorder, wrappedSpanEventRecorder, localAsyncId); } else { return new DisableAsyncChildTrace(traceRoot, localAsyncId); } @@ -171,8 +168,7 @@ public Trace continueAsyncContextTraceObject(TraceRoot traceRoot, LocalAsyncId l @Override public Trace continueAsyncTraceObject(final TraceId traceId) { final TraceSampler.State state = traceSampler.isContinueSampled(); - final boolean sampling = state.isSampled(); - if (sampling) { + if (state.isSampled()) { final TraceRoot traceRoot = traceRootFactory.continueTraceRoot(traceId, state.nextId()); final Span span = spanFactory.newSpan(traceRoot); @@ -184,13 +180,10 @@ public Trace continueAsyncTraceObject(final TraceId traceId) { final SpanAsyncStateListener asyncStateListener = new SpanAsyncStateListener(span, storageFactory); final AsyncState asyncState = new ListenableAsyncState(traceRoot, asyncStateListener, handle, uriStatStorage); - final SpanRecorder spanRecorder = recorderFactory.newSpanRecorder(span, traceId.isRoot(), sampling); + final SpanRecorder spanRecorder = recorderFactory.newSpanRecorder(span); final WrappedSpanEventRecorder wrappedSpanEventRecorder = recorderFactory.newWrappedSpanEventRecorder(traceRoot, asyncState); - - final DefaultTrace trace = new DefaultTrace(span, callStack, storage, sampling, spanRecorder, wrappedSpanEventRecorder); - - return new AsyncTrace(traceRoot, trace, asyncState); + return new AsyncDefaultTrace(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, asyncState); } else { return newLocalTrace(state.nextId()); } @@ -211,8 +204,7 @@ public Trace newAsyncTraceObject(String urlPath) { } Trace newAsyncTraceObject(TraceSampler.State state) { - final boolean sampling = state.isSampled(); - if (sampling) { + if (state.isSampled()) { final TraceRoot traceRoot = traceRootFactory.newTraceRoot(state.nextId()); final Span span = spanFactory.newSpan(traceRoot); final SpanChunkFactory spanChunkFactory = new DefaultSpanChunkFactory(traceRoot); @@ -223,15 +215,10 @@ Trace newAsyncTraceObject(TraceSampler.State state) { final SpanAsyncStateListener asyncStateListener = new SpanAsyncStateListener(span, storageFactory); final AsyncState asyncState = new ListenableAsyncState(traceRoot, asyncStateListener, handle, uriStatStorage); - - final TraceId traceId = traceRoot.getTraceId(); - final SpanRecorder spanRecorder = recorderFactory.newSpanRecorder(span, traceId.isRoot(), sampling); + final SpanRecorder spanRecorder = recorderFactory.newSpanRecorder(span); final WrappedSpanEventRecorder wrappedSpanEventRecorder = recorderFactory.newWrappedSpanEventRecorder(traceRoot, asyncState); - - final DefaultTrace trace = new DefaultTrace(span, callStack, storage, sampling, spanRecorder, wrappedSpanEventRecorder); - - return new AsyncTrace(traceRoot, trace, asyncState); + return new AsyncDefaultTrace(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, asyncState); } else { return newLocalTrace(state.nextId()); } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTrace.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTrace.java index 2db568973c81..eeb35a390fc5 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTrace.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTrace.java @@ -22,7 +22,6 @@ import com.navercorp.pinpoint.bootstrap.context.TraceId; import com.navercorp.pinpoint.bootstrap.context.scope.TraceScope; import com.navercorp.pinpoint.common.annotations.VisibleForTesting; -import com.navercorp.pinpoint.common.util.Assert; import com.navercorp.pinpoint.exception.PinpointException; import com.navercorp.pinpoint.profiler.context.active.ActiveTraceHandle; import com.navercorp.pinpoint.profiler.context.id.Shared; @@ -42,10 +41,10 @@ * @author emeroad * @author jaehong.kim */ -public final class DefaultTrace implements Trace { +public class DefaultTrace implements Trace { - private static final Logger logger = LogManager.getLogger(DefaultTrace.class.getName()); - private static final boolean isDebug = logger.isDebugEnabled(); + static final Logger logger = LogManager.getLogger(DefaultTrace.class.getName()); + static final boolean isDebug = logger.isDebugEnabled(); private final CallStack callStack; @@ -64,12 +63,12 @@ public final class DefaultTrace implements Trace { @Nullable private final UriStatStorage uriStatStorage; - public DefaultTrace(Span span, CallStack callStack, Storage storage, boolean sampling, + public DefaultTrace(Span span, CallStack callStack, Storage storage, SpanRecorder spanRecorder, WrappedSpanEventRecorder wrappedSpanEventRecorder) { - this(span, callStack, storage, sampling, spanRecorder, wrappedSpanEventRecorder, null, null); + this(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, null, null); } - public DefaultTrace(Span span, CallStack callStack, Storage storage, boolean sampling, + public DefaultTrace(Span span, CallStack callStack, Storage storage, SpanRecorder spanRecorder, WrappedSpanEventRecorder wrappedSpanEventRecorder, ActiveTraceHandle activeTraceHandle, UriStatStorage uriStatStorage) { @@ -77,7 +76,6 @@ public DefaultTrace(Span span, CallStack callStack, Storage storage, this.span = Objects.requireNonNull(span, "span"); this.callStack = Objects.requireNonNull(callStack, "callStack"); this.storage = Objects.requireNonNull(storage, "storage"); - Assert.isTrue(sampling, "sampling must be true"); this.spanRecorder = Objects.requireNonNull(spanRecorder, "spanRecorder"); this.wrappedSpanEventRecorder = Objects.requireNonNull(wrappedSpanEventRecorder, "wrappedSpanEventRecorder"); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultRecorderFactory.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultRecorderFactory.java index c346dcbcb9d9..de7d79ec591a 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultRecorderFactory.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultRecorderFactory.java @@ -50,13 +50,13 @@ public DefaultRecorderFactory(Provider asyncContextFactoryP } @Override - public SpanRecorder newSpanRecorder(Span span, boolean isRoot, boolean sampling) { - return new DefaultSpanRecorder(span, isRoot, sampling, stringMetaDataService, sqlMetaDataService, errorHandler); + public SpanRecorder newSpanRecorder(Span span) { + return new DefaultSpanRecorder(span, stringMetaDataService, sqlMetaDataService, errorHandler); } @Override - public SpanRecorder newTraceRootSpanRecorder(TraceRoot traceRoot, boolean sampling) { - return new TraceRootSpanRecorder(traceRoot, sampling); + public SpanRecorder newTraceRootSpanRecorder(TraceRoot traceRoot) { + return new TraceRootSpanRecorder(traceRoot); } @Override diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultSpanRecorder.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultSpanRecorder.java index 0e4d660f60b8..fe8c2c8f4ea4 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultSpanRecorder.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultSpanRecorder.java @@ -29,30 +29,24 @@ import org.apache.logging.log4j.Logger; /** - * + * * @author jaehong.kim * */ public class DefaultSpanRecorder extends AbstractRecorder implements SpanRecorder { private static final Logger logger = LogManager.getLogger(DefaultTrace.class.getName()); private static final boolean isDebug = logger.isDebugEnabled(); - + private final Span span; - private final boolean isRoot; - private final boolean sampling; - - public DefaultSpanRecorder(final Span span, final boolean isRoot, final boolean sampling, - final StringMetaDataService stringMetaDataService, SqlMetaDataService sqlMetaDataService, + + public DefaultSpanRecorder(final Span span, + final StringMetaDataService stringMetaDataService, + final SqlMetaDataService sqlMetaDataService, final IgnoreErrorHandler errorHandler) { super(stringMetaDataService, sqlMetaDataService, errorHandler); this.span = span; - this.isRoot = isRoot; - this.sampling = sampling; } - public Span getSpan() { - return span; - } @Override public void recordStartTime(long startTime) { @@ -124,12 +118,12 @@ public void recordAcceptorHost(String host) { @Override public boolean canSampled() { - return sampling; + return true; } @Override public boolean isRoot() { - return isRoot; + return span.getTraceRoot().getTraceId().isRoot(); } @Override diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/RecorderFactory.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/RecorderFactory.java index 1b1f8b45d6b7..94fd2fcd2dbf 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/RecorderFactory.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/RecorderFactory.java @@ -27,9 +27,9 @@ */ public interface RecorderFactory { - SpanRecorder newSpanRecorder(final Span span, final boolean isRoot, final boolean sampling); + SpanRecorder newSpanRecorder(final Span span); - SpanRecorder newTraceRootSpanRecorder(TraceRoot traceRoot, boolean sampling); + SpanRecorder newTraceRootSpanRecorder(TraceRoot traceRoot); SpanRecorder newDisableSpanRecorder(LocalTraceRoot traceRoot); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/TraceRootSpanRecorder.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/TraceRootSpanRecorder.java index c5caeba5b920..6ce3307dd822 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/TraceRootSpanRecorder.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/recorder/TraceRootSpanRecorder.java @@ -33,17 +33,14 @@ public class TraceRootSpanRecorder implements SpanRecorder { private final TraceRoot traceRoot; - private final boolean sampling; - public TraceRootSpanRecorder(TraceRoot traceRoot, boolean sampling) { + public TraceRootSpanRecorder(TraceRoot traceRoot) { this.traceRoot = Objects.requireNonNull(traceRoot, "traceRoot"); - - this.sampling = sampling; } @Override public boolean canSampled() { - return sampling; + return true; } @Override diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/DefaultTraceTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/DefaultTraceTest.java index a39a594f2238..1426964ae4fe 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/DefaultTraceTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/DefaultTraceTest.java @@ -19,11 +19,9 @@ import com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder; import com.navercorp.pinpoint.bootstrap.context.SpanRecorder; import com.navercorp.pinpoint.bootstrap.context.Trace; -import com.navercorp.pinpoint.bootstrap.context.TraceId; import com.navercorp.pinpoint.profiler.context.active.ActiveTraceHandle; import com.navercorp.pinpoint.profiler.context.errorhandler.BypassErrorHandler; import com.navercorp.pinpoint.profiler.context.errorhandler.IgnoreErrorHandler; -import com.navercorp.pinpoint.profiler.context.id.DefaultTraceId; import com.navercorp.pinpoint.profiler.context.id.Shared; import com.navercorp.pinpoint.profiler.context.id.TraceRoot; import com.navercorp.pinpoint.profiler.context.recorder.DefaultSpanRecorder; @@ -152,9 +150,6 @@ private Trace newTrace() { private Trace newTrace(final int maxCallStackDepth) { when(traceRoot.getShared()).thenReturn(shared); - TraceId traceId = new DefaultTraceId(agentId, agentStartTime, 0); - when(traceRoot.getTraceId()).thenReturn(traceId); - CallStackFactory callStackFactory = new CallStackFactoryV1(maxCallStackDepth, -1, 1000); CallStack callStack = callStackFactory.newCallStack(); @@ -164,10 +159,9 @@ private Trace newTrace(final int maxCallStackDepth) { UriStatStorage uriStatStorage = mock(UriStatStorage.class); final Span span = spanFactory.newSpan(traceRoot); - final boolean root = span.getTraceRoot().getTraceId().isRoot(); - final SpanRecorder spanRecorder = new DefaultSpanRecorder(span, root, true, stringMetaDataService, sqlMetaDataService, errorHandler); + final SpanRecorder spanRecorder = new DefaultSpanRecorder(span, stringMetaDataService, sqlMetaDataService, errorHandler); final WrappedSpanEventRecorder wrappedSpanEventRecorder = new WrappedSpanEventRecorder(traceRoot, asyncContextFactory, stringMetaDataService, sqlMetaDataService, errorHandler); - return new DefaultTrace(span, callStack, storage, true, spanRecorder, wrappedSpanEventRecorder, ActiveTraceHandle.EMPTY_HANDLE, uriStatStorage); + return new DefaultTrace(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, ActiveTraceHandle.EMPTY_HANDLE, uriStatStorage); } } diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TraceTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TraceTest.java index b849fef50e49..2c7b5ddd0c19 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TraceTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/TraceTest.java @@ -73,8 +73,7 @@ public void trace() { final CallStack callStack = newCallStack(); final Span span = newSpan(traceRoot); - boolean root = span.getTraceRoot().getTraceId().isRoot(); - SpanRecorder spanRecorder = new DefaultSpanRecorder(span, root, true, stringMetaDataService, sqlMetaDataService, errorHandler); + SpanRecorder spanRecorder = new DefaultSpanRecorder(span, stringMetaDataService, sqlMetaDataService, errorHandler); WrappedSpanEventRecorder wrappedSpanEventRecorder = new WrappedSpanEventRecorder(traceRoot, asyncContextFactory, stringMetaDataService, sqlMetaDataService, errorHandler); AsyncContextFactory asyncContextFactory = mock(AsyncContextFactory.class); @@ -82,7 +81,7 @@ public void trace() { Storage storage = mock(Storage.class); UriStatStorage uriStatStorage = mock(UriStatStorage.class); - Trace trace = new DefaultTrace(span, callStack, storage, true, spanRecorder, wrappedSpanEventRecorder, ActiveTraceHandle.EMPTY_HANDLE, uriStatStorage); + Trace trace = new DefaultTrace(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, ActiveTraceHandle.EMPTY_HANDLE, uriStatStorage); trace.traceBlockBegin(); // get data form db @@ -107,8 +106,7 @@ public void popEventTest() { final Span span = newSpan(traceRoot); - final boolean root = span.getTraceRoot().getTraceId().isRoot(); - SpanRecorder spanRecorder = new DefaultSpanRecorder(span, root, true, stringMetaDataService, sqlMetaDataService, errorHandler); + SpanRecorder spanRecorder = new DefaultSpanRecorder(span, stringMetaDataService, sqlMetaDataService, errorHandler); WrappedSpanEventRecorder wrappedSpanEventRecorder = new WrappedSpanEventRecorder(traceRoot, asyncContextFactory, stringMetaDataService, sqlMetaDataService, errorHandler); @@ -117,7 +115,7 @@ public void popEventTest() { Storage storage = mock(Storage.class); UriStatStorage uriStatStorage = mock(UriStatStorage.class); - Trace trace = new DefaultTrace(span, callStack, storage, true, spanRecorder, wrappedSpanEventRecorder, + Trace trace = new DefaultTrace(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, ActiveTraceHandle.EMPTY_HANDLE, uriStatStorage); trace.close(); diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultSpanRecorderTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultSpanRecorderTest.java index 850f5d7d3099..07b3f70e9810 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultSpanRecorderTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/context/recorder/DefaultSpanRecorderTest.java @@ -17,7 +17,6 @@ package com.navercorp.pinpoint.profiler.context.recorder; import com.navercorp.pinpoint.bootstrap.context.SpanRecorder; -import com.navercorp.pinpoint.bootstrap.context.TraceId; import com.navercorp.pinpoint.profiler.context.Span; import com.navercorp.pinpoint.profiler.context.errorhandler.BypassErrorHandler; import com.navercorp.pinpoint.profiler.context.errorhandler.IgnoreErrorHandler; @@ -44,8 +43,7 @@ public class DefaultSpanRecorderTest { private TraceRoot traceRoot; @Mock private Shared shared; - @Mock - private TraceId traceId; + @Mock private StringMetaDataService stringMetaDataService; @Mock @@ -54,10 +52,10 @@ public class DefaultSpanRecorderTest { private final IgnoreErrorHandler errorHandler = new BypassErrorHandler(); @Test - public void testRecordApiId() throws Exception { + public void testRecordApiId() { Span span = new Span(traceRoot); - SpanRecorder recorder = new DefaultSpanRecorder(span, true, true, stringMetaDataService, sqlMetaDataService, errorHandler); + SpanRecorder recorder = new DefaultSpanRecorder(span, stringMetaDataService, sqlMetaDataService, errorHandler); final int API_ID = 1000; recorder.recordApiId(API_ID); @@ -66,13 +64,13 @@ public void testRecordApiId() throws Exception { } @Test - public void testRecordEndPoint() throws Exception { + public void testRecordEndPoint() { when(traceRoot.getShared()).thenReturn(shared); Span span = new Span(traceRoot); - SpanRecorder recorder = new DefaultSpanRecorder(span, true, true, stringMetaDataService, sqlMetaDataService, errorHandler); + SpanRecorder recorder = new DefaultSpanRecorder(span, stringMetaDataService, sqlMetaDataService, errorHandler); final String endPoint = "endPoint"; recorder.recordEndPoint(endPoint);