Skip to content

Commit

Permalink
add filter by environment
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Sep 29, 2020
1 parent 76e0c76 commit db3ab30
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions x-pack/plugins/apm/server/lib/service_map/get_service_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -85,21 +86,27 @@ 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: {
size: 0,
query: {
bool: {
...projection.body.query.bool,
filter: options.serviceName
? filter.concat({
term: {
[SERVICE_NAME]: options.serviceName,
},
})
: filter,
filter,
},
},
aggs: {
Expand Down

0 comments on commit db3ab30

Please sign in to comment.