Skip to content

Commit 6c0c502

Browse files
kibanamachinermyz
andauthored
[9.0] [APM] Prevent getChildrenGroupedByParentId to include the parent in the children list (#214957) (#215153)
# Backport This will backport the following commits from `main` to `9.0`: - [[APM] Prevent `getChildrenGroupedByParentId` to include the parent in the children list (#214957)](#214957) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Sergi Romeu","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-03-19T12:28:20Z","message":"[APM] Prevent `getChildrenGroupedByParentId` to include the parent in the children list (#214957)\n\n## Summary\n\nCloses #213074\n\nThis PR prevents `getChildrenGroupedByParentId` to include the parent\nitem in the children list, as this was causing some duplication.\n\n| Before | After |\n\n|-------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------|\n<img width=\"1433\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/788684a8-21d7-48a6-820c-07b1fb3d0045\"\n/>|<img width=\"858\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/b68129e1-137d-42fe-a7ce-70373447ece9\"\n/>|\n|<img width=\"1372\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/ff6a5ac8-b46a-4eea-9c4c-638f4b479dc8\"\n/>|<img width=\"844\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/31ef881c-a6d0-41ea-80d4-aebd587e76cd\"\n/>|","sha":"0ee664a555d860b045291b5757bafce33decedb3","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","Team:obs-ux-infra_services","backport:version","v9.1.0","v8.19.0","v9.0.1"],"title":"[APM] Prevent `getChildrenGroupedByParentId` to include the parent in the children list","number":214957,"url":"https://github.com/elastic/kibana/pull/214957","mergeCommit":{"message":"[APM] Prevent `getChildrenGroupedByParentId` to include the parent in the children list (#214957)\n\n## Summary\n\nCloses #213074\n\nThis PR prevents `getChildrenGroupedByParentId` to include the parent\nitem in the children list, as this was causing some duplication.\n\n| Before | After |\n\n|-------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------|\n<img width=\"1433\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/788684a8-21d7-48a6-820c-07b1fb3d0045\"\n/>|<img width=\"858\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/b68129e1-137d-42fe-a7ce-70373447ece9\"\n/>|\n|<img width=\"1372\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/ff6a5ac8-b46a-4eea-9c4c-638f4b479dc8\"\n/>|<img width=\"844\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/31ef881c-a6d0-41ea-80d4-aebd587e76cd\"\n/>|","sha":"0ee664a555d860b045291b5757bafce33decedb3"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/214957","number":214957,"mergeCommit":{"message":"[APM] Prevent `getChildrenGroupedByParentId` to include the parent in the children list (#214957)\n\n## Summary\n\nCloses #213074\n\nThis PR prevents `getChildrenGroupedByParentId` to include the parent\nitem in the children list, as this was causing some duplication.\n\n| Before | After |\n\n|-------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------|\n<img width=\"1433\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/788684a8-21d7-48a6-820c-07b1fb3d0045\"\n/>|<img width=\"858\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/b68129e1-137d-42fe-a7ce-70373447ece9\"\n/>|\n|<img width=\"1372\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/ff6a5ac8-b46a-4eea-9c4c-638f4b479dc8\"\n/>|<img width=\"844\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/31ef881c-a6d0-41ea-80d4-aebd587e76cd\"\n/>|","sha":"0ee664a555d860b045291b5757bafce33decedb3"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Sergi Romeu <[email protected]>
1 parent d6aebc9 commit 6c0c502

File tree

1 file changed

+26
-3
lines changed
  • x-pack/solutions/observability/plugins/apm/public/components/app/transaction_details/waterfall_with_summary/waterfall_container/waterfall/waterfall_helpers

1 file changed

+26
-3
lines changed

x-pack/solutions/observability/plugins/apm/public/components/app/transaction_details/waterfall_with_summary/waterfall_container/waterfall/waterfall_helpers/waterfall_helpers.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,23 @@ function reparentSpans(waterfallItems: IWaterfallSpanOrTransaction[]) {
339339
});
340340
}
341341

342-
const getChildrenGroupedByParentId = (waterfallItems: IWaterfallSpanOrTransaction[]) =>
343-
groupBy(waterfallItems, (item) => item.parentId ?? ROOT_ID);
342+
const getChildrenGroupedByParentId = (waterfallItems: IWaterfallSpanOrTransaction[]) => {
343+
const childrenGroups = groupBy(waterfallItems, (item) => item.parentId ?? ROOT_ID);
344+
345+
const childrenGroupedByParentId = Object.entries(childrenGroups).reduce(
346+
(acc, [parentId, items]) => {
347+
// we shouldn't include the parent item in the children list
348+
const filteredItems = items.filter((item) => item.id !== parentId);
349+
return {
350+
...acc,
351+
[parentId]: filteredItems,
352+
};
353+
},
354+
{}
355+
);
356+
357+
return childrenGroupedByParentId;
358+
};
344359

345360
const getEntryWaterfallTransaction = (
346361
entryTransactionId: string,
@@ -517,15 +532,18 @@ function getChildren({
517532
path,
518533
waterfall,
519534
waterfallItemId,
535+
rootId,
520536
}: {
521537
waterfallItemId: string;
522538
waterfall: IWaterfall;
523539
path: {
524540
criticalPathSegmentsById: Dictionary<CriticalPathSegment[]>;
525541
showCriticalPath: boolean;
526542
};
543+
rootId: string;
527544
}) {
528545
const children = waterfall.childrenByParentId[waterfallItemId] ?? [];
546+
529547
return path.showCriticalPath
530548
? children.filter((child) => path.criticalPathSegmentsById[child.id]?.length)
531549
: children;
@@ -551,7 +569,12 @@ function buildTree({
551569
for (let queueIndex = 0; queueIndex < queue.length; queueIndex++) {
552570
const node = queue[queueIndex];
553571

554-
const children = getChildren({ path, waterfall, waterfallItemId: node.item.id });
572+
const children = getChildren({
573+
path,
574+
waterfall,
575+
waterfallItemId: node.item.id,
576+
rootId: root.item.id,
577+
});
555578

556579
// Set childrenToLoad for all nodes enqueued.
557580
// this allows lazy loading of child nodes

0 commit comments

Comments
 (0)