Skip to content

Commit cb7ba1f

Browse files
[7.x] showing service maps when filte by environment not defined (#77483) | Fixing service maps API test (#77586) (#77603)
* showing service maps when filte by environment not defined (#77483) * Fixing service maps API test (#77586) * fixing api tests * fixing api tests # Conflicts: # x-pack/test/apm_api_integration/trial/tests/service_maps/service_maps.ts
1 parent 0a715bc commit cb7ba1f

File tree

4 files changed

+82
-4
lines changed

4 files changed

+82
-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/__snapshots__/service_maps.snap

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ 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 ENVIRONMENT_NOT_DEFINED = 'ENVIRONMENT_NOT_DEFINED';
90+
const { body, status } = await supertest.get(
91+
`/api/apm/service-map?start=${start}&end=${end}&environment=${ENVIRONMENT_NOT_DEFINED}`
92+
);
93+
expect(status).to.be(200);
94+
const environments = new Set();
95+
body.elements.forEach((element: { data: Record<string, any> }) => {
96+
environments.add(element.data['service.environment']);
97+
});
98+
expect(environments.size).to.eql(1);
99+
expect(environments.has(ENVIRONMENT_NOT_DEFINED)).to.eql(true);
100+
expectSnapshot(body).toMatch();
101+
});
87102
});
88103
});
89104

0 commit comments

Comments
 (0)