From db3ab3027b4a044c489b8c4dcf2f230704b95b2a Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Tue, 29 Sep 2020 13:53:44 +0200 Subject: [PATCH] add filter by environment --- .../server/lib/service_map/get_service_map.ts | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/apm/server/lib/service_map/get_service_map.ts b/x-pack/plugins/apm/server/lib/service_map/get_service_map.ts index 402beb1999240..75acebe7ed56c 100644 --- a/x-pack/plugins/apm/server/lib/service_map/get_service_map.ts +++ b/x-pack/plugins/apm/server/lib/service_map/get_service_map.ts @@ -14,6 +14,7 @@ import { getServicesProjection } from '../../projections/services'; import { mergeProjection } from '../../projections/util/merge_projection'; import { PromiseReturnType } from '../../../typings/common'; import { Setup, SetupTimeRange } from '../helpers/setup_request'; +import { getEnvironmentUiFilterES } from '../helpers/convert_ui_filters/get_environment_ui_filter_es'; import { transformServiceMapResponses } from './transform_service_map_responses'; import { getServiceMapFromTraceIds } from './get_service_map_from_trace_ids'; import { getTraceSampleIds } from './get_trace_sample_ids'; @@ -85,7 +86,19 @@ async function getServicesData(options: IEnvOptions) { searchAggregatedTransactions, }); - const { filter } = projection.body.query.bool; + let { filter } = projection.body.query.bool; + + if (options.serviceName) { + filter = filter.concat({ + term: { + [SERVICE_NAME]: options.serviceName, + }, + }); + } + + if (options.environment) { + filter = filter.concat(getEnvironmentUiFilterES(options.environment)); + } const params = mergeProjection(projection, { body: { @@ -93,13 +106,7 @@ async function getServicesData(options: IEnvOptions) { query: { bool: { ...projection.body.query.bool, - filter: options.serviceName - ? filter.concat({ - term: { - [SERVICE_NAME]: options.serviceName, - }, - }) - : filter, + filter, }, }, aggs: {