From d9d2438aeed3b60a06aa7ab548c886ffcfb5e76a Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 27 Oct 2022 15:27:51 -0400 Subject: [PATCH] [APM] Performance fix for 'cardinality' telemetry task (#144061) (#144124) * Performance fix for 'cardinality' telemetry task * Make timeout/index required for telemetry searches * Fix tests Co-authored-by: Dario Gieselaar (cherry picked from commit a5c8ebe00d2f257dc251e2073b353f9689e4bb53) Co-authored-by: Colton Myers --- .../lib/apm_telemetry/collect_data_telemetry/index.ts | 6 +++++- .../lib/apm_telemetry/collect_data_telemetry/tasks.test.ts | 2 +- .../lib/apm_telemetry/collect_data_telemetry/tasks.ts | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/apm/server/lib/apm_telemetry/collect_data_telemetry/index.ts b/x-pack/plugins/apm/server/lib/apm_telemetry/collect_data_telemetry/index.ts index 559612cb07ead..b14de60d00f12 100644 --- a/x-pack/plugins/apm/server/lib/apm_telemetry/collect_data_telemetry/index.ts +++ b/x-pack/plugins/apm/server/lib/apm_telemetry/collect_data_telemetry/index.ts @@ -17,7 +17,11 @@ type ISavedObjectsClient = Pick; type TelemetryTaskExecutor = (params: { indices: ApmIndicesConfig; - search( + search< + TSearchRequest extends ESSearchRequest & { index: string | string[] } & { + body: { timeout: string }; + } + >( params: TSearchRequest ): Promise>; indicesStats( diff --git a/x-pack/plugins/apm/server/lib/apm_telemetry/collect_data_telemetry/tasks.test.ts b/x-pack/plugins/apm/server/lib/apm_telemetry/collect_data_telemetry/tasks.test.ts index b69aa1e6e0196..5f0c5e2c7ded4 100644 --- a/x-pack/plugins/apm/server/lib/apm_telemetry/collect_data_telemetry/tasks.test.ts +++ b/x-pack/plugins/apm/server/lib/apm_telemetry/collect_data_telemetry/tasks.test.ts @@ -433,7 +433,7 @@ describe('data telemetry collection tasks', () => { } }); - expect(await task?.executor({ search } as any)).toEqual({ + expect(await task?.executor({ search, indices } as any)).toEqual({ cardinality: { client: { geo: { country_iso_code: { rum: { '1d': 5 } } } }, transaction: { name: { all_agents: { '1d': 3 }, rum: { '1d': 1 } } }, diff --git a/x-pack/plugins/apm/server/lib/apm_telemetry/collect_data_telemetry/tasks.ts b/x-pack/plugins/apm/server/lib/apm_telemetry/collect_data_telemetry/tasks.ts index d9a695ff1f4e4..7283761c4b4bd 100644 --- a/x-pack/plugins/apm/server/lib/apm_telemetry/collect_data_telemetry/tasks.ts +++ b/x-pack/plugins/apm/server/lib/apm_telemetry/collect_data_telemetry/tasks.ts @@ -147,6 +147,7 @@ export const tasks: TelemetryTask[] = [ await search({ index: indices.transaction, body: { + timeout, query: { bool: { filter: [ @@ -354,6 +355,7 @@ export const tasks: TelemetryTask[] = [ const response = await search({ index: [indices.transaction], body: { + timeout, query: { bool: { filter: [{ range: { '@timestamp': { gte: 'now-1d' } } }], @@ -1031,8 +1033,9 @@ export const tasks: TelemetryTask[] = [ }, { name: 'cardinality', - executor: async ({ search }) => { + executor: async ({ indices, search }) => { const allAgentsCardinalityResponse = await search({ + index: [indices.transaction], body: { size: 0, timeout, @@ -1057,6 +1060,7 @@ export const tasks: TelemetryTask[] = [ }); const rumAgentCardinalityResponse = await search({ + index: [indices.transaction], body: { size: 0, timeout,