Skip to content

Commit ec7578c

Browse files
authored
[Telemetry] schema check throw on missing schema (#75750)
1 parent 2620882 commit ec7578c

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

packages/kbn-telemetry-tools/src/cli/run_telemetry_check.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ export function runTelemetryCheck() {
6565
},
6666
{
6767
title: 'Checking Matching collector.schema against stored json files',
68-
task: (context) => new Listr(checkMatchingSchemasTask(context), { exitOnError: true }),
68+
task: (context) =>
69+
new Listr(checkMatchingSchemasTask(context, !fix), { exitOnError: true }),
6970
},
7071
{
7172
enabled: (_) => fix,

packages/kbn-telemetry-tools/src/tools/tasks/check_matching_schemas_task.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { TaskContext } from './task_context';
2222
import { checkMatchingMapping } from '../check_collector_integrity';
2323
import { readFileAsync } from '../utils';
2424

25-
export function checkMatchingSchemasTask({ roots }: TaskContext) {
25+
export function checkMatchingSchemasTask({ roots }: TaskContext, throwOnDiff: boolean) {
2626
return roots.map((root) => ({
2727
task: async () => {
2828
const fullPath = path.resolve(process.cwd(), root.config.output);
@@ -31,8 +31,16 @@ export function checkMatchingSchemasTask({ roots }: TaskContext) {
3131

3232
if (root.parsedCollections) {
3333
const differences = checkMatchingMapping(root.parsedCollections, esMapping);
34-
3534
root.esMappingDiffs = Object.keys(differences);
35+
if (root.esMappingDiffs.length && throwOnDiff) {
36+
throw Error(
37+
`The following changes must be persisted in ${fullPath} file. Use '--fix' to update.\n${JSON.stringify(
38+
differences,
39+
null,
40+
2
41+
)}`
42+
);
43+
}
3644
}
3745
},
3846
title: `Checking in ${root.config.root}`,

src/plugins/telemetry/schema/oss_plugins.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@
4848
}
4949
}
5050
},
51+
"csp": {
52+
"properties": {
53+
"strict": {
54+
"type": "boolean"
55+
},
56+
"warnLegacyBrowsers": {
57+
"type": "boolean"
58+
},
59+
"rulesChangedFromDefault": {
60+
"type": "boolean"
61+
}
62+
}
63+
},
5164
"telemetry": {
5265
"properties": {
5366
"opt_in_status": {

0 commit comments

Comments
 (0)