Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handled the case in which child span starts before and ends after parent span. #1780

Merged
merged 7 commits into from
Sep 12, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,26 @@ import sanitizeOverFlowingChildren from './utils/sanitizeOverFlowingChildren';
import test6 from './testCases/test6';
GLVSKiriti marked this conversation as resolved.
Show resolved Hide resolved
import test7 from './testCases/test7';
import test5 from './testCases/test5';
import test8 from './testCases/test8';

describe.each([[test1], [test2], [test3], [test4], [test5], [test6], [test7]])('Happy Path', testProps => {
it('Should find criticalPathSections correctly', () => {
const rootSpanId = testProps.trace.spans[0].spanID;
const spanMap = testProps.trace.spans.reduce((map, span) => {
map.set(span.spanID, span);
return map;
}, new Map());
const refinedSpanMap = getChildOfSpans(spanMap);
const sanitizedSpanMap = sanitizeOverFlowingChildren(refinedSpanMap);
const criticalPath = computeCriticalPath(sanitizedSpanMap, rootSpanId, []);
expect(criticalPath).toStrictEqual(testProps.criticalPathSections);
});
describe.each([[test1], [test2], [test3], [test4], [test5], [test6], [test7], [test8]])(
'Happy Path',
testProps => {
it('Should find criticalPathSections correctly', () => {
GLVSKiriti marked this conversation as resolved.
Show resolved Hide resolved
const rootSpanId = testProps.trace.spans[0].spanID;
const spanMap = testProps.trace.spans.reduce((map, span) => {
map.set(span.spanID, span);
return map;
}, new Map());
const refinedSpanMap = getChildOfSpans(spanMap);
const sanitizedSpanMap = sanitizeOverFlowingChildren(refinedSpanMap);
const criticalPath = computeCriticalPath(sanitizedSpanMap, rootSpanId, []);
expect(criticalPath).toStrictEqual(testProps.criticalPathSections);
});

it('Critical path sections', () => {
const criticalPath = TraceCriticalPath(testProps.trace);
expect(criticalPath).toStrictEqual(testProps.criticalPathSections);
});
});
it('Critical path sections', () => {
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
const criticalPath = TraceCriticalPath(testProps.trace);
expect(criticalPath).toStrictEqual(testProps.criticalPathSections);
});
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// 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 │ | spanA
└─────────────────┘ | /
| /
┌──────────────────────┐ | spanB (CHILD_OF)
│ Span B │ |
└──────────────────────┘ | ((parent-child tree))
*/

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: 5,
duration: 30,
processID: 'p1',
},
],
processes: {
p1: {
serviceName: 'service-one',
},
},
};

const transformedTrace = transformTraceData(trace);

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

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

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

Expand All @@ -24,6 +25,7 @@ function getExpectedSanitizedData(spans, test) {
const testSanitizedData = {
test6: [spans[0], { ...spans[1], duration: 15 }, { ...spans[2], duration: 10, startTime: 15 }],
test7: [spans[0], { ...spans[1], duration: 15 }, { ...spans[2], duration: 10 }],
test8: [spans[0], { ...spans[1], startTime: 10, duration: 20 }],
};
const spanMap = testSanitizedData[test].reduce((map, span) => {
map.set(span.spanID, span);
Expand All @@ -37,6 +39,7 @@ describe.each([
[test4, new Map().set(test4.trace.spans[0].spanID, test4.trace.spans[0])],
[test6, getExpectedSanitizedData(test6.trace.spans, 'test6')],
[test7, getExpectedSanitizedData(test7.trace.spans, 'test7')],
[test8, getExpectedSanitizedData(test8.trace.spans, 'test8')],
])('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 @@ -65,8 +65,19 @@ const sanitizeOverFlowingChildren = (spanMap: Map<string, Span>): Map<string, Sp
});
break;

case span.startTime < parentSpan.startTime && childEndTime > parentEndTime:
// case 4: child start before parent and end after parent, truncate is needed
// |----parent----|
// |---------child---------|
spanMap.set(span.spanID, {
...span,
startTime: parentSpan.startTime,
duration: parentEndTime - parentSpan.startTime,
});
break;

case span.startTime >= parentEndTime || childEndTime <= parentSpan.startTime:
// case 4: child outside of parent range => drop the child span
// case 5: child outside of parent range => drop the child span
// |----parent----|
// |----child--|
// or
Expand Down