Skip to content

Commit

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

# Backport

This will backport the following commits from `main` to `8.x`:
- [[APM] Attempt to fix service maps
(elastic#192859)](elastic#192859)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Carlos
Crespo","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-11T10:52:39Z","message":"[APM]
Attempt to fix service maps (elastic#192859)\n\n## Summary\r\n\r\n<img
width=\"1029\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/155d5dff-dc9e-44c7-a5ad-532867088763\">\r\n\r\n---------\r\n\r\nCo-authored-by:
miriam.aparicio <[email protected]>\r\nCo-authored-by: Miriam
<[email protected]>","sha":"c19551f89a039c26ece79b505b4d9ff7ad729f47","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-infra_services","v8.17.0"],"title":"[APM]
Attempt to fix service
maps","number":192859,"url":"https://github.com/elastic/kibana/pull/192859","mergeCommit":{"message":"[APM]
Attempt to fix service maps (elastic#192859)\n\n## Summary\r\n\r\n<img
width=\"1029\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/155d5dff-dc9e-44c7-a5ad-532867088763\">\r\n\r\n---------\r\n\r\nCo-authored-by:
miriam.aparicio <[email protected]>\r\nCo-authored-by: Miriam
<[email protected]>","sha":"c19551f89a039c26ece79b505b4d9ff7ad729f47"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/192859","number":192859,"mergeCommit":{"message":"[APM]
Attempt to fix service maps (elastic#192859)\n\n## Summary\r\n\r\n<img
width=\"1029\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/155d5dff-dc9e-44c7-a5ad-532867088763\">\r\n\r\n---------\r\n\r\nCo-authored-by:
miriam.aparicio <[email protected]>\r\nCo-authored-by: Miriam
<[email protected]>","sha":"c19551f89a039c26ece79b505b4d9ff7ad729f47"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Carlos Crespo <[email protected]>
  • Loading branch information
kibanamachine and crespocarlos authored Nov 11, 2024
1 parent 1fed60e commit 54c8329
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 54c8329

Please sign in to comment.