fix: optimize the usage of ApiTraceGraph in the ingestion pipeline#195
fix: optimize the usage of ApiTraceGraph in the ingestion pipeline#195kotharironak merged 6 commits intomainfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## main #195 +/- ##
=========================================
Coverage 78.92% 78.92%
Complexity 1128 1128
=========================================
Files 101 101
Lines 4370 4370
Branches 406 406
=========================================
Hits 3449 3449
Misses 732 732
Partials 189 189
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@d-trace does this affect what you are working on? |
No @tim-mwangi. My logic at the moment does calculations based on StructuredTrace directly. |
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class GraphBuilderUtil { |
There was a problem hiding this comment.
Is it possible to add unit tests for this util?
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class ApiTraceGraphBuilder { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
||
| // calls second time, this time it returns from cache | ||
| StructuredTraceGraphBuilder.buildGraph(underTestTrace); | ||
| structuredTraceGraphMockedStatic.verify( |
There was a problem hiding this comment.
this assertion should be placed before the second call?
There was a problem hiding this comment.
It makes sure that after the second call, it was not incremented. Let me put at both the places. Done.
There was a problem hiding this comment.
Yeah, it should be at both places
| // first call | ||
| ApiTraceGraph actual = ApiTraceGraphBuilder.buildGraph(underTestTrace); | ||
| Assertions.assertNotNull(actual); | ||
| Assertions.assertEquals(1, mockedConstruction.constructed().size()); |
There was a problem hiding this comment.
what is this mockedConstruction.constructed().size() size representing?
There was a problem hiding this comment.
The number of times new ApiTraceGraph(trace) is called.
| /** | ||
| * optimistic method of comparing two trace for considering rebuilding of entire graph structure. | ||
| */ | ||
| static boolean isSameStructuredTrace(StructuredTrace cachedTrace, StructuredTrace trace) { |
There was a problem hiding this comment.
the method name could be misleading, we are trying to check if the components in the Trace are same as previous or not. Trace might have changed due to event enrichment or trace enrichment.
| when(underTestTrace.getEventEdgeList()).thenReturn(List.of(eventEdge)); | ||
|
|
||
| boolean result = GraphBuilderUtil.isSameStructuredTrace(cachedTrace, underTestTrace); | ||
| Assertions.assertTrue(result); |
There was a problem hiding this comment.
Test the negative case as well?
There was a problem hiding this comment.
The remains are covered with the other two tests, and this I have created as an end to cover up all. But, if you want, I can add one to the list item.
There was a problem hiding this comment.
I think it can be taken up subsequently
| // calls second time, this time it returns from cache | ||
| StructuredTraceGraphBuilder.buildGraph(underTestTrace); | ||
| structuredTraceGraphMockedStatic.verify( | ||
| () -> StructuredTraceGraph.createGraph(underTestTrace), times(1)); |
There was a problem hiding this comment.
I think, its also important to test that the cached structure is not returned when a different trace is passed?
There was a problem hiding this comment.
Isn't the fist call doing the same StructuredTraceGraphBuilder.buildGraph as it has to test GraphBuilderUtil.isSameStructuredTrace and the first call cover that part and the method is independently covered in GraphBuilderUtilTest.
There was a problem hiding this comment.
yeah the correctness is tested, this was more of a suggestion for completeness sake.
First test with empty cache, second call return from cache, third call with different trace again build structure.
| // second call | ||
| ApiTraceGraph second = ApiTraceGraphBuilder.buildGraph(underTestTrace); | ||
| Assertions.assertEquals(actual, second); | ||
| Assertions.assertEquals(1, mockedConstruction.constructed().size()); |
There was a problem hiding this comment.
I think, its also important to test that the cached graph is not returned when a different trace is passed?
There was a problem hiding this comment.
The first call is testing that we are going to if block where the cache is prepared. And GraphBuilderUtil.isSameStructuredTrace is independently tested in GraphBuilderUtilTest.




Description
As part of looking into handling large traces, we have observed a couple of optimization in our ingestion pipeline as described here - hypertrace/hypertrace#244
This PR addresses
Testing