Skip to content

Commit

Permalink
add CI job and complete code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Bamieh committed Jun 24, 2020
1 parent f1f4146 commit 3c360f0
Show file tree
Hide file tree
Showing 23 changed files with 47 additions and 40 deletions.
10 changes: 5 additions & 5 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -27,7 +27,7 @@ export const myCollector = makeUsageCollector<Usage>({
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
Expand Down Expand Up @@ -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:

Expand All @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

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

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

2 changes: 1 addition & 1 deletion packages/kbn-telemetry-tools/src/tools/manage_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/telemetry_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
2 changes: 1 addition & 1 deletion scripts/telemetry_extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
2 changes: 1 addition & 1 deletion src/plugins/usage_collection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions tasks/config/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions tasks/jenkins.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = function (grunt) {
'run:checkDocApiChanges',
'run:typeCheck',
'run:i18nCheck',
'run:telemetryCheck',
'run:checkFileCasing',
'run:checkLockfileSymlinks',
'run:licenses',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function registerMapsUsageCollector(
}

const mapsUsageCollector = usageCollection.makeUsageCollector({
type: 'maps-telemetry',
type: 'maps',
isReady: () => true,
fetch: async () => await getMapsTelemetry(config),
});
Expand Down

0 comments on commit 3c360f0

Please sign in to comment.