Skip to content

Commit

Permalink
[APM] Add cloud attributes to data telemetry
Browse files Browse the repository at this point in the history
Add cloud provider, region, and availability zone to the data telemetry mappings and queries.

Fixes #70465
  • Loading branch information
smith committed Jul 7, 2020
1 parent 735d3ba commit 86c5d3d
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 1 deletion.
16 changes: 16 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.

7 changes: 7 additions & 0 deletions x-pack/plugins/apm/common/apm_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ export function getApmTelemetryMapping() {
{}
),
},
cloud: {
properties: {
availability_zone: keyword,
provider: keyword,
region: keyword,
},
},
counts: {
properties: {
agent_configuration: allProperties,
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/apm/common/elasticsearch_fieldnames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

export const CLOUD_AVAILABILITY_ZONE = 'cloud.availability_zone';
export const CLOUD_PROVIDER = 'cloud.provider';
export const CLOUD_REGION = 'cloud.region';

export const SERVICE_NAME = 'service.name';
export const SERVICE_ENVIRONMENT = 'service.environment';
export const SERVICE_FRAMEWORK_NAME = 'service.framework.name';
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/apm/dev_docs/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ node ./scripts/merge-telemetry-mapping.js ../../../../telemetry/config/templates

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.

The queries for the stats are in the [collect data telemetry tasks](../server/lib/apm_telemetry/collect_data_telemetry/tasks.ts).

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.

## Behavioral Telemetry

Behavioral telemetry is recorded with the ui_metrics and application_usage methods from the Usage Collection plugin.
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/apm/scripts/upload-telemetry-data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ async function uploadData() {
...(httpAuth
? {
auth: { ...httpAuth, username: 'elastic' },
ssl: { rejectUnauthorized: false },
}
: {}),
: { ssl: { rejectUnauthorized: false } }),
});

// The new template is the template downloaded from the telemetry repo, with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import {
SERVICE_RUNTIME_NAME,
SERVICE_RUNTIME_VERSION,
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';
Expand All @@ -32,6 +35,66 @@ const TIME_RANGES = ['1d', 'all'] as const;
type TimeRange = typeof TIME_RANGES[number];

export const tasks: TelemetryTask[] = [
{
name: 'cloud',
executor: async ({ indices, search }) => {
function getBucketKeys({
buckets,
}: {
buckets: Array<{
doc_count: number;
key: string | number;
}>;
}) {
return buckets.map((bucket) => bucket.key as string);
}

const az = 'availability_zone';
const region = 'region';
const provider = 'provider';

const response = await search({
index: [
indices['apm_oss.errorIndices'],
indices['apm_oss.metricsIndices'],
indices['apm_oss.spanIndices'],
indices['apm_oss.transactionIndices'],
],
body: {
size: 0,
aggs: {
[az]: {
terms: {
field: CLOUD_AVAILABILITY_ZONE,
},
},
[provider]: {
terms: {
field: CLOUD_PROVIDER,
},
},
[region]: {
terms: {
field: CLOUD_REGION,
},
},
},
},
});

const { aggregations } = response;

if (!aggregations) {
return { [az]: [], [provider]: [], [region]: [] };
}
const cloud = {
[az]: getBucketKeys(aggregations[az]),
[provider]: getBucketKeys(aggregations[provider]),
[region]: getBucketKeys(aggregations[region]),
};
return { cloud };
},
},
{
name: 'processor_events',
executor: async ({ indices, search }) => {
Expand Down
6 changes: 6 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 @@ -25,6 +25,11 @@ export type APMDataTelemetry = DeepPartial<{
patch: number;
};
};
cloud: {
availability_zone: string[];
provider: string[];
region: string[];
};
counts: {
transaction: TimeframeMap;
span: TimeframeMap;
Expand Down Expand Up @@ -102,6 +107,7 @@ export type APMDataTelemetry = DeepPartial<{
};
};
tasks: Record<
| 'cloud'
| 'processor_events'
| 'agent_configuration'
| 'services'
Expand Down

0 comments on commit 86c5d3d

Please sign in to comment.