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

[APM] Fix service maps #192859

Merged
Next Next commit
Attempt to fix service maps
  • Loading branch information
crespocarlos authored and MiriamAparicio committed Nov 5, 2024
commit 03836d3e3ec5f335eda335f093b8135977057868
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ function addMessagingConnections(
const newConnections = messagingDestinations
.map((node) => {
const matchedService = discoveredServices.find(
({ from }) =>
({ from, to }) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you using this to?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it's not used there

node[SPAN_DESTINATION_SERVICE_RESOURCE] === from[SPAN_DESTINATION_SERVICE_RESOURCE]
)?.to;
if (matchedService) {
@@ -86,9 +86,25 @@ export function getAllNodes(
return allNodes;
}

export function getServiceNodes(allNodes: ConnectionNode[]) {
export function getServiceNodes(
allNodes: ConnectionNode[],
discoveredServices: Array<{
from: ExternalConnectionNode;
to: ServiceConnectionNode;
}>
) {
const connectionFromDiscoveredServices = discoveredServices
.filter(({ from, to }) => {
return (
allNodes.some((node) => node.id === getConnectionNodeId(from)) &&
!allNodes.some((node) => node.id === to[SERVICE_NAME])
);
})
.map(({ to }) => ({ ...to }));
// List of nodes that are services
const serviceNodes = allNodes.filter((node) => SERVICE_NAME in node) as ServiceConnectionNode[];
const serviceNodes = [...allNodes, ...connectionFromDiscoveredServices].filter(
(node) => SERVICE_NAME in node
) as ServiceConnectionNode[];

return serviceNodes;
}
@@ -108,12 +124,16 @@ export function transformServiceMapResponses({
const { discoveredServices, services, connections, anomalies } = response;
const allConnections = addMessagingConnections(connections, discoveredServices);
const allNodes = getAllNodes(services, allConnections);
const serviceNodes = getServiceNodes(allNodes);
const serviceNodes = getServiceNodes(allNodes, discoveredServices);

// List of nodes that are externals
const externalNodes = allNodes.filter(
(node) => SPAN_DESTINATION_SERVICE_RESOURCE in node
) as ExternalConnectionNode[];
const externalNodes = [
...new Set(
allNodes.filter(
(node) => SPAN_DESTINATION_SERVICE_RESOURCE in node
) as ExternalConnectionNode[]
),
];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const externalNodes = [
...new Set(
allNodes.filter(
(node) => SPAN_DESTINATION_SERVICE_RESOURCE in node
) as ExternalConnectionNode[]
),
];
const externalNodes = Array.from(new Set(
allNodes.filter(
(node) => SPAN_DESTINATION_SERVICE_RESOURCE in node
) as ExternalConnectionNode[]
)
);


// 1. Map external nodes to internal services
// 2. Collapse external nodes into one node based on span.destination.service.resource
@@ -202,9 +222,11 @@ export function transformServiceMapResponses({
})
.filter((connection) => connection.source !== connection.target);

const nodes = mappedConnections
.flatMap((connection) => [connection.sourceData, connection.targetData])
.concat(serviceNodes);
const nodes = mappedConnections.flatMap((connection) => [
connection.sourceData,
connection.targetData,
]);
// .concat(serviceNodes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I think it can be removed


const dedupedNodes: typeof nodes = [];