diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 52082a2ca33c7f..47f9942162f75c 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -178,11 +178,11 @@ /src/plugins/telemetry_management_section/ @elastic/kibana-telemetry /src/plugins/usage_collection/ @elastic/kibana-telemetry /x-pack/plugins/telemetry_collection_xpack/ @elastic/kibana-telemetry -/.telemetryrc.json @elastic/pulse -/x-pack/.telemetryrc.json @elastic/pulse -src/plugins/telemetry/schema/legacy_oss_plugins.json @elastic/pulse -src/plugins/telemetry/schema/oss_plugins.json @elastic/pulse -x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @elastic/pulse +/.telemetryrc.json @elastic/kibana-telemetry +/x-pack/.telemetryrc.json @elastic/kibana-telemetry +src/plugins/telemetry/schema/legacy_oss_plugins.json @elastic/kibana-telemetry +src/plugins/telemetry/schema/oss_plugins.json @elastic/kibana-telemetry +x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @elastic/kibana-telemetry # Kibana Alerting Services /x-pack/plugins/alerts/ @elastic/kibana-alerting-services diff --git a/packages/kbn-telemetry-tools/src/tools/README.md b/packages/kbn-telemetry-tools/README.md similarity index 86% rename from packages/kbn-telemetry-tools/src/tools/README.md rename to packages/kbn-telemetry-tools/README.md index 1162da2bf40658..ccd092c76a17c4 100644 --- a/packages/kbn-telemetry-tools/src/tools/README.md +++ b/packages/kbn-telemetry-tools/README.md @@ -4,7 +4,7 @@ ### Description -The tool is used to extract telemetry collectors schema from all `*.{js, ts, jsx, tsx, html, pug}` files in provided plugins directories to JSON files. The tool looks for `.telemeryrc.json` files in the root of the project and in the `x-pack` dir for its runtime configurations. +The tool is used to extract telemetry collectors schema from all `*.{ts}` files in provided plugins directories to JSON files. The tool looks for `.telemetryrc.json` files in the root of the project and in the `x-pack` dir for its runtime configurations. It uses typescript parser to build an AST for each file. The tool is able to validate, extract and match collector schemas. @@ -27,7 +27,7 @@ export const myCollector = makeUsageCollector({ node scripts/telemetry_extract.js ``` -This command has no additional flags or arguments. The `.telemetryrc.json` files specify the path to the directory(-es) where searching should start, output json files, and files to exclude. +This command has no additional flags or arguments. The `.telemetryrc.json` files specify the path to the directory where searching should start, output json files, and files to exclude. ### Output @@ -71,7 +71,7 @@ What will not be caught by the validator: * Fields in the schema that are never collected. If you are trying to report a field from ES but that value is never stored in ES, the check will not be able to detect if that field is ever collected in the first palce. It is advised to add unit/functional tests to check that all the fields are being reported as expected. -The tool looks for `.telemeryrc.json` files in the root of the project and in the `x-pack` dir for its runtime configurations. +The tool looks for `.telemetryrc.json` files in the root of the project and in the `x-pack` dir for its runtime configurations. Currently auto-fixer (`--fix`) can automatically fix the json files with the following errors: @@ -86,4 +86,4 @@ node scripts/telemetry_check --fix ``` * `--path` specifies a collector path instead of checking all collectors specified in the `.telemetryrc.json` files. Accepts a `.ts` file. The file must be discoverable by at least one rc file. -* `--fix` tells the tool to try to fix as much violations as possible. All errors that tool won't be able to fix will be reported. +* `--fix` tells the tool to try to fix as many violations as possible. All errors that tool won't be able to fix will be reported. diff --git a/packages/kbn-telemetry-tools/src/tools/__fixture__/constants.ts b/packages/kbn-telemetry-tools/src/tools/__fixture__/constants.ts index 8f79ed6794b9fc..ec1c983ea93fa6 100644 --- a/packages/kbn-telemetry-tools/src/tools/__fixture__/constants.ts +++ b/packages/kbn-telemetry-tools/src/tools/__fixture__/constants.ts @@ -17,7 +17,7 @@ * under the License. */ import moment, { Moment } from 'moment'; -import { MakeSchemaFrom } from '../../../../src/plugins/usage_collection/server'; +import { MakeSchemaFrom } from '../../../../../src/plugins/usage_collection/server'; export interface Usage { locale: string; diff --git a/packages/kbn-telemetry-tools/src/tools/__fixture__/externally_defined_collector.ts b/packages/kbn-telemetry-tools/src/tools/__fixture__/externally_defined_collector.ts index 7fd038f0ce4732..031cea0b037b79 100644 --- a/packages/kbn-telemetry-tools/src/tools/__fixture__/externally_defined_collector.ts +++ b/packages/kbn-telemetry-tools/src/tools/__fixture__/externally_defined_collector.ts @@ -19,8 +19,8 @@ import { CollectorSet, CollectorOptions, -} from '../../../../src/plugins/usage_collection/server/collector'; -import { loggingServiceMock } from '../../../../src/core/server/mocks'; +} from '../../../../../src/plugins/usage_collection/server/collector'; +import { loggingServiceMock } from '../../../../../src/core/server/mocks'; const collectorSet = new CollectorSet({ logger: loggingServiceMock.createLogger(), diff --git a/packages/kbn-telemetry-tools/src/tools/__fixture__/imported_schema.ts b/packages/kbn-telemetry-tools/src/tools/__fixture__/imported_schema.ts index f2974dd91e43d6..5a4673ed2419a3 100644 --- a/packages/kbn-telemetry-tools/src/tools/__fixture__/imported_schema.ts +++ b/packages/kbn-telemetry-tools/src/tools/__fixture__/imported_schema.ts @@ -16,8 +16,8 @@ * specific language governing permissions and limitations * under the License. */ -import { CollectorSet } from '../../../../src/plugins/usage_collection/server/collector'; -import { loggingServiceMock } from '../../../../src/core/server/mocks'; +import { CollectorSet } from '../../../../../src/plugins/usage_collection/server/collector'; +import { loggingServiceMock } from '../../../../../src/core/server/mocks'; import { externallyDefinedSchema } from './constants'; const { makeUsageCollector } = new CollectorSet({ diff --git a/packages/kbn-telemetry-tools/src/tools/__fixture__/imported_usage_interface.ts b/packages/kbn-telemetry-tools/src/tools/__fixture__/imported_usage_interface.ts index 5323dbaa7b97dc..20d5d3fb49e5ab 100644 --- a/packages/kbn-telemetry-tools/src/tools/__fixture__/imported_usage_interface.ts +++ b/packages/kbn-telemetry-tools/src/tools/__fixture__/imported_usage_interface.ts @@ -16,8 +16,8 @@ * specific language governing permissions and limitations * under the License. */ -import { CollectorSet } from '../../../../src/plugins/usage_collection/server/collector'; -import { loggingServiceMock } from '../../../../src/core/server/mocks'; +import { CollectorSet } from '../../../../../src/plugins/usage_collection/server/collector'; +import { loggingServiceMock } from '../../../../../src/core/server/mocks'; import { Usage } from './constants'; const { makeUsageCollector } = new CollectorSet({ diff --git a/packages/kbn-telemetry-tools/src/tools/__fixture__/nested_collector.ts b/packages/kbn-telemetry-tools/src/tools/__fixture__/nested_collector.ts index 4ad1290f3c9b07..f707b662a9d0f9 100644 --- a/packages/kbn-telemetry-tools/src/tools/__fixture__/nested_collector.ts +++ b/packages/kbn-telemetry-tools/src/tools/__fixture__/nested_collector.ts @@ -19,8 +19,8 @@ import { CollectorSet, UsageCollector, -} from '../../../../src/plugins/usage_collection/server/collector'; -import { loggingServiceMock } from '../../../../src/core/server/mocks'; +} from '../../../../../src/plugins/usage_collection/server/collector'; +import { loggingServiceMock } from '../../../../../src/core/server/mocks'; const collectorSet = new CollectorSet({ logger: loggingServiceMock.createLogger(), diff --git a/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_externally_defined_collector.ts b/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_externally_defined_collector.ts index a6da392c615a28..2b3df1b391cd5d 100644 --- a/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_externally_defined_collector.ts +++ b/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_externally_defined_collector.ts @@ -22,7 +22,7 @@ import { ParsedUsageCollection } from '../ts_parser'; export const parsedExternallyDefinedCollector: ParsedUsageCollection[] = [ [ - 'src/dev/telemetry/__fixture__/externally_defined_collector.ts', + 'packages/kbn-telemetry-tools/src/tools/__fixture__/externally_defined_collector.ts', { collectorName: 'from_variable_collector', schema: { @@ -44,7 +44,7 @@ export const parsedExternallyDefinedCollector: ParsedUsageCollection[] = [ }, ], [ - 'src/dev/telemetry/__fixture__/externally_defined_collector.ts', + 'packages/kbn-telemetry-tools/src/tools/__fixture__/externally_defined_collector.ts', { collectorName: 'from_fn_collector', schema: { diff --git a/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_imported_schema.ts b/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_imported_schema.ts index a6bca756bb36f1..a57ae56e732ebc 100644 --- a/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_imported_schema.ts +++ b/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_imported_schema.ts @@ -22,7 +22,7 @@ import { ParsedUsageCollection } from '../ts_parser'; export const parsedImportedSchemaCollector: ParsedUsageCollection[] = [ [ - 'src/dev/telemetry/__fixture__/imported_schema.ts', + 'packages/kbn-telemetry-tools/src/tools/__fixture__/imported_schema.ts', { collectorName: 'with_imported_schema', schema: { diff --git a/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_imported_usage_interface.ts b/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_imported_usage_interface.ts index 3c72ad53b56ea1..69437aa90690a4 100644 --- a/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_imported_usage_interface.ts +++ b/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_imported_usage_interface.ts @@ -22,7 +22,7 @@ import { ParsedUsageCollection } from '../ts_parser'; export const parsedImportedUsageInterface: ParsedUsageCollection[] = [ [ - 'src/dev/telemetry/__fixture__/imported_usage_interface.ts', + 'packages/kbn-telemetry-tools/src/tools/__fixture__/imported_usage_interface.ts', { collectorName: 'imported_usage_interface_collector', schema: { diff --git a/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_nested_collector.ts b/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_nested_collector.ts index 94389981a2a258..a746c5dc485e95 100644 --- a/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_nested_collector.ts +++ b/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_nested_collector.ts @@ -21,7 +21,7 @@ import { SyntaxKind } from 'typescript'; import { ParsedUsageCollection } from '../ts_parser'; export const parsedNestedCollector: ParsedUsageCollection = [ - 'src/dev/telemetry/__fixture__/nested_collector.ts', + 'packages/kbn-telemetry-tools/src/tools/__fixture__/nested_collector.ts', { collectorName: 'my_nested_collector', schema: { diff --git a/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_working_collector.ts b/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_working_collector.ts index 5374999ffe5ec8..d338a7ca736ffa 100644 --- a/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_working_collector.ts +++ b/packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_working_collector.ts @@ -21,7 +21,7 @@ import { SyntaxKind } from 'typescript'; import { ParsedUsageCollection } from '../ts_parser'; export const parsedWorkingCollector: ParsedUsageCollection = [ - 'src/dev/telemetry/__fixture__/working_collector.ts', + 'packages/kbn-telemetry-tools/src/tools/__fixture__/working_collector.ts', { collectorName: 'my_working_collector', schema: { diff --git a/packages/kbn-telemetry-tools/src/tools/__fixture__/unmapped_collector.ts b/packages/kbn-telemetry-tools/src/tools/__fixture__/unmapped_collector.ts index fdca0cab427add..063e54a3b8a977 100644 --- a/packages/kbn-telemetry-tools/src/tools/__fixture__/unmapped_collector.ts +++ b/packages/kbn-telemetry-tools/src/tools/__fixture__/unmapped_collector.ts @@ -16,8 +16,8 @@ * specific language governing permissions and limitations * under the License. */ -import { CollectorSet } from '../../../../src/plugins/usage_collection/server/collector'; -import { loggingServiceMock } from '../../../../src/core/server/mocks'; +import { CollectorSet } from '../../../../../src/plugins/usage_collection/server/collector'; +import { loggingServiceMock } from '../../../../../src/core/server/mocks'; const { makeUsageCollector } = new CollectorSet({ logger: loggingServiceMock.createLogger(), diff --git a/packages/kbn-telemetry-tools/src/tools/__fixture__/working_collector.ts b/packages/kbn-telemetry-tools/src/tools/__fixture__/working_collector.ts index 6f5d8ee8f8fbf5..e401c076066783 100644 --- a/packages/kbn-telemetry-tools/src/tools/__fixture__/working_collector.ts +++ b/packages/kbn-telemetry-tools/src/tools/__fixture__/working_collector.ts @@ -16,8 +16,8 @@ * specific language governing permissions and limitations * under the License. */ -import { CollectorSet } from '../../../../src/plugins/usage_collection/server/collector'; -import { loggingServiceMock } from '../../../../src/core/server/mocks'; +import { CollectorSet } from '../../../../../src/plugins/usage_collection/server/collector'; +import { loggingServiceMock } from '../../../../../src/core/server/mocks'; const { makeUsageCollector } = new CollectorSet({ logger: loggingServiceMock.createLogger(), diff --git a/packages/kbn-telemetry-tools/src/tools/__snapshots__/extract_collectors.test.ts.snap b/packages/kbn-telemetry-tools/src/tools/__snapshots__/extract_collectors.test.ts.snap index 6d7a122590832b..28586db2e493db 100644 --- a/packages/kbn-telemetry-tools/src/tools/__snapshots__/extract_collectors.test.ts.snap +++ b/packages/kbn-telemetry-tools/src/tools/__snapshots__/extract_collectors.test.ts.snap @@ -3,7 +3,7 @@ exports[`extractCollectors extracts collectors given rc file 1`] = ` Array [ Array [ - "src/dev/telemetry/__fixture__/externally_defined_collector.ts", + "packages/kbn-telemetry-tools/src/tools/__fixture__/externally_defined_collector.ts", Object { "collectorName": "from_variable_collector", "fetch": Object { @@ -25,7 +25,7 @@ Array [ }, ], Array [ - "src/dev/telemetry/__fixture__/externally_defined_collector.ts", + "packages/kbn-telemetry-tools/src/tools/__fixture__/externally_defined_collector.ts", Object { "collectorName": "from_fn_collector", "fetch": Object { @@ -47,7 +47,7 @@ Array [ }, ], Array [ - "src/dev/telemetry/__fixture__/imported_schema.ts", + "packages/kbn-telemetry-tools/src/tools/__fixture__/imported_schema.ts", Object { "collectorName": "with_imported_schema", "fetch": Object { @@ -69,7 +69,7 @@ Array [ }, ], Array [ - "src/dev/telemetry/__fixture__/imported_usage_interface.ts", + "packages/kbn-telemetry-tools/src/tools/__fixture__/imported_usage_interface.ts", Object { "collectorName": "imported_usage_interface_collector", "fetch": Object { @@ -91,7 +91,7 @@ Array [ }, ], Array [ - "src/dev/telemetry/__fixture__/nested_collector.ts", + "packages/kbn-telemetry-tools/src/tools/__fixture__/nested_collector.ts", Object { "collectorName": "my_nested_collector", "fetch": Object { @@ -113,7 +113,7 @@ Array [ }, ], Array [ - "src/dev/telemetry/__fixture__/working_collector.ts", + "packages/kbn-telemetry-tools/src/tools/__fixture__/working_collector.ts", Object { "collectorName": "my_working_collector", "fetch": Object { diff --git a/packages/kbn-telemetry-tools/src/tools/__snapshots__/ts_parser.test.ts.snap b/packages/kbn-telemetry-tools/src/tools/__snapshots__/ts_parser.test.ts.snap index 07e682a746616c..025ae54ecd3acf 100644 --- a/packages/kbn-telemetry-tools/src/tools/__snapshots__/ts_parser.test.ts.snap +++ b/packages/kbn-telemetry-tools/src/tools/__snapshots__/ts_parser.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`parseUsageCollection throws when mapping fields is not defined 1`] = ` -"Error extracting collector in src/dev/telemetry/__fixture__/unmapped_collector.ts +"Error extracting collector in packages/kbn-telemetry-tools/src/tools/__fixture__/unmapped_collector.ts Error: usageCollector.schema must be defined." `; diff --git a/packages/kbn-telemetry-tools/src/tools/manage_schema.ts b/packages/kbn-telemetry-tools/src/tools/manage_schema.ts index 24d711a52db053..d4d7c85a31642e 100644 --- a/packages/kbn-telemetry-tools/src/tools/manage_schema.ts +++ b/packages/kbn-telemetry-tools/src/tools/manage_schema.ts @@ -18,7 +18,7 @@ */ import { ParsedUsageCollection } from './ts_parser'; -import { AllowedSchemaTypes } from '../../../src/plugins/usage_collection/server'; +import { AllowedSchemaTypes } from '../../../../src/plugins/usage_collection/server'; export function compatibleSchemaTypes(type: AllowedSchemaTypes) { switch (type) { diff --git a/scripts/telemetry_check.js b/scripts/telemetry_check.js index 8659f5d4e38a75..06b3ed46bdba6a 100644 --- a/scripts/telemetry_check.js +++ b/scripts/telemetry_check.js @@ -17,5 +17,5 @@ * under the License. */ -require('../src/setup_node_env'); +require('../src/setup_node_env/prebuilt_dev_only_entry'); require('@kbn/telemetry-tools').runTelemetryCheck(); diff --git a/scripts/telemetry_extract.js b/scripts/telemetry_extract.js index 1cb561701b0afa..051bee26537b9b 100644 --- a/scripts/telemetry_extract.js +++ b/scripts/telemetry_extract.js @@ -17,5 +17,5 @@ * under the License. */ -require('../src/setup_node_env'); +require('../src/setup_node_env/prebuilt_dev_only_entry'); require('@kbn/telemetry-tools').runTelemetryExtract(); diff --git a/src/plugins/usage_collection/README.md b/src/plugins/usage_collection/README.md index 69e823e1d4d292..9520dfc03cfa47 100644 --- a/src/plugins/usage_collection/README.md +++ b/src/plugins/usage_collection/README.md @@ -128,7 +128,7 @@ export function registerMyPluginUsageCollector( ## Schema Field -The `schema` field is a proscribed data model that eliminates maintenance of mappings in the telemetry cluster. Simply define a schema field that specifies every possible field reported by the collector. Whenever the `schema` field is set or changed. Please run `node scripts/telemetry_check.js --fix` to update the stored schema json files. +The `schema` field is a proscribed data model assists with detecting changes in usage collector payloads. To define the collector schema add a schema field that specifies every possible field reported when registering the collector. Whenever the `schema` field is set or changed please run `node scripts/telemetry_check.js --fix` to update the stored schema json files. ### Allowed Schema Types diff --git a/tasks/config/run.js b/tasks/config/run.js index 22deead1d380e5..32adf4f1f87c22 100644 --- a/tasks/config/run.js +++ b/tasks/config/run.js @@ -149,6 +149,12 @@ module.exports = function (grunt) { args: ['scripts/i18n_check', '--ignore-missing'], }), + telemetryCheck: scriptWithGithubChecks({ + title: 'Telemetry Schema check', + cmd: NODE, + args: ['scripts/telemetry_check'], + }), + // used by the test:quick task // runs all node.js/server mocha tests mocha: scriptWithGithubChecks({ diff --git a/tasks/jenkins.js b/tasks/jenkins.js index 4d92ff406a3253..b40bb8156098d3 100644 --- a/tasks/jenkins.js +++ b/tasks/jenkins.js @@ -27,6 +27,7 @@ module.exports = function (grunt) { 'run:checkDocApiChanges', 'run:typeCheck', 'run:i18nCheck', + 'run:telemetryCheck', 'run:checkFileCasing', 'run:checkLockfileSymlinks', 'run:licenses', diff --git a/x-pack/plugins/maps/server/maps_telemetry/collectors/register.ts b/x-pack/plugins/maps/server/maps_telemetry/collectors/register.ts index 36c0b28cdd69b0..f54776f5ab629f 100644 --- a/x-pack/plugins/maps/server/maps_telemetry/collectors/register.ts +++ b/x-pack/plugins/maps/server/maps_telemetry/collectors/register.ts @@ -17,7 +17,7 @@ export function registerMapsUsageCollector( } const mapsUsageCollector = usageCollection.makeUsageCollector({ - type: 'maps-telemetry', + type: 'maps', isReady: () => true, fetch: async () => await getMapsTelemetry(config), });