Skip to content

Commit 1934d34

Browse files
[APM] Add range query to service map trace walk (#86631)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent 8d2e51d commit 1934d34

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,27 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6+
import { rangeFilter } from '../../../common/utils/range_filter';
67
import { ProcessorEvent } from '../../../common/processor_event';
78
import { TRACE_ID } from '../../../common/elasticsearch_fieldnames';
89
import {
910
ConnectionNode,
1011
ExternalConnectionNode,
1112
ServiceConnectionNode,
1213
} from '../../../common/service_map';
13-
import { Setup } from '../helpers/setup_request';
14+
import { Setup, SetupTimeRange } from '../helpers/setup_request';
1415

1516
export async function fetchServicePathsFromTraceIds(
16-
setup: Setup,
17+
setup: Setup & SetupTimeRange,
1718
traceIds: string[]
1819
) {
1920
const { apmEventClient } = setup;
2021

22+
// make sure there's a range so ES can skip shards
23+
const dayInMs = 24 * 60 * 60 * 1000;
24+
const start = setup.start - dayInMs;
25+
const end = setup.end + dayInMs;
26+
2127
const serviceMapParams = {
2228
apm: {
2329
events: [ProcessorEvent.span, ProcessorEvent.transaction],
@@ -32,6 +38,7 @@ export async function fetchServicePathsFromTraceIds(
3238
[TRACE_ID]: traceIds,
3339
},
3440
},
41+
{ range: rangeFilter(start, end) },
3542
],
3643
},
3744
},

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
SERVICE_NAME,
1111
} from '../../../common/elasticsearch_fieldnames';
1212
import { Connection, ConnectionNode } from '../../../common/service_map';
13-
import { Setup } from '../helpers/setup_request';
13+
import { Setup, SetupTimeRange } from '../helpers/setup_request';
1414
import { fetchServicePathsFromTraceIds } from './fetch_service_paths_from_trace_ids';
1515

1616
export function getConnections({
@@ -79,7 +79,7 @@ export async function getServiceMapFromTraceIds({
7979
serviceName,
8080
environment,
8181
}: {
82-
setup: Setup;
82+
setup: Setup & SetupTimeRange;
8383
traceIds: string[];
8484
serviceName?: string;
8585
environment?: string;

0 commit comments

Comments
 (0)