Skip to content

Commit b1b3211

Browse files
committed
Example of straighening projections out
1 parent 40ff82d commit b1b3211

3 files changed

Lines changed: 45 additions & 38 deletions

File tree

x-pack/plugins/apm/common/projections/services.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import {
8-
Setup,
9-
SetupUIFilters,
10-
SetupTimeRange,
11-
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
12-
} from '../../server/lib/helpers/setup_request';
137
import { SERVICE_NAME, PROCESSOR_EVENT } from '../elasticsearch_fieldnames';
14-
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
158
import { rangeFilter } from '../utils/range_filter';
9+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
10+
import { ApmIndicesConfig } from '../../server/lib/settings/apm_indices/get_apm_indices';
11+
import { ESFilter } from '../../typings/elasticsearch';
1612

1713
export function getServicesProjection({
18-
setup,
14+
start,
15+
end,
16+
uiFiltersES,
17+
indices,
1918
}: {
20-
setup: Setup & SetupTimeRange & SetupUIFilters;
19+
start: number;
20+
end: number;
21+
uiFiltersES: ESFilter[];
22+
indices: ApmIndicesConfig;
2123
}) {
22-
const { start, end, uiFiltersES, indices } = setup;
23-
2424
return {
2525
index: [
2626
indices['apm_oss.metricsIndices'],

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
SERVICE_NAME,
1111
} from '../../../common/elasticsearch_fieldnames';
1212
import { getServicesProjection } from '../../../common/projections/services';
13-
import { mergeProjection } from '../../../common/projections/util/merge_projection';
1413
import { PromiseReturnType } from '../../../typings/common';
1514
import { Setup, SetupTimeRange } from '../helpers/setup_request';
1615
import { transformServiceMapResponses } from './transform_service_map_responses';
@@ -76,21 +75,17 @@ async function getServicesData(options: IEnvOptions) {
7675
setup: { ...setup, uiFiltersES: [] },
7776
});
7877

79-
const { filter } = projection.body.query.bool;
78+
const serviceNameFilter = options.serviceName
79+
? [{ term: { [SERVICE_NAME]: options.serviceName } }]
80+
: [];
8081

81-
const params = mergeProjection(projection, {
82+
const params = {
8283
body: {
84+
index: projection.index,
8385
size: 0,
8486
query: {
8587
bool: {
86-
...projection.body.query.bool,
87-
filter: options.serviceName
88-
? filter.concat({
89-
term: {
90-
[SERVICE_NAME]: options.serviceName,
91-
},
92-
})
93-
: filter,
88+
filter: [...projection.body.query.bool.filter, ...serviceNameFilter],
9489
},
9590
},
9691
aggs: {
@@ -109,7 +104,7 @@ async function getServicesData(options: IEnvOptions) {
109104
},
110105
},
111106
},
112-
});
107+
};
113108

114109
const { client } = setup;
115110

x-pack/plugins/apm/server/lib/services/get_services/get_services_items.ts

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,48 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { mergeProjection } from '../../../../common/projections/util/merge_projection';
7+
import { ESFilter } from '../../../../typings/elasticsearch';
88
import {
99
PROCESSOR_EVENT,
1010
AGENT_NAME,
1111
SERVICE_ENVIRONMENT,
1212
TRANSACTION_DURATION,
1313
} from '../../../../common/elasticsearch_fieldnames';
1414
import { PromiseReturnType } from '../../../../typings/common';
15-
import {
16-
Setup,
17-
SetupTimeRange,
18-
SetupUIFilters,
19-
} from '../../helpers/setup_request';
2015
import { getServicesProjection } from '../../../../common/projections/services';
16+
import { ApmIndicesConfig } from '../../settings/apm_indices/get_apm_indices';
17+
import { ESClient } from '../../helpers/es_client';
2118

2219
export type ServiceListAPIResponse = PromiseReturnType<typeof getServicesItems>;
23-
export async function getServicesItems(
24-
setup: Setup & SetupTimeRange & SetupUIFilters
25-
) {
26-
const { start, end, client } = setup;
27-
28-
const projection = getServicesProjection({ setup });
20+
export async function getServicesItems({
21+
start,
22+
end,
23+
uiFiltersES,
24+
indices,
25+
client,
26+
}: {
27+
start: number;
28+
end: number;
29+
uiFiltersES: ESFilter[];
30+
indices: ApmIndicesConfig;
31+
client: ESClient;
32+
}) {
33+
const projection = getServicesProjection({
34+
start,
35+
end,
36+
uiFiltersES,
37+
indices,
38+
});
2939

30-
const params = mergeProjection(projection, {
40+
const params = {
3141
body: {
42+
index: projection.index,
3243
size: 0,
44+
query: projection.body.query,
3345
aggs: {
3446
services: {
3547
terms: {
36-
...projection.body.aggs.services.terms,
48+
field: projection.body.aggs.services.terms.field,
3749
size: 500,
3850
},
3951
aggs: {
@@ -53,7 +65,7 @@ export async function getServicesItems(
5365
},
5466
},
5567
},
56-
});
68+
};
5769

5870
const resp = await client.search(params);
5971
const aggs = resp.aggregations;

0 commit comments

Comments
 (0)