Skip to content

Commit

Permalink
[APM] Attempt to fix service maps (elastic#192859)
Browse files Browse the repository at this point in the history
## Summary

<img width="1029" alt="image"
src="https://github.com/user-attachments/assets/155d5dff-dc9e-44c7-a5ad-532867088763">

---------

Co-authored-by: miriam.aparicio <[email protected]>
Co-authored-by: Miriam <[email protected]>
  • Loading branch information
3 people authored Nov 11, 2024
1 parent 43a8a0e commit c19551f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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, id: getConnectionNodeId(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;
}
Expand All @@ -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 = 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,11 @@ export default function serviceMapsApiTests({ getService }: FtrProviderContext)

it('returns the correct data', () => {
const elements: Array<{ data: Record<string, any> }> = response.body.elements;

const serviceNames = uniq(
elements
.filter((element) => element.data['service.name'] !== undefined)
.map((element) => element.data['service.name'])
).sort();

expectSnapshot(serviceNames).toMatchInline(`
Array [
"auditbeat",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export default function ApiTest({ getService }: FtrProviderContext) {
}

registry.when('Service Map', { config: 'trial', archives: [] }, () => {
// FLAKY: https://github.com/elastic/kibana/issues/176982
describe('optional kuery param', () => {
before(async () => {
const events = timerange(start, end)
Expand Down

0 comments on commit c19551f

Please sign in to comment.