forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APM] use span.destination.service.resource (elastic#60908)
* [APM] use span.destination.service.resource Closes elastic#60405. * update snapshots Co-authored-by: Nathan L Smith <[email protected]>
- Loading branch information
1 parent
f7a3049
commit d5c13c0
Showing
8 changed files
with
250 additions
and
60 deletions.
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
6 changes: 6 additions & 0 deletions
6
x-pack/plugins/apm/common/__snapshots__/elasticsearch_fieldnames.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
143 changes: 143 additions & 0 deletions
143
x-pack/plugins/apm/server/lib/service_map/dedupe_connections/index.test.ts
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 |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
* 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 { ServiceMapResponse } from './'; | ||
import { | ||
SPAN_DESTINATION_SERVICE_RESOURCE, | ||
SERVICE_NAME, | ||
SERVICE_ENVIRONMENT, | ||
SERVICE_FRAMEWORK_NAME, | ||
AGENT_NAME, | ||
SPAN_TYPE, | ||
SPAN_SUBTYPE | ||
} from '../../../../common/elasticsearch_fieldnames'; | ||
import { dedupeConnections } from './'; | ||
|
||
const nodejsService = { | ||
[SERVICE_NAME]: 'opbeans-node', | ||
[SERVICE_ENVIRONMENT]: 'production', | ||
[SERVICE_FRAMEWORK_NAME]: null, | ||
[AGENT_NAME]: 'nodejs' | ||
}; | ||
|
||
const nodejsExternal = { | ||
[SPAN_DESTINATION_SERVICE_RESOURCE]: 'opbeans-node', | ||
[SPAN_TYPE]: 'external', | ||
[SPAN_SUBTYPE]: 'aa' | ||
}; | ||
|
||
const javaService = { | ||
[SERVICE_NAME]: 'opbeans-java', | ||
[SERVICE_ENVIRONMENT]: 'production', | ||
[SERVICE_FRAMEWORK_NAME]: null, | ||
[AGENT_NAME]: 'java' | ||
}; | ||
|
||
describe('dedupeConnections', () => { | ||
it('maps external destinations to internal services', () => { | ||
const response: ServiceMapResponse = { | ||
services: [nodejsService, javaService], | ||
discoveredServices: [ | ||
{ | ||
from: nodejsExternal, | ||
to: nodejsService | ||
} | ||
], | ||
connections: [ | ||
{ | ||
source: javaService, | ||
destination: nodejsExternal | ||
} | ||
] | ||
}; | ||
|
||
const { elements } = dedupeConnections(response); | ||
|
||
const connection = elements.find( | ||
element => 'source' in element.data && 'target' in element.data | ||
); | ||
|
||
// @ts-ignore | ||
expect(connection?.data.target).toBe('opbeans-node'); | ||
|
||
expect( | ||
elements.find(element => element.data.id === '>opbeans-node') | ||
).toBeUndefined(); | ||
}); | ||
|
||
it('collapses external destinations based on span.destination.resource.name', () => { | ||
const response: ServiceMapResponse = { | ||
services: [nodejsService, javaService], | ||
discoveredServices: [ | ||
{ | ||
from: nodejsExternal, | ||
to: nodejsService | ||
} | ||
], | ||
connections: [ | ||
{ | ||
source: javaService, | ||
destination: nodejsExternal | ||
}, | ||
{ | ||
source: javaService, | ||
destination: { | ||
...nodejsExternal, | ||
[SPAN_TYPE]: 'foo' | ||
} | ||
} | ||
] | ||
}; | ||
|
||
const { elements } = dedupeConnections(response); | ||
|
||
const connections = elements.filter(element => 'source' in element.data); | ||
|
||
expect(connections.length).toBe(1); | ||
|
||
const nodes = elements.filter(element => !('source' in element.data)); | ||
|
||
expect(nodes.length).toBe(2); | ||
}); | ||
|
||
it('picks the first span.type/subtype in an alphabetically sorted list', () => { | ||
const response: ServiceMapResponse = { | ||
services: [javaService], | ||
discoveredServices: [], | ||
connections: [ | ||
{ | ||
source: javaService, | ||
destination: nodejsExternal | ||
}, | ||
{ | ||
source: javaService, | ||
destination: { | ||
...nodejsExternal, | ||
[SPAN_TYPE]: 'foo' | ||
} | ||
}, | ||
{ | ||
source: javaService, | ||
destination: { | ||
...nodejsExternal, | ||
[SPAN_SUBTYPE]: 'bb' | ||
} | ||
} | ||
] | ||
}; | ||
|
||
const { elements } = dedupeConnections(response); | ||
|
||
const nodes = elements.filter(element => !('source' in element.data)); | ||
|
||
const nodejsNode = nodes.find(node => node.data.id === '>opbeans-node'); | ||
|
||
// @ts-ignore | ||
expect(nodejsNode?.data[SPAN_TYPE]).toBe('external'); | ||
// @ts-ignore | ||
expect(nodejsNode?.data[SPAN_SUBTYPE]).toBe('aa'); | ||
}); | ||
}); |
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
Oops, something went wrong.