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

[Telemetry] Collector Schema #64942

Merged
merged 38 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
86563ce
first working draft
Bamieh Apr 30, 2020
e80f27f
Merge branch 'master' of github.com:elastic/kibana into telemetry/aut…
Bamieh Apr 30, 2020
a870296
first working draft
Bamieh Apr 30, 2020
80b3257
add more test scenarios
Bamieh May 4, 2020
adb1bea
Merge branch 'master' of github.com:elastic/kibana into telemetry/aut…
Bamieh May 4, 2020
9f68343
Merge branch 'master' of github.com:elastic/kibana into telemetry/aut…
Bamieh May 6, 2020
b4dfeb8
Merge branch 'master' of github.com:elastic/kibana into telemetry/aut…
Bamieh May 11, 2020
babf185
Merge branch 'master' of github.com:elastic/kibana into telemetry/aut…
Bamieh May 17, 2020
1dbee95
Merge branch 'master' of github.com:elastic/kibana into telemetry/aut…
Bamieh May 23, 2020
16ed263
finalize initial implementation
Bamieh May 26, 2020
e580992
Merge branch 'master' of github.com:elastic/kibana into telemetry/aut…
Bamieh May 26, 2020
c452ab4
running typechecker
Bamieh May 26, 2020
ddc5f12
add telemetry cli checker - phase 1
Bamieh May 26, 2020
fa81c2a
Merge branch 'master' of github.com:elastic/kibana into telemetry/aut…
Bamieh May 27, 2020
a3fad35
xpack .telemetryrc file
Bamieh Jun 1, 2020
e2795af
Merge branch 'master' of github.com:elastic/kibana into telemetry/aut…
Bamieh Jun 1, 2020
1c3e112
code review changes
Bamieh Jun 12, 2020
34444f2
Merge branch 'master' of github.com:elastic/kibana into telemetry/aut…
Bamieh Jun 12, 2020
a924d65
Merge branch 'master' of github.com:elastic/kibana into telemetry/aut…
Bamieh Jun 12, 2020
526d132
reporting usage
Bamieh Jun 14, 2020
b5c50d7
Merge branch 'master' of github.com:elastic/kibana into telemetry/aut…
Bamieh Jun 14, 2020
b95a431
ready for review
Bamieh Jun 15, 2020
0e879d6
Merge branch 'master' of github.com:elastic/kibana into telemetry/aut…
Bamieh Jun 15, 2020
fd2086e
self code review
Bamieh Jun 15, 2020
23d087a
fix typecheck
Bamieh Jun 15, 2020
f957e67
fix some more schemas
Bamieh Jun 15, 2020
902f5ff
Merge branch 'master' of github.com:elastic/kibana into telemetry/aut…
Bamieh Jun 15, 2020
e04a074
move into a pacakge
Bamieh Jun 18, 2020
71dc5b1
merge master
Bamieh Jun 18, 2020
9afad1a
Merge branch 'master' into telemetry/automate_mapping
elasticmachine Jun 18, 2020
f1f4146
Merge branch 'master' of github.com:elastic/kibana into telemetry/aut…
Bamieh Jun 24, 2020
3c360f0
add CI job and complete code review suggestions
Bamieh Jun 24, 2020
3ecf97e
fix typecheck
Bamieh Jun 24, 2020
bf590ee
fix package tests
Bamieh Jun 24, 2020
32664b9
Merge branch 'master' of github.com:elastic/kibana into telemetry/aut…
Bamieh Jun 24, 2020
1fd4625
revert to maps-telemetry
Bamieh Jun 25, 2020
f5bd5f1
Merge branch 'master' of github.com:elastic/kibana into telemetry/aut…
Bamieh Jun 25, 2020
bac4718
revert to maps
Bamieh Jun 25, 2020
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
25 changes: 25 additions & 0 deletions .telemetryrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[
{
"output": "src/plugins/telemetry/mappings/legacy_oss_plugins.json",
"root": "src/legacy/core_plugins/",
"exclude": [
"src/legacy/core_plugins/testbed",
"src/legacy/core_plugins/elasticsearch",
"src/legacy/core_plugins/tests_bundle"
]
},
{
"output": "src/plugins/telemetry/mappings/oss_plugins.json",
"root": "src/plugins/",
"exclude": [
"src/plugins/kibana_react/",
"src/plugins/testbed/",
"src/plugins/kibana_utils/",
"src/plugins/kibana_usage_collection/server/collectors/kibana/kibana_usage_collector.ts",
"src/plugins/kibana_usage_collection/server/collectors/application_usage/telemetry_application_usage_collector.ts",
"src/plugins/kibana_usage_collection/server/collectors/management/telemetry_management_collector.ts",
"src/plugins/kibana_usage_collection/server/collectors/ui_metric/telemetry_ui_metric_collector.ts",
"src/plugins/telemetry/server/collectors/usage/telemetry_usage_collector.ts"
Bamieh marked this conversation as resolved.
Show resolved Hide resolved
]
}
]
21 changes: 21 additions & 0 deletions scripts/telemetry_check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

require('../src/setup_node_env');
Bamieh marked this conversation as resolved.
Show resolved Hide resolved
require('../src/dev/run_telemetry_check');
21 changes: 21 additions & 0 deletions scripts/telemetry_extract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

require('../src/setup_node_env');
require('../src/dev/run_telemetry_extract');
93 changes: 93 additions & 0 deletions src/dev/run_telemetry_check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import Listr from 'listr';
import chalk from 'chalk';
import { createFailError, run } from '@kbn/dev-utils';

import {
createTaskContext,
ErrorReporter,
parseConfigsTask,
extractCollectorsTask,
checkMatchingMappingTask,
generateMappingsTask,
checkCompatibleTypesTask,
writeToFileTask,
TaskContext,
} from './telemetry/tasks';

run(
async ({ flags: { fix = false }, log }) => {
if (typeof fix !== 'boolean') {
throw createFailError(`${chalk.white.bgRed(' TELEMETRY ERROR ')} --fix can't have a value`);
}

const list = new Listr([
{
title: 'Checking .telemetryrc.json files',
task: () => new Listr(parseConfigsTask(), { exitOnError: true }),
},
{
title: 'Extracting Collectors',
task: (context) => new Listr(extractCollectorsTask(context), { exitOnError: true }),
},
{
title: 'Checking Compatible collector.mapping with collector.fetch type',
task: (context) => new Listr(checkCompatibleTypesTask(context), { exitOnError: true }),
},
{
title: 'Checking Matching collector.mapping with mapped json file',
task: (context) => new Listr(checkMatchingMappingTask(context), { exitOnError: true }),
},
{
skip: ({ roots }: TaskContext) =>
!fix && roots.every((root) => !root.esMappingDiffs || !root.esMappingDiffs.length),
title: 'Generating new telemetry mappings',
task: (context) => new Listr(generateMappingsTask(context), { exitOnError: true }),
},
{
skip: ({ roots }: TaskContext) =>
!fix && roots.every((root) => !root.esMappingDiffs || !root.esMappingDiffs.length),
title: 'Updating telemetry mapping files',
task: (context) => new Listr(writeToFileTask(context), { exitOnError: true }),
},
]);

try {
const context = createTaskContext();
await list.run(context);
} catch (error) {
process.exitCode = 1;
if (error instanceof ErrorReporter) {
error.errors.forEach((e: string | Error) => log.error(e));
} else {
log.error('Unhandled exception!');
log.error(error);
}
}
process.exit();
},
{
flags: {
allowUnexpected: true,
guessTypesForUnexpectedFlags: true,
},
}
);
73 changes: 73 additions & 0 deletions src/dev/run_telemetry_extract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import Listr from 'listr';
import { run } from '@kbn/dev-utils';

import {
createTaskContext,
ErrorReporter,
parseConfigsTask,
extractCollectorsTask,
generateMappingsTask,
writeToFileTask,
} from './telemetry/tasks';

run(
async ({ flags: {}, log }) => {
const list = new Listr([
{
title: 'Parsing .telemetryrc.json files',
task: () => new Listr(parseConfigsTask(), { exitOnError: true }),
},
{
title: 'Extracting Telemetry Collectors',
task: (context) => new Listr(extractCollectorsTask(context), { exitOnError: true }),
},
{
title: 'Generating Mapping files',
task: (context) => new Listr(generateMappingsTask(context), { exitOnError: true }),
},
{
title: 'Writing to file',
task: (context) => new Listr(writeToFileTask(context), { exitOnError: true }),
},
]);

try {
const context = createTaskContext();
await list.run(context);
} catch (error) {
process.exitCode = 1;
if (error instanceof ErrorReporter) {
error.errors.forEach((e: string | Error) => log.error(e));
} else {
log.error('Unhandled exception');
log.error(error);
}
}
process.exit();
},
{
flags: {
allowUnexpected: true,
guessTypesForUnexpectedFlags: true,
},
}
);
7 changes: 7 additions & 0 deletions src/dev/telemetry/__fixture__/.telemetryrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"root": ".",
"output": ".",
"exclude": [
"./unmapped_collector.ts"
]
}
44 changes: 44 additions & 0 deletions src/dev/telemetry/__fixture__/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import moment, { Moment } from 'moment';

export interface Usage {
locale: string;
}

export interface WithUnion {
prop1: string | null;
prop2: string | null | undefined;
prop3?: string | null;
prop4: 'opt1' | 'opt2';
prop5: 123 | 431;
}

export interface WithMoment {
prop1: Moment;
prop2: moment.Moment;
}

export interface WithConflictingUnion {
prop1: 123 | 'str';
}

export interface WithUnsupportedUnion {
prop1: 123 | Moment;
}
71 changes: 71 additions & 0 deletions src/dev/telemetry/__fixture__/externally_defined_collector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { CollectorSet, CollectorOptions } from '../../../plugins/usage_collection/server/collector';
import { loggingServiceMock } from '../../../core/server/mocks';

const collectorSet = new CollectorSet({
logger: loggingServiceMock.createLogger(),
maximumWaitTimeForAllCollectorsInS: 0,
});

interface Usage {
locale: string;
}

function createCollector(): CollectorOptions<Usage> {
return {
type: 'from_fn_collector',
isReady: () => true,
fetch(): Usage {
return {
locale: 'en',
};
},
mapping: {
locale: {
type: 'keyword',
},
},
};
}

export function defineCollectorFromVariable() {
const fromVarCollector: CollectorOptions<Usage> = {
type: 'from_variable_collector',
isReady: () => true,
fetch(): Usage {
return {
locale: 'en',
};
},
mapping: {
locale: {
type: 'keyword',
},
},
};

collectorSet.makeUsageCollector<Usage>(fromVarCollector);
}

export function defineCollectorFromFn() {
const fromFnCollector = createCollector();

collectorSet.makeUsageCollector<Usage>(fromFnCollector);
}
20 changes: 20 additions & 0 deletions src/dev/telemetry/__fixture__/file_with_no_collector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export const SOME_CONST: number = 123;
Loading