-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
MiriamAparicio
merged 10 commits into
elastic:main
from
crespocarlos:192857-service-map-possible-fix
Nov 11, 2024
+26
−9
Merged
[APM] Fix service maps #192859
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
03836d3
Attempt to fix service maps
crespocarlos aa66780
delete not needed code
MiriamAparicio f882bf0
fix api snapshot test
MiriamAparicio dadaa6c
Merge remote-tracking branch 'upstream/main' into 192857-service-map-…
MiriamAparicio 4c82ffe
fix failing test
MiriamAparicio fea3a66
increase timeout for flaky test, pr comments
MiriamAparicio 919843a
fix conflict
MiriamAparicio 6bd3292
deduplicate per service.name instead of id
MiriamAparicio 04353ce
add id to lsit of service nodes
MiriamAparicio c33dc51
Merge branch 'main' into 192857-service-map-possible-fix
MiriamAparicio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) => | ||||||||||||||||||||||||||||
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[] | ||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||
]; | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
// 1. Map external nodes to internal services | ||||||||||||||||||||||||||||
// 2. Collapse external nodes into one node based on span.destination.service.resource | ||||||||||||||||||||||||||||
|
@@ -202,9 +222,10 @@ 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, | ||||||||||||||||||||||||||||
]); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
const dedupedNodes: typeof nodes = []; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
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