From cb7ba1f01d2df1ae57ce54b0f83802f68447c07e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Marcondes?= <55978943+cauemarcondes@users.noreply.github.com> Date: Wed, 16 Sep 2020 14:39:41 +0100 Subject: [PATCH] [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 --- .../get_service_map_from_trace_ids.ts | 3 +- .../lib/service_map/get_trace_sample_ids.ts | 5 +- .../__snapshots__/service_maps.snap | 63 +++++++++++++++++++ .../trial/tests/service_maps/service_maps.ts | 15 +++++ 4 files changed, 82 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/apm/server/lib/service_map/get_service_map_from_trace_ids.ts b/x-pack/plugins/apm/server/lib/service_map/get_service_map_from_trace_ids.ts index f6e331a09fa65..a7771d14532d6 100644 --- a/x-pack/plugins/apm/server/lib/service_map/get_service_map_from_trace_ids.ts +++ b/x-pack/plugins/apm/server/lib/service_map/get_service_map_from_trace_ids.ts @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ import { find, uniqBy } from 'lodash'; +import { ENVIRONMENT_NOT_DEFINED } from '../../../common/environment_filter_values'; import { SERVICE_ENVIRONMENT, SERVICE_NAME, @@ -35,7 +36,7 @@ export function getConnections( SERVICE_NAME in node && (node as ServiceConnectionNode)[SERVICE_NAME] === serviceName; } - if (environment) { + if (environment && environment !== ENVIRONMENT_NOT_DEFINED.value) { matches = matches && SERVICE_ENVIRONMENT in node && diff --git a/x-pack/plugins/apm/server/lib/service_map/get_trace_sample_ids.ts b/x-pack/plugins/apm/server/lib/service_map/get_trace_sample_ids.ts index d6d681f24ab85..dfc4e02c25a7f 100644 --- a/x-pack/plugins/apm/server/lib/service_map/get_trace_sample_ids.ts +++ b/x-pack/plugins/apm/server/lib/service_map/get_trace_sample_ids.ts @@ -14,6 +14,7 @@ import { TRACE_ID, SPAN_DESTINATION_SERVICE_RESOURCE, } from '../../../common/elasticsearch_fieldnames'; +import { getEnvironmentUiFilterES } from '../helpers/convert_ui_filters/get_environment_ui_filter_es'; const MAX_TRACES_TO_INSPECT = 1000; @@ -47,9 +48,7 @@ export async function getTraceSampleIds({ query.bool.filter.push({ term: { [SERVICE_NAME]: serviceName } }); } - if (environment) { - query.bool.filter.push({ term: { [SERVICE_ENVIRONMENT]: environment } }); - } + query.bool.filter.push(...getEnvironmentUiFilterES(environment)); const fingerprintBucketSize = serviceName ? config['xpack.apm.serviceMapFingerprintBucketSize'] diff --git a/x-pack/test/apm_api_integration/trial/tests/service_maps/__snapshots__/service_maps.snap b/x-pack/test/apm_api_integration/trial/tests/service_maps/__snapshots__/service_maps.snap index 859f928c211a4..479117bd493a9 100644 --- a/x-pack/test/apm_api_integration/trial/tests/service_maps/__snapshots__/service_maps.snap +++ b/x-pack/test/apm_api_integration/trial/tests/service_maps/__snapshots__/service_maps.snap @@ -1,5 +1,68 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Service Maps with a trial license /api/apm/service-map when there is data returns service map elements filtering by environment not defined 1`] = ` +Object { + "elements": Array [ + Object { + "data": Object { + "agent.name": "nodejs", + "id": "opbeans-node", + "service.environment": "ENVIRONMENT_NOT_DEFINED", + "service.name": "opbeans-node", + }, + }, + Object { + "data": Object { + "agent.name": "python", + "id": "opbeans-python", + "service.environment": "ENVIRONMENT_NOT_DEFINED", + "service.name": "opbeans-python", + }, + }, + Object { + "data": Object { + "agent.name": "ruby", + "id": "opbeans-ruby", + "service.environment": "ENVIRONMENT_NOT_DEFINED", + "service.name": "opbeans-ruby", + }, + }, + Object { + "data": Object { + "agent.name": "java", + "id": "opbeans-java", + "service.environment": "ENVIRONMENT_NOT_DEFINED", + "service.name": "opbeans-java", + }, + }, + Object { + "data": Object { + "agent.name": "go", + "id": "opbeans-go", + "service.environment": "ENVIRONMENT_NOT_DEFINED", + "service.name": "opbeans-go", + }, + }, + Object { + "data": Object { + "agent.name": "rum-js", + "id": "opbeans-rum", + "service.environment": "ENVIRONMENT_NOT_DEFINED", + "service.name": "opbeans-rum", + }, + }, + Object { + "data": Object { + "agent.name": "dotnet", + "id": "opbeans-dotnet", + "service.environment": "ENVIRONMENT_NOT_DEFINED", + "service.name": "opbeans-dotnet", + }, + }, + ], +} +`; + exports[`Service Maps with a trial license /api/apm/service-map when there is data returns the correct data 3`] = ` Array [ Object { diff --git a/x-pack/test/apm_api_integration/trial/tests/service_maps/service_maps.ts b/x-pack/test/apm_api_integration/trial/tests/service_maps/service_maps.ts index 9dc13f58268df..7f79dd8d9375b 100644 --- a/x-pack/test/apm_api_integration/trial/tests/service_maps/service_maps.ts +++ b/x-pack/test/apm_api_integration/trial/tests/service_maps/service_maps.ts @@ -84,6 +84,21 @@ export default function serviceMapsApiTests({ getService }: FtrProviderContext) expectSnapshot(elements).toMatch(); }); + + it('returns service map elements filtering by environment not defined', async () => { + const ENVIRONMENT_NOT_DEFINED = 'ENVIRONMENT_NOT_DEFINED'; + const { body, status } = await supertest.get( + `/api/apm/service-map?start=${start}&end=${end}&environment=${ENVIRONMENT_NOT_DEFINED}` + ); + expect(status).to.be(200); + const environments = new Set(); + body.elements.forEach((element: { data: Record }) => { + environments.add(element.data['service.environment']); + }); + expect(environments.size).to.eql(1); + expect(environments.has(ENVIRONMENT_NOT_DEFINED)).to.eql(true); + expectSnapshot(body).toMatch(); + }); }); });