Skip to content

Commit

Permalink
Collect host.os.platform telemetry for APM (#103520)
Browse files Browse the repository at this point in the history
Fixes #97958.
  • Loading branch information
smith committed Jun 29, 2021
1 parent da13795 commit 1dce600
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 4 deletions.
22 changes: 22 additions & 0 deletions x-pack/plugins/apm/common/__snapshots__/apm_telemetry.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
CONTAINER_ID,
ERROR_GROUP_ID,
HOST_NAME,
HOST_OS_PLATFORM,
OBSERVER_HOSTNAME,
PARENT_ID,
POD_NAME,
Expand Down Expand Up @@ -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 }) => {
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/apm/server/lib/apm_telemetry/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export const apmSchema: MakeSchemaFrom<APMUsage> = {
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,
Expand Down Expand Up @@ -185,6 +186,7 @@ export const apmSchema: MakeSchemaFrom<APMUsage> = {
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 } },
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/apm/server/lib/apm_telemetry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface APMUsage {
provider: string[];
region: string[];
};
host: { os: { platform: string[] } };
counts: {
transaction: TimeframeMap;
span: TimeframeMap;
Expand Down Expand Up @@ -132,6 +133,7 @@ export interface APMUsage {
tasks: Record<
| 'aggregated_transactions'
| 'cloud'
| 'host'
| 'processor_events'
| 'agent_configuration'
| 'services'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
"__index": {
"type": "long"
},
"__swimlane": {
"__pagerduty": {
"type": "long"
},
"__pagerduty": {
"__swimlane": {
"type": "long"
},
"__server-log": {
Expand Down Expand Up @@ -71,10 +71,10 @@
"__index": {
"type": "long"
},
"__swimlane": {
"__pagerduty": {
"type": "long"
},
"__pagerduty": {
"__swimlane": {
"type": "long"
},
"__server-log": {
Expand Down Expand Up @@ -1260,6 +1260,20 @@
}
}
},
"host": {
"properties": {
"os": {
"properties": {
"platform": {
"type": "array",
"items": {
"type": "keyword"
}
}
}
}
}
},
"counts": {
"properties": {
"transaction": {
Expand Down Expand Up @@ -1552,6 +1566,17 @@
}
}
},
"host": {
"properties": {
"took": {
"properties": {
"ms": {
"type": "long"
}
}
}
}
},
"processor_events": {
"properties": {
"took": {
Expand Down

0 comments on commit 1dce600

Please sign in to comment.