Skip to content

Commit 54bb62a

Browse files
committed
addressing PR comment
1 parent db3ab30 commit 54bb62a

File tree

2 files changed

+73
-27
lines changed

2 files changed

+73
-27
lines changed

x-pack/plugins/apm/server/lib/service_map/get_service_map_from_trace_ids.test.ts

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,23 @@ function getConnectionsPairs(connections: Connection[]) {
1717
: conn.destination['span.type'];
1818
return `${source} -> ${destination}`;
1919
})
20-
.filter((_) => _)
21-
.sort();
20+
.filter((_) => _);
2221
}
2322

2423
describe('getConnections', () => {
2524
describe('with environments defined', () => {
2625
const paths = [
2726
[
27+
{
28+
'service.environment': 'testing',
29+
'service.name': 'opbeans-ruby',
30+
'agent.name': 'ruby',
31+
},
32+
{
33+
'service.environment': null,
34+
'service.name': 'opbeans-node',
35+
'agent.name': 'nodejs',
36+
},
2837
{
2938
'service.environment': 'production',
3039
'service.name': 'opbeans-go',
@@ -44,13 +53,13 @@ describe('getConnections', () => {
4453
[
4554
{
4655
'service.environment': 'testing',
47-
'service.name': 'opbeans-python',
48-
'agent.name': 'python',
56+
'service.name': 'opbeans-ruby',
57+
'agent.name': 'ruby',
4958
},
5059
{
5160
'service.environment': 'testing',
52-
'service.name': 'opbeans-node',
53-
'agent.name': 'nodejs',
61+
'service.name': 'opbeans-python',
62+
'agent.name': 'python',
5463
},
5564
{
5665
'span.subtype': 'http',
@@ -66,12 +75,15 @@ describe('getConnections', () => {
6675
serviceName: undefined,
6776
environment: undefined,
6877
});
78+
6979
const connectionsPairs = getConnectionsPairs(connections);
7080
expect(connectionsPairs).toEqual([
81+
'opbeans-ruby:testing -> opbeans-node:null',
82+
'opbeans-node:null -> opbeans-go:production',
7183
'opbeans-go:production -> opbeans-java:production',
7284
'opbeans-java:production -> external',
73-
'opbeans-node:testing -> external',
74-
'opbeans-python:testing -> opbeans-node:testing',
85+
'opbeans-ruby:testing -> opbeans-python:testing',
86+
'opbeans-python:testing -> external',
7587
]);
7688
});
7789
});
@@ -87,6 +99,8 @@ describe('getConnections', () => {
8799
const connectionsPairs = getConnectionsPairs(connections);
88100

89101
expect(connectionsPairs).toEqual([
102+
'opbeans-ruby:testing -> opbeans-node:null',
103+
'opbeans-node:null -> opbeans-go:production',
90104
'opbeans-go:production -> opbeans-java:production',
91105
'opbeans-java:production -> external',
92106
]);
@@ -102,8 +116,8 @@ describe('getConnections', () => {
102116
const connectionsPairs = getConnectionsPairs(connections);
103117

104118
expect(connectionsPairs).toEqual([
105-
'opbeans-node:testing -> external',
106-
'opbeans-python:testing -> opbeans-node:testing',
119+
'opbeans-ruby:testing -> opbeans-python:testing',
120+
'opbeans-python:testing -> external',
107121
]);
108122
});
109123
});
@@ -119,8 +133,10 @@ describe('getConnections', () => {
119133
const connectionsPairs = getConnectionsPairs(connections);
120134

121135
expect(connectionsPairs).toEqual([
122-
'opbeans-node:testing -> external',
123-
'opbeans-python:testing -> opbeans-node:testing',
136+
'opbeans-ruby:testing -> opbeans-node:null',
137+
'opbeans-node:null -> opbeans-go:production',
138+
'opbeans-go:production -> opbeans-java:production',
139+
'opbeans-java:production -> external',
124140
]);
125141
});
126142
});
@@ -136,8 +152,12 @@ describe('getConnections', () => {
136152
const connectionsPairs = getConnectionsPairs(connections);
137153

138154
expect(connectionsPairs).toEqual([
139-
'opbeans-node:testing -> external',
140-
'opbeans-python:testing -> opbeans-node:testing',
155+
'opbeans-ruby:testing -> opbeans-node:null',
156+
'opbeans-node:null -> opbeans-go:production',
157+
'opbeans-go:production -> opbeans-java:production',
158+
'opbeans-java:production -> external',
159+
'opbeans-ruby:testing -> opbeans-python:testing',
160+
'opbeans-python:testing -> external',
141161
]);
142162
});
143163
it('shows all connections for production environment', () => {
@@ -150,6 +170,8 @@ describe('getConnections', () => {
150170
const connectionsPairs = getConnectionsPairs(connections);
151171

152172
expect(connectionsPairs).toEqual([
173+
'opbeans-ruby:testing -> opbeans-node:null',
174+
'opbeans-node:null -> opbeans-go:production',
153175
'opbeans-go:production -> opbeans-java:production',
154176
'opbeans-java:production -> external',
155177
]);
@@ -160,6 +182,23 @@ describe('getConnections', () => {
160182
describe('environment is "not defined"', () => {
161183
it('shows all connections where environment is not set', () => {
162184
const environmentNotDefinedPaths = [
185+
[
186+
{
187+
'service.environment': 'production',
188+
'service.name': 'opbeans-go',
189+
'agent.name': 'go',
190+
},
191+
{
192+
'service.environment': 'production',
193+
'service.name': 'opbeans-java',
194+
'agent.name': 'java',
195+
},
196+
{
197+
'span.subtype': 'http',
198+
'span.destination.service.resource': '172.18.0.6:3000',
199+
'span.type': 'external',
200+
},
201+
],
163202
[
164203
{
165204
'service.environment': null,
@@ -205,8 +244,8 @@ describe('getConnections', () => {
205244
expect(connectionsPairs).toEqual([
206245
'opbeans-go:null -> opbeans-java:null',
207246
'opbeans-java:null -> external',
208-
'opbeans-node:null -> external',
209247
'opbeans-python:null -> opbeans-node:null',
248+
'opbeans-node:null -> external',
210249
]);
211250
});
212251
});

x-pack/plugins/apm/server/lib/service_map/get_service_map_from_trace_ids.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,28 @@ export function getConnections({
2828

2929
if (serviceName || environment) {
3030
paths = paths.filter((path) => {
31-
return path.some((node) => {
32-
if (serviceName && node[SERVICE_NAME] !== serviceName) {
33-
return false;
34-
}
31+
return (
32+
path
33+
// Only apply the filter on node that contains service name, this filters out external nodes
34+
.filter((node) => {
35+
return node[SERVICE_NAME];
36+
})
37+
.some((node) => {
38+
if (serviceName && node[SERVICE_NAME] !== serviceName) {
39+
return false;
40+
}
3541

36-
if (!environment) {
37-
return true;
38-
}
42+
if (!environment) {
43+
return true;
44+
}
3945

40-
if (environment === ENVIRONMENT_NOT_DEFINED.value) {
41-
return !node[SERVICE_ENVIRONMENT];
42-
}
46+
if (environment === ENVIRONMENT_NOT_DEFINED.value) {
47+
return !node[SERVICE_ENVIRONMENT];
48+
}
4349

44-
return node[SERVICE_ENVIRONMENT] === environment;
45-
});
50+
return node[SERVICE_ENVIRONMENT] === environment;
51+
})
52+
);
4653
});
4754
}
4855

0 commit comments

Comments
 (0)