Skip to content

Commit

Permalink
remove script; update docs; add schema
Browse files Browse the repository at this point in the history
  • Loading branch information
smith committed Jul 9, 2020
1 parent 374d6a3 commit 0786190
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 173 deletions.

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

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

import {
getApmTelemetryMapping,
getApmTelemetryMappingFullPath,
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
Expand All @@ -23,41 +19,28 @@ expect.addSnapshotSerializer({

describe('APM telemetry helpers', () => {
describe('getApmTelemetryFullPath', () => {
it('generates a JSON object with the full path telemetry mapping', () => {
expect(getApmTelemetryMappingFullPath()).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: {
// 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({
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();
});
});
});
37 changes: 0 additions & 37 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 @@ -222,39 +221,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;
});
}

/**
* Create the just the mapping at its full path
*/
export function getApmTelemetryMappingFullPath() {
return {
properties: {
stack_stats: {
properties: {
kibana: {
properties: {
plugins: {
properties: {
apm: getApmTelemetryMapping(),
},
},
},
},
},
},
},
};
}
14 changes: 1 addition & 13 deletions x-pack/plugins/apm/dev_docs/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,10 @@ 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`. Pull requests with changes to the schema should automatically notify the Telemetry team so they can update the mapping in the telemetry clusters.

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.

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 slug-for-my-change 7.9
```

this will replace the contents of the mapping in the repository checkout with the updated mapping.

It will also create a file in the mapping_migrations directory named "00XX-slug-for-my-change". You'll need to rename the file to replace the "XX" with the next sequential migration number based on what's there already and in open pull requests.

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.
Expand Down
21 changes: 0 additions & 21 deletions x-pack/plugins/apm/scripts/merge-telemetry-mapping.js

This file was deleted.

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

This file was deleted.

12 changes: 7 additions & 5 deletions x-pack/plugins/apm/server/lib/apm_telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { CoreSetup, Logger } from 'src/core/server';
import { Observable } from 'rxjs';
import { take } from 'rxjs/operators';
import { CoreSetup, Logger } from 'src/core/server';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { getApmTelemetryMapping } from '../../../common/apm_telemetry';
import { APMConfig } from '../..';
import {
TaskManagerStartContract,
TaskManagerSetupContract,
TaskManagerStartContract,
} from '../../../../task_manager/server';
import { getApmIndices } from '../settings/apm_indices/get_apm_indices';
import {
APM_TELEMETRY_SAVED_OBJECT_ID,
APM_TELEMETRY_SAVED_OBJECT_TYPE,
} from '../../../common/apm_saved_object_constants';
import { getInternalSavedObjectsClient } from '../helpers/get_internal_saved_objects_client';
import { getApmIndices } from '../settings/apm_indices/get_apm_indices';
import {
collectDataTelemetry,
CollectTelemetryParams,
} from './collect_data_telemetry';
import { APMConfig } from '../..';
import { getInternalSavedObjectsClient } from '../helpers/get_internal_saved_objects_client';

const APM_TELEMETRY_TASK_NAME = 'apm-telemetry-task';

Expand Down Expand Up @@ -97,6 +98,7 @@ export async function createApmTelemetry({

const collector = usageCollector.makeUsageCollector({
type: 'apm',
schema: getApmTelemetryMapping(),
fetch: async () => {
try {
const data = (
Expand Down

0 comments on commit 0786190

Please sign in to comment.