From 1f5a1fe66cdc3c037544fdb4c6ce92b77d959208 Mon Sep 17 00:00:00 2001 From: Nathan L Smith Date: Wed, 8 Jul 2020 19:59:53 -0500 Subject: [PATCH] [APM] Update ML job ID in data telemetry tasks (#71044) * [APM] Update ML job ID in data telemetry tasks Use "apm-*" to match the new job IDs added in #70560. * additional fix * Remove unused import --- .../collect_data_telemetry/tasks.test.ts | 36 +++++++++++++++++++ .../collect_data_telemetry/tasks.ts | 26 +++++++------- 2 files changed, 49 insertions(+), 13 deletions(-) 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 c648cf4cc116..e3161b49b315 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 @@ -65,4 +65,40 @@ describe('data telemetry collection tasks', () => { }); }); }); + + describe('integrations', () => { + const integrationsTask = tasks.find((task) => task.name === 'integrations'); + + it('returns the count of ML jobs', async () => { + const transportRequest = jest + .fn() + .mockResolvedValueOnce({ body: { count: 1 } }); + + expect( + await integrationsTask?.executor({ indices, transportRequest } as any) + ).toEqual({ + integrations: { + ml: { + all_jobs_count: 1, + }, + }, + }); + }); + + describe('with no data', () => { + it('returns a count of 0', async () => { + const transportRequest = jest.fn().mockResolvedValueOnce({}); + + expect( + await integrationsTask?.executor({ indices, transportRequest } as any) + ).toEqual({ + integrations: { + ml: { + all_jobs_count: 0, + }, + }, + }); + }); + }); + }); }); 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 f27af9a2cc51..4bbaaf3e86e7 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 @@ -4,31 +4,31 @@ * you may not use this file except in compliance with the Elastic License. */ import { flatten, merge, sortBy, sum } from 'lodash'; -import { AgentName } from '../../../../typings/es_schemas/ui/fields/agent'; +import { TelemetryTask } from '.'; import { AGENT_NAMES } from '../../../../common/agent_name'; -import { Transaction } from '../../../../typings/es_schemas/ui/transaction'; import { - PROCESSOR_EVENT, - SERVICE_NAME, AGENT_NAME, AGENT_VERSION, + CLOUD_AVAILABILITY_ZONE, + CLOUD_PROVIDER, + CLOUD_REGION, ERROR_GROUP_ID, - TRANSACTION_NAME, PARENT_ID, + PROCESSOR_EVENT, SERVICE_FRAMEWORK_NAME, SERVICE_FRAMEWORK_VERSION, SERVICE_LANGUAGE_NAME, SERVICE_LANGUAGE_VERSION, + SERVICE_NAME, SERVICE_RUNTIME_NAME, SERVICE_RUNTIME_VERSION, + TRANSACTION_NAME, USER_AGENT_ORIGINAL, - CLOUD_AVAILABILITY_ZONE, - CLOUD_PROVIDER, - CLOUD_REGION, } from '../../../../common/elasticsearch_fieldnames'; -import { Span } from '../../../../typings/es_schemas/ui/span'; import { APMError } from '../../../../typings/es_schemas/ui/apm_error'; -import { TelemetryTask } from '.'; +import { AgentName } from '../../../../typings/es_schemas/ui/fields/agent'; +import { Span } from '../../../../typings/es_schemas/ui/span'; +import { Transaction } from '../../../../typings/es_schemas/ui/transaction'; import { APMTelemetry } from '../types'; const TIME_RANGES = ['1d', 'all'] as const; @@ -465,17 +465,17 @@ export const tasks: TelemetryTask[] = [ { name: 'integrations', executor: async ({ transportRequest }) => { - const apmJobs = ['*-high_mean_response_time']; + const apmJobs = ['apm-*', '*-high_mean_response_time']; const response = (await transportRequest({ method: 'get', path: `/_ml/anomaly_detectors/${apmJobs.join(',')}`, - })) as { data?: { count: number } }; + })) as { body?: { count: number } }; return { integrations: { ml: { - all_jobs_count: response.data?.count ?? 0, + all_jobs_count: response.body?.count ?? 0, }, }, };