From 440c024d177e27df6dc30390dbacae618fc9bf35 Mon Sep 17 00:00:00 2001 From: Dario Gieselaar Date: Mon, 21 Dec 2020 12:30:38 +0100 Subject: [PATCH 1/2] [APM] Add range query to service map trace walk --- .../fetch_service_paths_from_trace_ids.ts | 13 +++++++++++-- .../service_map/get_service_map_from_trace_ids.ts | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/apm/server/lib/service_map/fetch_service_paths_from_trace_ids.ts b/x-pack/plugins/apm/server/lib/service_map/fetch_service_paths_from_trace_ids.ts index 14047f4bacea93..3a95935b9abb5e 100644 --- a/x-pack/plugins/apm/server/lib/service_map/fetch_service_paths_from_trace_ids.ts +++ b/x-pack/plugins/apm/server/lib/service_map/fetch_service_paths_from_trace_ids.ts @@ -3,6 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ +import { rangeFilter } from '../../../common/utils/range_filter'; import { ProcessorEvent } from '../../../common/processor_event'; import { TRACE_ID } from '../../../common/elasticsearch_fieldnames'; import { @@ -10,14 +11,19 @@ import { ExternalConnectionNode, ServiceConnectionNode, } from '../../../common/service_map'; -import { Setup } from '../helpers/setup_request'; +import { Setup, SetupTimeRange } from '../helpers/setup_request'; export async function fetchServicePathsFromTraceIds( - setup: Setup, + setup: Setup & SetupTimeRange, traceIds: string[] ) { const { apmEventClient } = setup; + // make sure there's a range so ES can skip shards + const day = 24 * 60 * 60 * 1000; + const start = setup.start - day; + const end = setup.end + day; + const serviceMapParams = { apm: { events: [ProcessorEvent.span, ProcessorEvent.transaction], @@ -32,6 +38,9 @@ export async function fetchServicePathsFromTraceIds( [TRACE_ID]: traceIds, }, }, + { + range: rangeFilter(start, end), + }, ], }, }, 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 14cfece22d0538..b650602062c0b7 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 @@ -10,7 +10,7 @@ import { SERVICE_NAME, } from '../../../common/elasticsearch_fieldnames'; import { Connection, ConnectionNode } from '../../../common/service_map'; -import { Setup } from '../helpers/setup_request'; +import { Setup, SetupTimeRange } from '../helpers/setup_request'; import { fetchServicePathsFromTraceIds } from './fetch_service_paths_from_trace_ids'; export function getConnections({ @@ -79,7 +79,7 @@ export async function getServiceMapFromTraceIds({ serviceName, environment, }: { - setup: Setup; + setup: Setup & SetupTimeRange; traceIds: string[]; serviceName?: string; environment?: string; From 062298e965801a4481c3c968293d4b140134bd69 Mon Sep 17 00:00:00 2001 From: Dario Gieselaar Date: Mon, 4 Jan 2021 09:14:56 +0100 Subject: [PATCH 2/2] Review feedback --- .../service_map/fetch_service_paths_from_trace_ids.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/apm/server/lib/service_map/fetch_service_paths_from_trace_ids.ts b/x-pack/plugins/apm/server/lib/service_map/fetch_service_paths_from_trace_ids.ts index 3a95935b9abb5e..f40ae7803e3645 100644 --- a/x-pack/plugins/apm/server/lib/service_map/fetch_service_paths_from_trace_ids.ts +++ b/x-pack/plugins/apm/server/lib/service_map/fetch_service_paths_from_trace_ids.ts @@ -20,9 +20,9 @@ export async function fetchServicePathsFromTraceIds( const { apmEventClient } = setup; // make sure there's a range so ES can skip shards - const day = 24 * 60 * 60 * 1000; - const start = setup.start - day; - const end = setup.end + day; + const dayInMs = 24 * 60 * 60 * 1000; + const start = setup.start - dayInMs; + const end = setup.end + dayInMs; const serviceMapParams = { apm: { @@ -38,9 +38,7 @@ export async function fetchServicePathsFromTraceIds( [TRACE_ID]: traceIds, }, }, - { - range: rangeFilter(start, end), - }, + { range: rangeFilter(start, end) }, ], }, },