diff --git a/x-pack/plugins/apm/common/__snapshots__/apm_telemetry.test.ts.snap b/x-pack/plugins/apm/common/__snapshots__/apm_telemetry.test.ts.snap index d7fc8e6442f12e..71b0929164705b 100644 --- a/x-pack/plugins/apm/common/__snapshots__/apm_telemetry.test.ts.snap +++ b/x-pack/plugins/apm/common/__snapshots__/apm_telemetry.test.ts.snap @@ -675,6 +675,17 @@ exports[`APM telemetry helpers getApmTelemetry generates a JSON object with the } } }, + "host": { + "properties": { + "os": { + "properties": { + "platform": { + "type": "keyword" + } + } + } + } + }, "counts": { "properties": { "transaction": { @@ -967,6 +978,17 @@ exports[`APM telemetry helpers getApmTelemetry generates a JSON object with the } } }, + "host": { + "properties": { + "took": { + "properties": { + "ms": { + "type": "long" + } + } + } + } + }, "processor_events": { "properties": { "took": { 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 129da710978630..4bfac442b4a3cb 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 @@ -209,6 +209,44 @@ describe('data telemetry collection tasks', () => { }); }); + describe('host', () => { + const task = tasks.find((t) => t.name === 'host'); + + it('returns a map of host provider data', async () => { + const search = jest.fn().mockResolvedValueOnce({ + aggregations: { + platform: { + buckets: [ + { doc_count: 1, key: 'linux' }, + { doc_count: 1, key: 'windows' }, + { doc_count: 1, key: 'macos' }, + ], + }, + }, + }); + + expect(await task?.executor({ indices, search } as any)).toEqual({ + host: { + os: { platform: ['linux', 'windows', 'macos'] }, + }, + }); + }); + + describe('with no results', () => { + it('returns an empty map', async () => { + const search = jest.fn().mockResolvedValueOnce({}); + + expect(await task?.executor({ indices, search } as any)).toEqual({ + host: { + os: { + platform: [], + }, + }, + }); + }); + }); + }); + describe('processor_events', () => { const task = tasks.find((t) => t.name === 'processor_events'); 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 3d5b4b754e4aa5..fd341565c235b0 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 @@ -20,6 +20,7 @@ import { CONTAINER_ID, ERROR_GROUP_ID, HOST_NAME, + HOST_OS_PLATFORM, OBSERVER_HOSTNAME, PARENT_ID, POD_NAME, @@ -293,6 +294,53 @@ export const tasks: TelemetryTask[] = [ return { cloud }; }, }, + { + name: 'host', + executor: async ({ indices, search }) => { + function getBucketKeys({ + buckets, + }: { + buckets: Array<{ + doc_count: number; + key: string | number; + }>; + }) { + return buckets.map((bucket) => bucket.key as string); + } + + const response = await search({ + index: [ + indices['apm_oss.errorIndices'], + indices['apm_oss.metricsIndices'], + indices['apm_oss.spanIndices'], + indices['apm_oss.transactionIndices'], + ], + body: { + size: 0, + timeout, + aggs: { + platform: { + terms: { + field: HOST_OS_PLATFORM, + }, + }, + }, + }, + }); + + const { aggregations } = response; + + if (!aggregations) { + return { host: { os: { platform: [] } } }; + } + const host = { + os: { + platform: getBucketKeys(aggregations.platform), + }, + }; + return { host }; + }, + }, { name: 'environments', executor: async ({ indices, search }) => { diff --git a/x-pack/plugins/apm/server/lib/apm_telemetry/schema.ts b/x-pack/plugins/apm/server/lib/apm_telemetry/schema.ts index 0b1bc3d50d4c1a..b04f64c6bccff6 100644 --- a/x-pack/plugins/apm/server/lib/apm_telemetry/schema.ts +++ b/x-pack/plugins/apm/server/lib/apm_telemetry/schema.ts @@ -135,6 +135,7 @@ export const apmSchema: MakeSchemaFrom = { provider: { type: 'array', items: { type: 'keyword' } }, region: { type: 'array', items: { type: 'keyword' } }, }, + host: { os: { platform: { type: 'array', items: { type: 'keyword' } } } }, counts: { transaction: timeframeMapSchema, span: timeframeMapSchema, @@ -185,6 +186,7 @@ export const apmSchema: MakeSchemaFrom = { tasks: { aggregated_transactions: { took: { ms: long } }, cloud: { took: { ms: long } }, + host: { took: { ms: long } }, processor_events: { took: { ms: long } }, agent_configuration: { took: { ms: long } }, services: { took: { ms: long } }, diff --git a/x-pack/plugins/apm/server/lib/apm_telemetry/types.ts b/x-pack/plugins/apm/server/lib/apm_telemetry/types.ts index 6dc829425eadac..cd4e80ff6bf6bc 100644 --- a/x-pack/plugins/apm/server/lib/apm_telemetry/types.ts +++ b/x-pack/plugins/apm/server/lib/apm_telemetry/types.ts @@ -52,6 +52,7 @@ export interface APMUsage { provider: string[]; region: string[]; }; + host: { os: { platform: string[] } }; counts: { transaction: TimeframeMap; span: TimeframeMap; @@ -132,6 +133,7 @@ export interface APMUsage { tasks: Record< | 'aggregated_transactions' | 'cloud' + | 'host' | 'processor_events' | 'agent_configuration' | 'services' diff --git a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json index bab4244139df07..5a8b30c5c0f267 100644 --- a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json +++ b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @@ -31,10 +31,10 @@ "__index": { "type": "long" }, - "__swimlane": { + "__pagerduty": { "type": "long" }, - "__pagerduty": { + "__swimlane": { "type": "long" }, "__server-log": { @@ -71,10 +71,10 @@ "__index": { "type": "long" }, - "__swimlane": { + "__pagerduty": { "type": "long" }, - "__pagerduty": { + "__swimlane": { "type": "long" }, "__server-log": { @@ -1260,6 +1260,20 @@ } } }, + "host": { + "properties": { + "os": { + "properties": { + "platform": { + "type": "array", + "items": { + "type": "keyword" + } + } + } + } + } + }, "counts": { "properties": { "transaction": { @@ -1552,6 +1566,17 @@ } } }, + "host": { + "properties": { + "took": { + "properties": { + "ms": { + "type": "long" + } + } + } + } + }, "processor_events": { "properties": { "took": {