Skip to content

Commit

Permalink
Fix partial trace viewing after agent JVM restart
Browse files Browse the repository at this point in the history
Closes #269
  • Loading branch information
trask committed Sep 30, 2017
1 parent 873d3aa commit 3289d59
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import org.glowroot.wire.api.model.DownstreamServiceOuterClass.GlobalMeta;
import org.glowroot.wire.api.model.DownstreamServiceOuterClass.GlobalMetaRequest;
import org.glowroot.wire.api.model.DownstreamServiceOuterClass.HeaderRequest;
import org.glowroot.wire.api.model.DownstreamServiceOuterClass.HeaderResponse;
import org.glowroot.wire.api.model.DownstreamServiceOuterClass.HeapDumpFileInfo;
import org.glowroot.wire.api.model.DownstreamServiceOuterClass.HeapDumpRequest;
import org.glowroot.wire.api.model.DownstreamServiceOuterClass.HeapDumpResponse;
Expand Down Expand Up @@ -322,7 +323,12 @@ Trace.Header getHeader(String agentId, String traceId) throws Exception {
.setHeaderRequest(HeaderRequest.newBuilder()
.setTraceId(traceId))
.build());
return responseWrapper.getHeaderResponse().getHeader();
HeaderResponse response = responseWrapper.getHeaderResponse();
if (response.hasHeader()) {
return response.getHeader();
} else {
return null;
}
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ class LiveTraceRepositoryImpl implements LiveTraceRepository {

@Override
public @Nullable Profile getAuxThreadProfile(String agentRollupId, String agentId,
String traceId)
throws Exception {
String traceId) throws Exception {
checkValidAgentIdForRequest(agentRollupId, agentId);
return downstreamService.getAuxThreadProfile(agentId, traceId);
}
Expand Down
38 changes: 31 additions & 7 deletions ui/src/main/java/org/glowroot/ui/TraceCommonService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.common.io.CharStreams;
import org.immutables.value.Value;

import org.glowroot.common.live.LiveJvmService.AgentNotConnectedException;
import org.glowroot.common.live.LiveTraceRepository;
import org.glowroot.common.live.LiveTraceRepository.Entries;
import org.glowroot.common.live.LiveTraceRepository.Existence;
Expand Down Expand Up @@ -63,7 +64,12 @@ String getHeaderJson(String agentRollupId, String agentId, String traceId,
if (checkLiveTraces) {
// check active/pending traces first, and lastly stored traces to make sure that the
// trace is not missed if it is in transition between these states
Trace.Header header = liveTraceRepository.getHeader(agentRollupId, agentId, traceId);
Trace.Header header;
try {
header = liveTraceRepository.getHeader(agentRollupId, agentId, traceId);
} catch (AgentNotConnectedException e) {
header = null;
}
if (header != null) {
return toJsonLiveHeader(agentId, header);
}
Expand All @@ -85,7 +91,12 @@ String getEntriesJson(String agentRollupId, String agentId, String traceId,
if (checkLiveTraces) {
// check active/pending traces first, and lastly stored traces to make sure that the
// trace is not missed if it is in transition between these states
Entries entries = liveTraceRepository.getEntries(agentRollupId, agentId, traceId);
Entries entries;
try {
entries = liveTraceRepository.getEntries(agentRollupId, agentId, traceId);
} catch (AgentNotConnectedException e) {
entries = null;
}
if (entries != null) {
return toJson(entries);
}
Expand All @@ -102,8 +113,12 @@ String getMainThreadProfileJson(String agentRollupId, String agentId, String tra
if (checkLiveTraces) {
// check active/pending traces first, and lastly stored traces to make sure that the
// trace is not missed if it is in transition between these states
Profile profile =
liveTraceRepository.getMainThreadProfile(agentRollupId, agentId, traceId);
Profile profile;
try {
profile = liveTraceRepository.getMainThreadProfile(agentRollupId, agentId, traceId);
} catch (AgentNotConnectedException e) {
profile = null;
}
if (profile != null) {
return toJson(profile);
}
Expand All @@ -120,8 +135,12 @@ String getAuxThreadProfileJson(String agentRollupId, String agentId, String trac
if (checkLiveTraces) {
// check active/pending traces first, and lastly stored traces to make sure that the
// trace is not missed if it is in transition between these states
Profile profile =
liveTraceRepository.getAuxThreadProfile(agentRollupId, agentId, traceId);
Profile profile;
try {
profile = liveTraceRepository.getAuxThreadProfile(agentRollupId, agentId, traceId);
} catch (AgentNotConnectedException e) {
profile = null;
}
if (profile != null) {
return toJson(profile);
}
Expand All @@ -136,7 +155,12 @@ TraceExport getExport(String agentRollupId, String agentId, String traceId,
if (checkLiveTraces) {
// check active/pending traces first, and lastly stored traces to make sure that the
// trace is not missed if it is in transition between these states
Trace trace = liveTraceRepository.getFullTrace(agentRollupId, agentId, traceId);
Trace trace;
try {
trace = liveTraceRepository.getFullTrace(agentRollupId, agentId, traceId);
} catch (AgentNotConnectedException e) {
trace = null;
}
if (trace != null) {
Trace.Header header = trace.getHeader();
return ImmutableTraceExport.builder()
Expand Down

0 comments on commit 3289d59

Please sign in to comment.