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

[7.x] [APM] Service map - fixes layout issues for maps with no rum services (#62887) #63002

Merged
merged 1 commit into from
Apr 9, 2020
Merged
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 @@ -14,8 +14,6 @@ import React, {
useState
} from 'react';
import { debounce } from 'lodash';
import { isRumAgentName } from '../../../../../../../plugins/apm/common/agent_name';
import { AGENT_NAME } from '../../../../../../../plugins/apm/common/elasticsearch_fieldnames';
import {
animationOptions,
cytoscapeOptions,
Expand Down Expand Up @@ -96,10 +94,15 @@ function getLayoutOptions(
}

function selectRoots(cy: cytoscape.Core): string[] {
const nodes = cy.nodes();
const roots = nodes.roots();
const rumNodes = nodes.filter(node => isRumAgentName(node.data(AGENT_NAME)));
return rumNodes.union(roots).map(node => node.id());
const bfs = cy.elements().bfs({
roots: cy.elements().leaves()
});
const furthestNodeFromLeaves = bfs.path.last();
return cy
.elements()
.roots()
.union(furthestNodeFromLeaves)
.map(el => el.id());
}

export function Cytoscape({
Expand Down Expand Up @@ -168,15 +171,26 @@ export function Cytoscape({
layout.run();
}
};
let layoutstopDelayTimeout: NodeJS.Timeout;
const layoutstopHandler: cytoscape.EventHandler = event => {
event.cy.animate({
...animationOptions,
center: {
eles: serviceName
? event.cy.getElementById(serviceName)
: event.cy.collection()
// This 0ms timer is necessary to prevent a race condition
// between the layout finishing rendering and viewport centering
layoutstopDelayTimeout = setTimeout(() => {
if (serviceName) {
event.cy.animate({
...animationOptions,
fit: {
eles: event.cy.elements(),
padding: nodeHeight
},
center: {
eles: event.cy.getElementById(serviceName)
}
});
} else {
event.cy.fit(undefined, nodeHeight);
}
});
}, 0);
};
// debounce hover tracking so it doesn't spam telemetry with redundant events
const trackNodeEdgeHover = debounce(
Expand Down Expand Up @@ -231,6 +245,7 @@ export function Cytoscape({
cy.removeListener('select', 'node', selectHandler);
cy.removeListener('unselect', 'node', unselectHandler);
}
clearTimeout(layoutstopDelayTimeout);
};
}, [cy, height, serviceName, trackApmEvent, width]);

Expand Down