Skip to content

Commit

Permalink
[#9595] Fix an issue where metric values in non sampling state were i…
Browse files Browse the repository at this point in the history
…ncorrect
  • Loading branch information
emeroad committed Feb 21, 2023
1 parent 6a38df1 commit 64cfaa5
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void before(Object target, Object[] args) {
logger.beforeInterceptor(target, args);
}

final Trace trace = traceContext.currentTraceObject();
final Trace trace = traceContext.currentRawTraceObject();
if (trace == null) {
return;
}
Expand All @@ -61,7 +61,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab
logger.afterInterceptor(target, args, result, throwable);
}

final Trace trace = traceContext.currentTraceObject();
final Trace trace = traceContext.currentRawTraceObject();
if (trace == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void before(Object target, Object[] args) {
logger.beforeInterceptor(target, args);
}

final Trace trace = traceContext.currentTraceObject();
final Trace trace = traceContext.currentRawTraceObject();
if (trace == null) {
return;
}
Expand All @@ -62,7 +62,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab
logger.afterInterceptor(target, args, result, throwable);
}

final Trace trace = traceContext.currentTraceObject();
final Trace trace = traceContext.currentRawTraceObject();
if (trace == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ public Trace continueAsyncContextTraceObject(TraceRoot traceRoot, LocalAsyncId l

@Override
public Trace continueDisableAsyncContextTraceObject(LocalTraceRoot traceRoot) {
final AsyncState asyncState = new DisableAsyncState();
final ActiveTraceHandle handle = registerActiveTrace(traceRoot);
final AsyncState asyncState = new ListenableAsyncState(traceRoot,
ListenableAsyncState.AsyncStateListener.EMPTY,
handle, uriStatStorage);

SpanRecorder spanRecorder = recorderFactory.newDisableSpanRecorder(traceRoot);
SpanEventRecorder spanEventRecorder = recorderFactory.newDisableSpanEventRecorder(traceRoot, asyncState);
return new DisableAsyncChildTrace(traceRoot, spanRecorder, spanEventRecorder);
Expand Down Expand Up @@ -238,10 +242,6 @@ private Trace newAsyncLocalTrace(long nextDisabledId) {
return new AsyncDisableTrace(traceRoot, spanRecorder, spanEventRecorder, asyncState);
}

private ActiveTraceHandle registerActiveTrace(TraceRoot traceRoot) {
return activeTraceRepository.register(traceRoot);
}

private ActiveTraceHandle registerActiveTrace(LocalTraceRoot localTraceRoot) {
return activeTraceRepository.register(localTraceRoot);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.navercorp.pinpoint.profiler.context.active;

import com.navercorp.pinpoint.profiler.context.id.LocalTraceRoot;
import com.navercorp.pinpoint.profiler.context.id.TraceRoot;

import java.util.List;

Expand All @@ -32,8 +31,6 @@ public interface ActiveTraceRepository {

List<Long> getThreadIdList();

ActiveTraceHandle register(TraceRoot traceRoot);

ActiveTraceHandle register(LocalTraceRoot traceRoot);

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.navercorp.pinpoint.common.trace.HistogramSchema;
import com.navercorp.pinpoint.common.trace.HistogramSlot;
import com.navercorp.pinpoint.profiler.context.id.LocalTraceRoot;
import com.navercorp.pinpoint.profiler.context.id.TraceRoot;
import com.navercorp.pinpoint.profiler.monitor.metric.response.ResponseTimeCollector;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -83,32 +82,20 @@ private void remove(ActiveTraceHandle key, long purgeTime) {
}
}

@Override
public ActiveTraceHandle register(TraceRoot traceRoot) {
final ActiveTrace activeTrace = new DefaultActiveTrace(traceRoot);
return register0(activeTrace);
}


@Override
public ActiveTraceHandle register(LocalTraceRoot localTraceRoot) {
final ActiveTrace activeTrace = new DefaultActiveTrace(localTraceRoot);
return register0(activeTrace);
}

private ActiveTraceHandle register0(ActiveTrace activeTrace) {
if (isDebug) {
logger.debug("register ActiveTrace key:{}", activeTrace);
logger.debug("register ActiveTrace key:{}", localTraceRoot);
}

final long id = activeTrace.getId();
final long id = localTraceRoot.getLocalTransactionId();

final ActiveTraceHandle handle = new DefaultActiveTraceHandle(id);
final ActiveTrace old = this.activeTraceInfoMap.put(handle, activeTrace);
if (old != null) {
if (logger.isWarnEnabled()) {
logger.warn("old activeTrace exist:{}", old);
}
}

this.activeTraceInfoMap.computeIfAbsent(handle, activeTraceHandle -> new DefaultActiveTrace(localTraceRoot));

return handle;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.navercorp.pinpoint.common.trace.BaseHistogramSchema;
import com.navercorp.pinpoint.profiler.context.id.LocalTraceRoot;
import com.navercorp.pinpoint.profiler.context.id.TraceRoot;
import com.navercorp.pinpoint.profiler.monitor.metric.response.ResponseTimeCollector;

import java.util.Collections;
Expand Down Expand Up @@ -53,11 +52,6 @@ public List<ActiveTraceSnapshot> snapshot() {
return Collections.emptyList();
}

@Override
public ActiveTraceHandle register(TraceRoot traceRoot) {
Objects.requireNonNull(traceRoot, "traceRoot");
return new EmptyActiveTraceHandle(traceRoot.getTraceStartTime());
}

@Override
public ActiveTraceHandle register(LocalTraceRoot traceRoot) {
Expand Down

0 comments on commit 64cfaa5

Please sign in to comment.