Skip to content

Commit

Permalink
Added a new test case that is child span ends before parent span
Browse files Browse the repository at this point in the history
Signed-off-by: GLVS Kiriti <glvskiriti2003369@gmail.com>
  • Loading branch information
GLVSKiriti committed Sep 14, 2023
1 parent c127eea commit 9da89cc
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import test6 from './testCases/test6';
import test7 from './testCases/test7';
import test5 from './testCases/test5';
import test8 from './testCases/test8';
import test9 from './testCases/test9';

describe.each([[test1], [test2], [test3], [test4], [test5], [test6], [test7], [test8]])(
describe.each([[test1], [test2], [test3], [test4], [test5], [test6], [test7], [test8], [test9]])(
'Happy Path',
testProps => {
it('should find criticalPathSections correctly', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) 2023 The Jaeger Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import transformTraceData from '../../../../model/transform-trace-data';

/*
┌──────────┐ |
│ Span A │ | span A
└──────────┘ | /
++++++++++++ | /
┌────────────┐ | span B
│ Span B │ |
└────────────┘ | (parent-child tree)
spanB will be dropped. |
span A is on critical path(+++++) |
*/

const trace = {
traceID: 'trace-abc',
spans: [
{
spanID: 'span-A',
operationName: 'op-A',
references: [],
startTime: 10,
duration: 20,
processID: 'p1',
},
{
spanID: 'span-B',
operationName: 'op-B',
references: [
{
refType: 'CHILD_OF',
spanID: 'span-A',
},
],
startTime: 1,
duration: 4,
processID: 'p1',
},
],
processes: {
p1: {
serviceName: 'service-one',
},
},
};

const transformedTrace = transformTraceData(trace);

const criticalPathSections = [
{
spanId: 'span-A',
section_start: 10,
section_end: 30,
},
];

const test9 = {
criticalPathSections,
trace: transformedTrace,
};

export default test9;
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import test4 from '../testCases/test4';
import test6 from '../testCases/test6';
import test7 from '../testCases/test7';
import test8 from '../testCases/test8';
import test9 from '../testCases/test9';
import getChildOfSpans from './getChildOfSpans';
import sanitizeOverFlowingChildren from './sanitizeOverFlowingChildren';

Expand All @@ -40,6 +41,7 @@ describe.each([
[test6, getExpectedSanitizedData(test6.trace.spans, 'test6')],
[test7, getExpectedSanitizedData(test7.trace.spans, 'test7')],
[test8, getExpectedSanitizedData(test8.trace.spans, 'test8')],
[test9, new Map().set(test9.trace.spans[0].spanID, { ...test9.trace.spans[0], childSpanIds: [] })],
])('sanitizeOverFlowingChildren', (testProps, expectedSanitizedData) => {
it('Should sanitize the data(overflowing spans) correctly', () => {
const refinedSpanData = getChildOfSpans(testProps.trace.spans);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const sanitizeOverFlowingChildren = (spanMap: Map<string, Span>): Map<string, Sp

// Remove the childSpanId from its parent span
parentSpan.childSpanIds = parentSpan.childSpanIds.filter(id => id !== span.spanID);
spanMap.set(parentSpan.spanID, { ...parentSpan });
return;
}
if (childEndTime > parentEndTime) {
Expand Down Expand Up @@ -78,7 +77,6 @@ const sanitizeOverFlowingChildren = (spanMap: Map<string, Span>): Map<string, Sp

// Remove the childSpanId from its parent span
parentSpan.childSpanIds = parentSpan.childSpanIds.filter(id => id !== span.spanID);
spanMap.set(parentSpan.spanID, { ...parentSpan });
} else if (childEndTime <= parentEndTime) {
// child start before parent, truncate is needed
// |----parent----|
Expand Down

0 comments on commit 9da89cc

Please sign in to comment.