Skip to content

Commit 86c5d3d

Browse files
committed
[APM] Add cloud attributes to data telemetry
Add cloud provider, region, and availability zone to the data telemetry mappings and queries. Fixes #70465
1 parent 735d3ba commit 86c5d3d

File tree

7 files changed

+102
-1
lines changed

7 files changed

+102
-1
lines changed

x-pack/plugins/apm/common/__snapshots__/apm_telemetry.test.ts.snap

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/apm/common/apm_telemetry.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ export function getApmTelemetryMapping() {
9191
{}
9292
),
9393
},
94+
cloud: {
95+
properties: {
96+
availability_zone: keyword,
97+
provider: keyword,
98+
region: keyword,
99+
},
100+
},
94101
counts: {
95102
properties: {
96103
agent_configuration: allProperties,

x-pack/plugins/apm/common/elasticsearch_fieldnames.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7+
export const CLOUD_AVAILABILITY_ZONE = 'cloud.availability_zone';
8+
export const CLOUD_PROVIDER = 'cloud.provider';
9+
export const CLOUD_REGION = 'cloud.region';
10+
711
export const SERVICE_NAME = 'service.name';
812
export const SERVICE_ENVIRONMENT = 'service.environment';
913
export const SERVICE_FRAMEWORK_NAME = 'service.framework.name';

x-pack/plugins/apm/dev_docs/telemetry.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ node ./scripts/merge-telemetry-mapping.js ../../../../telemetry/config/templates
6262

6363
this will replace the contents of the mapping in the repository checkout with the updated mapping. You can then [follow the telemetry team's instructions](https://github.com/elastic/telemetry#mappings) for opening a pull request with the mapping changes.
6464

65+
The queries for the stats are in the [collect data telemetry tasks](../server/lib/apm_telemetry/collect_data_telemetry/tasks.ts).
66+
67+
The collection tasks also use the [`APMDataTelemetry` type](../server/lib/apm_telemetry/types.ts) which also needs to be updated with any changes to the fields.
68+
6569
## Behavioral Telemetry
6670

6771
Behavioral telemetry is recorded with the ui_metrics and application_usage methods from the Usage Collection plugin.

x-pack/plugins/apm/scripts/upload-telemetry-data/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ async function uploadData() {
4949
...(httpAuth
5050
? {
5151
auth: { ...httpAuth, username: 'elastic' },
52+
ssl: { rejectUnauthorized: false },
5253
}
53-
: {}),
54+
: { ssl: { rejectUnauthorized: false } }),
5455
});
5556

5657
// The new template is the template downloaded from the telemetry repo, with

x-pack/plugins/apm/server/lib/apm_telemetry/collect_data_telemetry/tasks.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import {
2222
SERVICE_RUNTIME_NAME,
2323
SERVICE_RUNTIME_VERSION,
2424
USER_AGENT_ORIGINAL,
25+
CLOUD_AVAILABILITY_ZONE,
26+
CLOUD_PROVIDER,
27+
CLOUD_REGION,
2528
} from '../../../../common/elasticsearch_fieldnames';
2629
import { Span } from '../../../../typings/es_schemas/ui/span';
2730
import { APMError } from '../../../../typings/es_schemas/ui/apm_error';
@@ -32,6 +35,66 @@ const TIME_RANGES = ['1d', 'all'] as const;
3235
type TimeRange = typeof TIME_RANGES[number];
3336

3437
export const tasks: TelemetryTask[] = [
38+
{
39+
name: 'cloud',
40+
executor: async ({ indices, search }) => {
41+
function getBucketKeys({
42+
buckets,
43+
}: {
44+
buckets: Array<{
45+
doc_count: number;
46+
key: string | number;
47+
}>;
48+
}) {
49+
return buckets.map((bucket) => bucket.key as string);
50+
}
51+
52+
const az = 'availability_zone';
53+
const region = 'region';
54+
const provider = 'provider';
55+
56+
const response = await search({
57+
index: [
58+
indices['apm_oss.errorIndices'],
59+
indices['apm_oss.metricsIndices'],
60+
indices['apm_oss.spanIndices'],
61+
indices['apm_oss.transactionIndices'],
62+
],
63+
body: {
64+
size: 0,
65+
aggs: {
66+
[az]: {
67+
terms: {
68+
field: CLOUD_AVAILABILITY_ZONE,
69+
},
70+
},
71+
[provider]: {
72+
terms: {
73+
field: CLOUD_PROVIDER,
74+
},
75+
},
76+
[region]: {
77+
terms: {
78+
field: CLOUD_REGION,
79+
},
80+
},
81+
},
82+
},
83+
});
84+
85+
const { aggregations } = response;
86+
87+
if (!aggregations) {
88+
return { [az]: [], [provider]: [], [region]: [] };
89+
}
90+
const cloud = {
91+
[az]: getBucketKeys(aggregations[az]),
92+
[provider]: getBucketKeys(aggregations[provider]),
93+
[region]: getBucketKeys(aggregations[region]),
94+
};
95+
return { cloud };
96+
},
97+
},
3598
{
3699
name: 'processor_events',
37100
executor: async ({ indices, search }) => {

x-pack/plugins/apm/server/lib/apm_telemetry/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export type APMDataTelemetry = DeepPartial<{
2525
patch: number;
2626
};
2727
};
28+
cloud: {
29+
availability_zone: string[];
30+
provider: string[];
31+
region: string[];
32+
};
2833
counts: {
2934
transaction: TimeframeMap;
3035
span: TimeframeMap;
@@ -102,6 +107,7 @@ export type APMDataTelemetry = DeepPartial<{
102107
};
103108
};
104109
tasks: Record<
110+
| 'cloud'
105111
| 'processor_events'
106112
| 'agent_configuration'
107113
| 'services'

0 commit comments

Comments
 (0)