Skip to content
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 @@ -31,6 +31,7 @@ public static StructuredTraceGraph buildGraph(StructuredTrace trace) {
trace.getCustomerId());
cachedTraceThreadLocal.set(StructuredTrace.newBuilder(trace).build());
cachedGraphThreadLocal.set(graph);
debugGraph("Case: Rebuilding the graph.", graph, trace);
return graph;
}

Expand All @@ -46,8 +47,50 @@ public static StructuredTraceGraph buildGraph(StructuredTrace trace) {
trace.getCustomerId());
cachedTraceThreadLocal.set(StructuredTrace.newBuilder(trace).build());
cachedGraphThreadLocal.set(graph);
debugGraph("Case: Partially building the graph.", graph, trace);
return graph;
}

debugGraph("Case: Not building the graph.", cachedGraphThreadLocal.get(), trace);
return cachedGraphThreadLocal.get();
}

private static void debugGraph(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: we will remove this after debugging.

String logPrefix, StructuredTraceGraph graph, StructuredTrace trace) {
if (null != graph
&& (null == graph.getTraceEntitiesGraph() || null == graph.getTraceEventsGraph())) {
LOG.info(
logPrefix
+ "StructuredTraceGraph is not built correctly, trace {}, Is events graph non-null: {}."
+ " Is entities graph non-null: {}",
trace,
(null != graph.getTraceEventsGraph()),
(null != graph.getTraceEntitiesGraph()));

// build the graph again and check
StructuredTraceGraph tempGraph = StructuredTraceGraph.createGraph(trace);
LOG.info(
logPrefix
+ "Recreating StructuredTraceGraph. Is events graph non-null: {}."
+ " Is entities graph non-null: {}",
(null != tempGraph.getTraceEventsGraph()),
(null != tempGraph.getTraceEntitiesGraph()));

tempGraph = StructuredTraceGraph.reCreateTraceEventsGraph(trace);
LOG.info(
logPrefix
+ "Recreating events graph. Is events graph non-null: {}."
+ " Is entities graph non-null: {}",
(null != tempGraph.getTraceEventsGraph()),
(null != tempGraph.getTraceEntitiesGraph()));

tempGraph = StructuredTraceGraph.reCreateTraceEntitiesGraph(trace);
LOG.info(
logPrefix
+ "Recreating entities graph. Is events graph non-null: {}."
+ " Is entities graph non-null: {}",
(null != tempGraph.getTraceEventsGraph()),
(null != tempGraph.getTraceEntitiesGraph()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,26 @@ void testBuildGraph() {
structuredTraceGraphMockedStatic
.when(() -> StructuredTraceGraph.createGraph(underTestTrace))
.thenReturn(mockedStructuredTraceGraph);

structuredTraceGraphMockedStatic
.when(() -> StructuredTraceGraph.reCreateTraceEntitiesGraph(underTestTrace))
.thenReturn(mockedStructuredTraceGraph);
structuredTraceGraphMockedStatic
.when(() -> StructuredTraceGraph.reCreateTraceEventsGraph(underTestTrace))
.thenReturn(mockedStructuredTraceGraph);
// calls first time
StructuredTraceGraph actual = StructuredTraceGraphBuilder.buildGraph(underTestTrace);
Assertions.assertEquals(mockedStructuredTraceGraph, actual);
structuredTraceGraphMockedStatic.verify(
() -> StructuredTraceGraph.createGraph(underTestTrace), times(1));
// todo change times to 1 when logging is changed to debug level in
// StructuredTraceGraphBuilder#buildGraph
() -> StructuredTraceGraph.createGraph(underTestTrace), times(2));

// calls second time, this time it returns from cache
StructuredTraceGraphBuilder.buildGraph(underTestTrace);
structuredTraceGraphMockedStatic.verify(
() -> StructuredTraceGraph.createGraph(underTestTrace), times(1));
// todo change times to 1 when logging is changed to debug level in
// StructuredTraceGraphBuilder#buildGraph
() -> StructuredTraceGraph.createGraph(underTestTrace), times(3));
}
}
}
Expand Down