From dba4c6ec3da0adc482be06df5f98f3069fbc613b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Fern=C3=A1ndez=20Haro?= Date: Wed, 27 Nov 2024 18:18:09 +0100 Subject: [PATCH] [Sustainable Architecture] Telemetry schemas (#201760) ## Summary Since we are moving code around, the schema extractor now needs to adapt to the new directories. This PR adds new per-solution schemas to the `.telemetryrc.json` files and adapts FTRs accordingly. Related https://github.com/elastic/kibana/pull/201653 ### Checklist - [x] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios (cherry picked from commit dac87ef6fec2ff2291ea72ffe5ec00588265500a) --- .telemetryrc.json | 5 +++++ .../src/tools/extract_collectors.ts | 3 ++- src/plugins/telemetry/schema/README.md | 6 +++-- .../telemetry/schema/oss_platform.json | 3 +++ src/plugins/telemetry/tsconfig.json | 4 +--- x-pack/.telemetryrc.json | 20 +++++++++++++++++ .../schema/README.md | 8 +++++-- .../schema/xpack_observability.json | 3 +++ .../schema/xpack_platform.json | 3 +++ .../schema/xpack_search.json | 3 +++ .../schema/xpack_security.json | 3 +++ .../telemetry_collection_xpack/tsconfig.json | 4 +--- .../apis/telemetry/telemetry.ts | 22 ++++++++++++++----- .../apis/telemetry/telemetry_local.ts | 21 +++++++++++++----- .../common/telemetry/snapshot_telemetry.ts | 19 ++++++++++++---- 15 files changed, 102 insertions(+), 25 deletions(-) create mode 100644 src/plugins/telemetry/schema/oss_platform.json create mode 100644 x-pack/plugins/telemetry_collection_xpack/schema/xpack_observability.json create mode 100644 x-pack/plugins/telemetry_collection_xpack/schema/xpack_platform.json create mode 100644 x-pack/plugins/telemetry_collection_xpack/schema/xpack_search.json create mode 100644 x-pack/plugins/telemetry_collection_xpack/schema/xpack_security.json diff --git a/.telemetryrc.json b/.telemetryrc.json index 09c3051f81a01..2387ef73c88ec 100644 --- a/.telemetryrc.json +++ b/.telemetryrc.json @@ -10,5 +10,10 @@ "output": "src/plugins/telemetry/schema/kbn_packages.json", "root": "packages/", "exclude": [] + }, + { + "output": "src/plugins/telemetry/schema/oss_platform.json", + "root": "src/platform/", + "exclude": [] } ] diff --git a/packages/kbn-telemetry-tools/src/tools/extract_collectors.ts b/packages/kbn-telemetry-tools/src/tools/extract_collectors.ts index 8b0d5d864947c..19560795114a1 100644 --- a/packages/kbn-telemetry-tools/src/tools/extract_collectors.ts +++ b/packages/kbn-telemetry-tools/src/tools/extract_collectors.ts @@ -37,7 +37,8 @@ export async function getProgramPaths({ ); if (filePaths.length === 0) { - throw Error(`No files found in ${root}`); + return []; // Temporarily accept empty directories while https://github.com/elastic/kibana-team/issues/1066 is completed + // throw Error(`No files found in ${root}`); } const fullPaths = filePaths diff --git a/src/plugins/telemetry/schema/README.md b/src/plugins/telemetry/schema/README.md index fb02d5fc49af3..38212d73c2592 100644 --- a/src/plugins/telemetry/schema/README.md +++ b/src/plugins/telemetry/schema/README.md @@ -2,16 +2,18 @@ This list of `.json` files describes the format of the payloads sent to the Remote Telemetry Service. All the files should follow the schema convention as defined in the `usage_collection` plugin and `@kbn/telemetry-tools`, with the addition of the type `pass_through`. This additional `type` indicates Kibana sends the payload as-is from the output of an external ES query. -There are currently 2 files: +There are currently 4 files: - `oss_root.json`: Defines the schema for the payload from the root keys. Manually maintained for now because the frequency it changes should be pretty low. - `oss_plugins.json`: The schema for the content that will be nested in `stack_stats.kibana.plugins`. It is automatically generated by `@kbn/telemetry-tools` based on the `schema` property provided by all the registered Usage Collectors via the `usageCollection.makeUsageCollector` API. More details in the [Schema field](../../usage_collection/README.md#schema-field) chapter in the UsageCollection's docs. +- `kbn_packages.json`: Same as `oss_plugins` but for collectors defined in `/packages/*`. +- `oss_platform.json`: Same as `oss_plugins` but for collectors defined in `/src/platform/*`. NOTE: Despite its similarities to ES mappings, the intention of these files is not to define any index mappings. They should be considered as a tool to understand the format of the payload that will be sent when reporting telemetry to the Remote Service. ## Testing -Functional tests are defined at `test/api_integration/apis/telemetry/telemetry_local.ts`. They merge both files, and validates the actual output of the telemetry endpoint against the final schema. \ No newline at end of file +Functional tests are defined at `x-pack/test/api_integration/apis/telemetry/telemetry_local.ts`. They merge all files and [the x-pack counterparts](../../../../x-pack/plugins/telemetry_collection_xpack/schema), and validates the actual output of the telemetry endpoint against the final schema. \ No newline at end of file diff --git a/src/plugins/telemetry/schema/oss_platform.json b/src/plugins/telemetry/schema/oss_platform.json new file mode 100644 index 0000000000000..d5b0514b64918 --- /dev/null +++ b/src/plugins/telemetry/schema/oss_platform.json @@ -0,0 +1,3 @@ +{ + "properties": {} +} diff --git a/src/plugins/telemetry/tsconfig.json b/src/plugins/telemetry/tsconfig.json index a8538b4a0b18a..c23b4fea26b89 100644 --- a/src/plugins/telemetry/tsconfig.json +++ b/src/plugins/telemetry/tsconfig.json @@ -9,9 +9,7 @@ "server/**/**/*", "common/**/*", "../../../typings/**/*", - "schema/oss_plugins.json", - "schema/oss_root.json", - "schema/kbn_packages.json" + "schema/*.json", ], "kbn_references": [ "@kbn/core", diff --git a/x-pack/.telemetryrc.json b/x-pack/.telemetryrc.json index b0a8b45c02de9..51abf578ae5f5 100644 --- a/x-pack/.telemetryrc.json +++ b/x-pack/.telemetryrc.json @@ -10,5 +10,25 @@ "output": "plugins/telemetry_collection_xpack/schema/xpack_monitoring.json", "root": "plugins/monitoring/server/telemetry_collection/", "exclude": [] + }, + { + "output": "plugins/telemetry_collection_xpack/schema/xpack_platform.json", + "root": "platform/", + "exclude": [] + }, + { + "output": "plugins/telemetry_collection_xpack/schema/xpack_observability.json", + "root": "solutions/observability", + "exclude": [] + }, + { + "output": "plugins/telemetry_collection_xpack/schema/xpack_search.json", + "root": "solutions/search", + "exclude": [] + }, + { + "output": "plugins/telemetry_collection_xpack/schema/xpack_security.json", + "root": "solutions/security", + "exclude": [] } ] diff --git a/x-pack/plugins/telemetry_collection_xpack/schema/README.md b/x-pack/plugins/telemetry_collection_xpack/schema/README.md index 097cc6c57d88a..80040d1ec387b 100644 --- a/x-pack/plugins/telemetry_collection_xpack/schema/README.md +++ b/x-pack/plugins/telemetry_collection_xpack/schema/README.md @@ -2,17 +2,21 @@ This is an extension of the [OSS Telemetry Schemas](../../../../src/plugins/telemetry/schema) to add the X-Pack-related data. The payloads described in these `.json` files must be merged to the OSS ones to get the structure of the full payload sent to the Remote Telemetry Service. All the files follow the schema convention as defined in the `usage_collection` plugin and `@kbn/telemetry-tools`. -There are currently 2 files: +There are currently 7 files: - `xpack_root.json`: Defines the extra fields x-pack reports over the OSS payload defined in the `oss_root.json`. Manually maintained for now because the frequency it changes is expected to be pretty low. - `xpack_plugins.json`: The X-Pack related schema for the content that will be nested in `stack_stats.kibana.plugins`. It is automatically generated by `@kbn/telemetry-tools` based on the `schema` property provided by all the registered Usage Collectors via the `usageCollection.makeUsageCollector` API. More details in the [Schema field](../../usage_collection/README.md#schema-field) chapter in the UsageCollection's docs. +- `xpack_platform.json`: Same as `xpack_plugins.json` but for collectors defined in `/x-pack/platform/*`. +- `xpack_observability.json`: Same as `xpack_plugins.json` but for collectors defined in `/x-pack/solutions/observability/*`. +- `xpack_search.json`: Same as `xpack_plugins.json` but for collectors defined in `/x-pack/solutions/search/*`. +- `xpack_security.json`: Same as `xpack_plugins.json` but for collectors defined in `/x-pack/solutions/security/*`. - `xpack_monitoring.json`: It declares the payload sent by the monitoring-sourced telemetry. The actual schema for the payload is declared under `properties.monitoringTelemetry.properties.stats.items`, but due to the general behaviour in the `@kbn/telemetry-tools`, it gets nested down in that path. NOTE: Despite its similarities to ES mappings, the intention of these files is not to define any index mappings. They should be considered as a tool to understand the format of the payload that will be sent when reporting telemetry to the Remote Service. ## Testing -Functional tests are defined at `x-pack/test/api_integration/apis/telemetry/telemetry_local.ts`. They merge both files (+ the OSS definitions), and validates the actual output of the telemetry endpoint against the final schema. \ No newline at end of file +Functional tests are defined at `x-pack/test/api_integration/apis/telemetry/telemetry_local.ts`. They merge these files (+ the [OSS definitions](../../../../src/plugins/telemetry/schema)), and validates the actual output of the telemetry endpoint against the final schema. \ No newline at end of file diff --git a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_observability.json b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_observability.json new file mode 100644 index 0000000000000..d5b0514b64918 --- /dev/null +++ b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_observability.json @@ -0,0 +1,3 @@ +{ + "properties": {} +} diff --git a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_platform.json b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_platform.json new file mode 100644 index 0000000000000..d5b0514b64918 --- /dev/null +++ b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_platform.json @@ -0,0 +1,3 @@ +{ + "properties": {} +} diff --git a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_search.json b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_search.json new file mode 100644 index 0000000000000..d5b0514b64918 --- /dev/null +++ b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_search.json @@ -0,0 +1,3 @@ +{ + "properties": {} +} diff --git a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_security.json b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_security.json new file mode 100644 index 0000000000000..d5b0514b64918 --- /dev/null +++ b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_security.json @@ -0,0 +1,3 @@ +{ + "properties": {} +} diff --git a/x-pack/plugins/telemetry_collection_xpack/tsconfig.json b/x-pack/plugins/telemetry_collection_xpack/tsconfig.json index 5ea98b7ecfb1a..740f21400b2ab 100644 --- a/x-pack/plugins/telemetry_collection_xpack/tsconfig.json +++ b/x-pack/plugins/telemetry_collection_xpack/tsconfig.json @@ -8,9 +8,7 @@ "common/**/*", "server/**/*", "../../../typings/*", - "schema/xpack_monitoring.json", - "schema/xpack_plugins.json", - "schema/xpack_root.json", + "schema/*.json", ], "kbn_references": [ "@kbn/core", diff --git a/x-pack/test/api_integration/apis/telemetry/telemetry.ts b/x-pack/test/api_integration/apis/telemetry/telemetry.ts index 5e034ce3a1847..6159770e253de 100644 --- a/x-pack/test/api_integration/apis/telemetry/telemetry.ts +++ b/x-pack/test/api_integration/apis/telemetry/telemetry.ts @@ -14,8 +14,13 @@ import ossRootTelemetrySchema from '@kbn/telemetry-plugin/schema/oss_root.json'; import xpackRootTelemetrySchema from '@kbn/telemetry-collection-xpack-plugin/schema/xpack_root.json'; import monitoringRootTelemetrySchema from '@kbn/telemetry-collection-xpack-plugin/schema/xpack_monitoring.json'; import ossPluginsTelemetrySchema from '@kbn/telemetry-plugin/schema/oss_plugins.json'; +import ossPlatformTelemetrySchema from '@kbn/telemetry-plugin/schema/oss_platform.json'; import ossPackagesTelemetrySchema from '@kbn/telemetry-plugin/schema/kbn_packages.json'; import xpackPluginsTelemetrySchema from '@kbn/telemetry-collection-xpack-plugin/schema/xpack_plugins.json'; +import xpackPlatformTelemetrySchema from '@kbn/telemetry-collection-xpack-plugin/schema/xpack_platform.json'; +import xpackObservabilityTelemetrySchema from '@kbn/telemetry-collection-xpack-plugin/schema/xpack_observability.json'; +import xpackSearchTelemetrySchema from '@kbn/telemetry-collection-xpack-plugin/schema/xpack_search.json'; +import xpackSecurityTelemetrySchema from '@kbn/telemetry-collection-xpack-plugin/schema/xpack_security.json'; import type { UnencryptedTelemetryPayload } from '@kbn/telemetry-plugin/common/types'; import type { UsageStatsPayload, @@ -161,10 +166,17 @@ export default function ({ getService }: FtrProviderContext) { // It's nested because of the way it's collected and declared monitoringRootTelemetrySchema.properties.monitoringTelemetry.properties.stats.items ); - const plugins = deepmerge( - deepmerge(ossPluginsTelemetrySchema, ossPackagesTelemetrySchema), - xpackPluginsTelemetrySchema - ); + + const plugins = [ + ossPluginsTelemetrySchema, + ossPackagesTelemetrySchema, + ossPlatformTelemetrySchema, + xpackPluginsTelemetrySchema, + xpackPlatformTelemetrySchema, + xpackObservabilityTelemetrySchema, + xpackSearchTelemetrySchema, + xpackSecurityTelemetrySchema, + ].reduce((acc, schema) => deepmerge(acc, schema)); try { assertTelemetryPayload({ root, plugins }, localXPack); @@ -172,7 +184,7 @@ export default function ({ getService }: FtrProviderContext) { assertTelemetryPayload({ root: monitoringRoot, plugins }, stats); }); } catch (err) { - err.message = `The telemetry schemas in 'x-pack/plugins/telemetry_collection_xpack/schema/' are out-of-date, please update it as required: ${err.message}`; + err.message = `The telemetry schemas in are out-of-date. Please define the schema of your collector and run "node scripts/telemetry_check --fix" to update them: ${err.message}`; throw err; } }); diff --git a/x-pack/test/api_integration/apis/telemetry/telemetry_local.ts b/x-pack/test/api_integration/apis/telemetry/telemetry_local.ts index d155bfb614cbf..3201556bd18f3 100644 --- a/x-pack/test/api_integration/apis/telemetry/telemetry_local.ts +++ b/x-pack/test/api_integration/apis/telemetry/telemetry_local.ts @@ -9,9 +9,14 @@ import expect from '@kbn/expect'; import deepmerge from 'deepmerge'; import ossRootTelemetrySchema from '@kbn/telemetry-plugin/schema/oss_root.json'; import ossPluginsTelemetrySchema from '@kbn/telemetry-plugin/schema/oss_plugins.json'; +import ossPlatformTelemetrySchema from '@kbn/telemetry-plugin/schema/oss_platform.json'; import ossPackagesTelemetrySchema from '@kbn/telemetry-plugin/schema/kbn_packages.json'; import xpackRootTelemetrySchema from '@kbn/telemetry-collection-xpack-plugin/schema/xpack_root.json'; import xpackPluginsTelemetrySchema from '@kbn/telemetry-collection-xpack-plugin/schema/xpack_plugins.json'; +import xpackPlatformTelemetrySchema from '@kbn/telemetry-collection-xpack-plugin/schema/xpack_platform.json'; +import xpackObservabilityTelemetrySchema from '@kbn/telemetry-collection-xpack-plugin/schema/xpack_observability.json'; +import xpackSearchTelemetrySchema from '@kbn/telemetry-collection-xpack-plugin/schema/xpack_search.json'; +import xpackSecurityTelemetrySchema from '@kbn/telemetry-collection-xpack-plugin/schema/xpack_security.json'; import { assertTelemetryPayload } from '@kbn/telemetry-tools'; import { ELASTIC_HTTP_VERSION_HEADER, @@ -57,15 +62,21 @@ export default function ({ getService }: FtrProviderContext) { it('should pass the schema validation', () => { const root = deepmerge(ossRootTelemetrySchema, xpackRootTelemetrySchema); - const plugins = deepmerge( - deepmerge(ossPluginsTelemetrySchema, ossPackagesTelemetrySchema), - xpackPluginsTelemetrySchema - ); + const plugins = [ + ossPluginsTelemetrySchema, + ossPackagesTelemetrySchema, + ossPlatformTelemetrySchema, + xpackPluginsTelemetrySchema, + xpackPlatformTelemetrySchema, + xpackObservabilityTelemetrySchema, + xpackSearchTelemetrySchema, + xpackSecurityTelemetrySchema, + ].reduce((acc, schema) => deepmerge(acc, schema)); try { assertTelemetryPayload({ root, plugins }, stats); } catch (err) { - err.message = `The telemetry schemas in 'x-pack/plugins/telemetry_collection_xpack/schema/' are out-of-date, please update it as required: ${err.message}`; + err.message = `The telemetry schemas in are out-of-date. Please define the schema of your collector and run "node scripts/telemetry_check --fix" to update them: ${err.message}`; throw err; } }); diff --git a/x-pack/test_serverless/api_integration/test_suites/common/telemetry/snapshot_telemetry.ts b/x-pack/test_serverless/api_integration/test_suites/common/telemetry/snapshot_telemetry.ts index b3d7f812de3e8..fa3ff28fa2f13 100644 --- a/x-pack/test_serverless/api_integration/test_suites/common/telemetry/snapshot_telemetry.ts +++ b/x-pack/test_serverless/api_integration/test_suites/common/telemetry/snapshot_telemetry.ts @@ -11,7 +11,12 @@ import ossRootTelemetrySchema from '@kbn/telemetry-plugin/schema/oss_root.json'; import xpackRootTelemetrySchema from '@kbn/telemetry-collection-xpack-plugin/schema/xpack_root.json'; import ossPluginsTelemetrySchema from '@kbn/telemetry-plugin/schema/oss_plugins.json'; import ossPackagesTelemetrySchema from '@kbn/telemetry-plugin/schema/kbn_packages.json'; +import ossPlatformTelemetrySchema from '@kbn/telemetry-plugin/schema/oss_platform.json'; import xpackPluginsTelemetrySchema from '@kbn/telemetry-collection-xpack-plugin/schema/xpack_plugins.json'; +import xpackPlatformTelemetrySchema from '@kbn/telemetry-collection-xpack-plugin/schema/xpack_platform.json'; +import xpackObservabilityTelemetrySchema from '@kbn/telemetry-collection-xpack-plugin/schema/xpack_observability.json'; +import xpackSearchTelemetrySchema from '@kbn/telemetry-collection-xpack-plugin/schema/xpack_search.json'; +import xpackSecurityTelemetrySchema from '@kbn/telemetry-collection-xpack-plugin/schema/xpack_security.json'; import { assertTelemetryPayload } from '@kbn/telemetry-tools'; import type { UsageStatsPayloadTestFriendly } from '@kbn/test-suites-xpack/api_integration/services/usage_api'; import type { RoleCredentials } from '../../../../shared/services'; @@ -42,10 +47,16 @@ export default function ({ getService }: FtrProviderContext) { it('should pass the schema validation (ensures BWC with Classic offering)', () => { const root = deepmerge(ossRootTelemetrySchema, xpackRootTelemetrySchema); - const plugins = deepmerge( - deepmerge(ossPluginsTelemetrySchema, ossPackagesTelemetrySchema), - xpackPluginsTelemetrySchema - ); + const plugins = [ + ossPluginsTelemetrySchema, + ossPackagesTelemetrySchema, + ossPlatformTelemetrySchema, + xpackPluginsTelemetrySchema, + xpackPlatformTelemetrySchema, + xpackObservabilityTelemetrySchema, + xpackSearchTelemetrySchema, + xpackSecurityTelemetrySchema, + ].reduce((acc, schema) => deepmerge(acc, schema)); try { assertTelemetryPayload({ root, plugins }, stats);