Skip to content

Commit 32fb9c6

Browse files
committed
showing service maps when filte by environment not defined (#77483)
1 parent ee8bc62 commit 32fb9c6

File tree

3 files changed

+160
-4
lines changed

3 files changed

+160
-4
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66
import { find, uniqBy } from 'lodash';
7+
import { ENVIRONMENT_NOT_DEFINED } from '../../../common/environment_filter_values';
78
import {
89
SERVICE_ENVIRONMENT,
910
SERVICE_NAME,
@@ -35,7 +36,7 @@ export function getConnections(
3536
SERVICE_NAME in node &&
3637
(node as ServiceConnectionNode)[SERVICE_NAME] === serviceName;
3738
}
38-
if (environment) {
39+
if (environment && environment !== ENVIRONMENT_NOT_DEFINED.value) {
3940
matches =
4041
matches &&
4142
SERVICE_ENVIRONMENT in node &&

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
TRACE_ID,
1515
SPAN_DESTINATION_SERVICE_RESOURCE,
1616
} from '../../../common/elasticsearch_fieldnames';
17+
import { getEnvironmentUiFilterES } from '../helpers/convert_ui_filters/get_environment_ui_filter_es';
1718

1819
const MAX_TRACES_TO_INSPECT = 1000;
1920

@@ -47,9 +48,7 @@ export async function getTraceSampleIds({
4748
query.bool.filter.push({ term: { [SERVICE_NAME]: serviceName } });
4849
}
4950

50-
if (environment) {
51-
query.bool.filter.push({ term: { [SERVICE_ENVIRONMENT]: environment } });
52-
}
51+
query.bool.filter.push(...getEnvironmentUiFilterES(environment));
5352

5453
const fingerprintBucketSize = serviceName
5554
? config['xpack.apm.serviceMapFingerprintBucketSize']

x-pack/test/apm_api_integration/trial/tests/service_maps/service_maps.ts

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,162 @@ export default function serviceMapsApiTests({ getService }: FtrProviderContext)
8484

8585
expectSnapshot(elements).toMatch();
8686
});
87+
88+
it('returns service map elements filtering by environment not defined', async () => {
89+
const start = encodeURIComponent('2020-06-28T10:24:46.055Z');
90+
const end = encodeURIComponent('2020-06-29T10:24:46.055Z');
91+
const environment = 'ENVIRONMENT_NOT_DEFINED';
92+
const response = await supertest.get(
93+
`/api/apm/service-map?start=${start}&end=${end}&environment=${environment}`
94+
);
95+
expect(response.status).to.be(200);
96+
expectSnapshot(response.body).toMatchInline(`
97+
Object {
98+
"elements": Array [
99+
Object {
100+
"data": Object {
101+
"id": "client~opbeans-node",
102+
"source": "client",
103+
"sourceData": Object {
104+
"agent.name": "rum-js",
105+
"id": "client",
106+
"service.environment": "ENVIRONMENT_NOT_DEFINED",
107+
"service.name": "client",
108+
},
109+
"target": "opbeans-node",
110+
"targetData": Object {
111+
"agent.name": "nodejs",
112+
"id": "opbeans-node",
113+
"service.environment": "ENVIRONMENT_NOT_DEFINED",
114+
"service.name": "opbeans-node",
115+
},
116+
},
117+
},
118+
Object {
119+
"data": Object {
120+
"id": "opbeans-java~>postgresql",
121+
"source": "opbeans-java",
122+
"sourceData": Object {
123+
"agent.name": "java",
124+
"id": "opbeans-java",
125+
"service.environment": "ENVIRONMENT_NOT_DEFINED",
126+
"service.name": "opbeans-java",
127+
},
128+
"target": ">postgresql",
129+
"targetData": Object {
130+
"id": ">postgresql",
131+
"label": "postgresql",
132+
"span.destination.service.resource": "postgresql",
133+
"span.subtype": "postgresql",
134+
"span.type": "db",
135+
},
136+
},
137+
},
138+
Object {
139+
"data": Object {
140+
"id": "opbeans-node~>postgresql",
141+
"source": "opbeans-node",
142+
"sourceData": Object {
143+
"agent.name": "nodejs",
144+
"id": "opbeans-node",
145+
"service.environment": "ENVIRONMENT_NOT_DEFINED",
146+
"service.name": "opbeans-node",
147+
},
148+
"target": ">postgresql",
149+
"targetData": Object {
150+
"id": ">postgresql",
151+
"label": "postgresql",
152+
"span.destination.service.resource": "postgresql",
153+
"span.subtype": "postgresql",
154+
"span.type": "db",
155+
},
156+
},
157+
},
158+
Object {
159+
"data": Object {
160+
"id": "opbeans-node~>redis",
161+
"source": "opbeans-node",
162+
"sourceData": Object {
163+
"agent.name": "nodejs",
164+
"id": "opbeans-node",
165+
"service.environment": "ENVIRONMENT_NOT_DEFINED",
166+
"service.name": "opbeans-node",
167+
},
168+
"target": ">redis",
169+
"targetData": Object {
170+
"id": ">redis",
171+
"label": "redis",
172+
"span.destination.service.resource": "redis",
173+
"span.subtype": "redis",
174+
"span.type": "cache",
175+
},
176+
},
177+
},
178+
Object {
179+
"data": Object {
180+
"id": "opbeans-node~opbeans-java",
181+
"source": "opbeans-node",
182+
"sourceData": Object {
183+
"agent.name": "nodejs",
184+
"id": "opbeans-node",
185+
"service.environment": "ENVIRONMENT_NOT_DEFINED",
186+
"service.name": "opbeans-node",
187+
},
188+
"target": "opbeans-java",
189+
"targetData": Object {
190+
"agent.name": "java",
191+
"id": "opbeans-java",
192+
"service.environment": "ENVIRONMENT_NOT_DEFINED",
193+
"service.name": "opbeans-java",
194+
},
195+
},
196+
},
197+
Object {
198+
"data": Object {
199+
"agent.name": "rum-js",
200+
"id": "client",
201+
"service.environment": "ENVIRONMENT_NOT_DEFINED",
202+
"service.name": "client",
203+
},
204+
},
205+
Object {
206+
"data": Object {
207+
"agent.name": "nodejs",
208+
"id": "opbeans-node",
209+
"service.environment": "ENVIRONMENT_NOT_DEFINED",
210+
"service.name": "opbeans-node",
211+
},
212+
},
213+
Object {
214+
"data": Object {
215+
"id": ">redis",
216+
"label": "redis",
217+
"span.destination.service.resource": "redis",
218+
"span.subtype": "redis",
219+
"span.type": "cache",
220+
},
221+
},
222+
Object {
223+
"data": Object {
224+
"agent.name": "java",
225+
"id": "opbeans-java",
226+
"service.environment": "ENVIRONMENT_NOT_DEFINED",
227+
"service.name": "opbeans-java",
228+
},
229+
},
230+
Object {
231+
"data": Object {
232+
"id": ">postgresql",
233+
"label": "postgresql",
234+
"span.destination.service.resource": "postgresql",
235+
"span.subtype": "postgresql",
236+
"span.type": "db",
237+
},
238+
},
239+
],
240+
}
241+
`);
242+
});
87243
});
88244
});
89245

0 commit comments

Comments
 (0)