Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#9575] Polishing #9613

Merged
merged 2 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,13 +52,12 @@ public class AsyncChildTrace implements Trace {
private final TraceRoot traceRoot;
private final LocalAsyncId localAsyncId;

public AsyncChildTrace(final TraceRoot traceRoot, CallStack<SpanEvent> callStack, Storage storage, boolean sampling,
SpanRecorder spanRecorder, WrappedSpanEventRecorder wrappedSpanEventRecorder, final LocalAsyncId localAsyncId) {
public AsyncChildTrace(final TraceRoot traceRoot, CallStack<SpanEvent> 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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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<SpanEvent> callStack,
Storage storage,
SpanRecorder spanRecorder,
WrappedSpanEventRecorder wrappedSpanEventRecorder,
AsyncState asyncState) {
super(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, CloseListener.EMPTY);
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();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.navercorp.pinpoint.profiler.context;

public interface CloseListener {
void close(Span span);

CloseListener EMPTY = new CloseListener() {
@Override
public void close(Span span) {
}
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +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<SpanEvent> 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,
wrappedSpanEventRecorder, handle, uriStatStorage);
final CloseListener closeListener = new DefaultCloseListener(handle, uriStatStorage);
return new DefaultTrace(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, closeListener);
} else {
return newLocalTrace(state.nextId());
}
Expand Down Expand Up @@ -125,22 +123,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<SpanEvent> 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,
handle, uriStatStorage);
final CloseListener closeListener = new DefaultCloseListener(handle, uriStatStorage);
return new DefaultTrace(span, callStack, storage, spanRecorder, wrappedSpanEventRecorder, closeListener);
} else {
return newLocalTrace(state.nextId());
}
Expand All @@ -155,11 +150,11 @@ public Trace continueAsyncContextTraceObject(TraceRoot traceRoot, LocalAsyncId l

final CallStack<SpanEvent> 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);
}
Expand All @@ -171,8 +166,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);

Expand All @@ -184,13 +178,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());
}
Expand All @@ -211,8 +202,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);
Expand All @@ -223,15 +213,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());
}
Expand Down
Loading