diff --git a/x-pack/legacy/plugins/apm/public/components/app/ServiceMap/get_cytoscape_elements.test.ts b/x-pack/legacy/plugins/apm/public/components/app/ServiceMap/get_cytoscape_elements.test.ts new file mode 100644 index 0000000000000..594b00c568f24 --- /dev/null +++ b/x-pack/legacy/plugins/apm/public/components/app/ServiceMap/get_cytoscape_elements.test.ts @@ -0,0 +1,121 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { getCytoscapeElements } from './get_cytoscape_elements'; + +describe('getCytoscapeElements', () => { + describe('with an empty list', () => { + it('returns an empty list', () => { + expect(getCytoscapeElements([], '')).toEqual([]); + }); + }); + + describe('with an external and a service with the same destination.address', () => { + it('only returns the service', () => { + const responses = [ + { + after: undefined, + connections: [ + { + source: { + 'service.environment': null, + 'service.name': 'client', + 'service.framework.name': null, + 'agent.name': 'js-base' + }, + destination: { + 'destination.address': 'opbeans-node', + 'span.subtype': null, + 'span.type': 'resource' + } + }, + { + source: { + 'service.environment': null, + 'service.name': 'client', + 'service.framework.name': null, + 'agent.name': 'js-base' + }, + destination: { + 'service.environment': 'production', + 'service.name': 'opbeans-node', + 'service.framework.name': null, + 'agent.name': 'nodejs' + } + } + ], + discoveredServices: [], + services: [ + { + 'service.name': 'client', + 'agent.name': 'js-base', + 'service.environment': null, + 'service.framework.name': null + } + ] + } + ]; + + const returnValue = [ + { + group: 'nodes', + data: { + id: 'client', + label: 'client', + href: + '#/services/client/service-map?rangeFrom=now-24h&rangeTo=now&refreshPaused=true&refreshInterval=0', + agentName: 'js-base', + frameworkName: null, + type: 'service' + } + }, + { + group: 'nodes', + data: { + id: '>opbeans-node', + label: 'opbeans-node', + type: 'resource', + subtype: null + } + }, + { + group: 'nodes', + data: { + id: 'opbeans-node', + label: 'opbeans-node', + href: + '#/services/opbeans-node/service-map?rangeFrom=now-24h&rangeTo=now&refreshPaused=true&refreshInterval=0', + agentName: 'nodejs', + frameworkName: null, + type: 'service' + } + }, + { + group: 'edges', + classes: undefined, + data: { + id: 'client~>opbeans-node', + source: 'client', + target: '>opbeans-node', + bidirectional: undefined + } + }, + { + group: 'edges', + classes: undefined, + data: { + id: 'client~opbeans-node', + source: 'client', + target: 'opbeans-node', + bidirectional: undefined + } + } + ]; + + expect(getCytoscapeElements(responses, '')).toEqual(returnValue); + }); + }); +}); diff --git a/x-pack/plugins/apm/common/service_map.ts b/x-pack/plugins/apm/common/service_map.ts index f4354baa97655..b79f7e8d505db 100644 --- a/x-pack/plugins/apm/common/service_map.ts +++ b/x-pack/plugins/apm/common/service_map.ts @@ -16,7 +16,7 @@ export interface ServiceConnectionNode { export interface ExternalConnectionNode { 'destination.address': string; 'span.type': string; - 'span.subtype': string; + 'span.subtype': string | null; } export type ConnectionNode = ServiceConnectionNode | ExternalConnectionNode;