Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM] Additional data telemetry changes #71112

Merged
merged 16 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,892 changes: 968 additions & 924 deletions x-pack/plugins/apm/common/__snapshots__/apm_telemetry.test.ts.snap

Large diffs are not rendered by default.

57 changes: 26 additions & 31 deletions x-pack/plugins/apm/common/apm_telemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,43 @@
* you may not use this file except in compliance with the Elastic License.
*/

import {
getApmTelemetryMapping,
mergeApmTelemetryMapping,
} from './apm_telemetry';
import { getApmTelemetryMapping } from './apm_telemetry';

// Add this snapshot serializer for this test. The default snapshot serializer
// prints "Object" next to objects in the JSON output, but we want to be able to
// Use the output from this JSON snapshot to share with the telemetry team. When
// new fields are added to the mapping, we'll have a diff in the snapshot.
expect.addSnapshotSerializer({
print: (contents) => {
return JSON.stringify(contents, null, 2);
},
test: () => true,
});

describe('APM telemetry helpers', () => {
describe('getApmTelemetry', () => {
// This test creates a snapshot with the JSON of our full telemetry mapping
// that can be PUT in a query to the index on the telemetry cluster. Sharing
// the contents of the snapshot with the telemetry team can provide them with
// useful information about changes to our telmetry.
it('generates a JSON object with the telemetry mapping', () => {
expect(getApmTelemetryMapping()).toMatchSnapshot();
});
});

describe('mergeApmTelemetryMapping', () => {
describe('with an invalid mapping', () => {
it('throws an error', () => {
expect(() => mergeApmTelemetryMapping({})).toThrowError();
});
});

describe('with a valid mapping', () => {
it('merges the mapping', () => {
// This is "valid" in the sense that it has all of the deep fields
// needed to merge. It's not a valid mapping opbject.
const validTelemetryMapping = {
mappings: {
expect({
properties: {
stack_stats: {
properties: {
stack_stats: {
kibana: {
properties: {
kibana: {
properties: { plugins: { properties: { apm: {} } } },
plugins: {
properties: {
apm: getApmTelemetryMapping(),
},
},
},
},
},
},
};

expect(
mergeApmTelemetryMapping(validTelemetryMapping)?.mappings.properties
.stack_stats.properties.kibana.properties.plugins.properties.apm
).toEqual(getApmTelemetryMapping());
});
},
}).toMatchSnapshot();
});
});
});
24 changes: 10 additions & 14 deletions x-pack/plugins/apm/common/apm_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { produce } from 'immer';
import { AGENT_NAMES } from './agent_name';

/**
Expand Down Expand Up @@ -115,6 +114,15 @@ export function getApmTelemetryMapping() {
},
cardinality: {
properties: {
client: {
properties: {
geo: {
properites: {
country_iso_code: { rum: oneDayProperties },
},
},
},
},
user_agent: {
properties: {
original: {
Expand Down Expand Up @@ -199,6 +207,7 @@ export function getApmTelemetryMapping() {
agent_configuration: tookProperties,
agents: tookProperties,
cardinality: tookProperties,
cloud: tookProperties,
groupings: tookProperties,
indices_stats: tookProperties,
integrations: tookProperties,
Expand All @@ -221,16 +230,3 @@ export function getApmTelemetryMapping() {
},
};
}

/**
* Merge a telemetry mapping object (from https://github.com/elastic/telemetry/blob/master/config/templates/xpack-phone-home.json)
* with the output from `getApmTelemetryMapping`.
*/
export function mergeApmTelemetryMapping(
xpackPhoneHomeMapping: Record<string, any>
) {
return produce(xpackPhoneHomeMapping, (draft: Record<string, any>) => {
draft.mappings.properties.stack_stats.properties.kibana.properties.plugins.properties.apm = getApmTelemetryMapping();
return draft;
});
}
12 changes: 4 additions & 8 deletions x-pack/plugins/apm/dev_docs/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,16 @@ The mapping for the telemetry data is here under `stack_stats.kibana.plugins.apm

The mapping used there can be generated with the output of the [`getTelemetryMapping`](../common/apm_telemetry.ts) function.

To make a change to the mapping, edit this function, run the tests to update the snapshots, then use the `merge_telemetry_mapping` script to merge the data into the telemetry repository.
The `schema` property of the `makeUsageCollector` call in the [`createApmTelemetry` function](../server/lib/apm_telemetry/index.ts) contains the output of `getTelemetryMapping`.

If the [telemetry repository](https://github.com/elastic/telemetry) is cloned as a sibling to the kibana directory, you can run the following from x-pack/plugins/apm:

```bash
node ./scripts/merge-telemetry-mapping.js ../../../../telemetry/config/templates/xpack-phone-home.json
```

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.
When adding a task, the key of the task and the `took` properties need to be added under the `tasks` properties in the mapping, as when tasks run they report the time they took.

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.

Running `node scripts/telemetry_check --fix` from the root Kibana directory will update the schemas which schema should automatically notify the Telemetry team when a pull request is opened so they can update the mapping in the telemetry clusters. (At the time of this writing the APM schema is excluded. #70180 is open to remove these exclusions so at this time any pull requests with mapping changes will have to manually request the Telemetry team as a reviewer.)

## Behavioral Telemetry

Behavioral telemetry is recorded with the ui_metrics and application_usage methods from the Usage Collection plugin.
Expand Down
21 changes: 0 additions & 21 deletions x-pack/plugins/apm/scripts/merge-telemetry-mapping.js

This file was deleted.

30 changes: 0 additions & 30 deletions x-pack/plugins/apm/scripts/merge-telemetry-mapping/index.ts

This file was deleted.

Loading