Skip to content

Commit a844cc3

Browse files
Merge branch 'master' into enable-explore-data-for-lens
2 parents 54f84b5 + 64e87cd commit a844cc3

File tree

546 files changed

+18106
-5476
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

546 files changed

+18106
-5476
lines changed

.github/CODEOWNERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,19 @@
170170

171171
# Kibana Telemetry
172172
/packages/kbn-analytics/ @elastic/kibana-telemetry
173+
/packages/kbn-telemetry-tools/ @elastic/kibana-telemetry
173174
/src/plugins/kibana_usage_collection/ @elastic/kibana-telemetry
174175
/src/plugins/newsfeed/ @elastic/kibana-telemetry
175176
/src/plugins/telemetry/ @elastic/kibana-telemetry
176177
/src/plugins/telemetry_collection_manager/ @elastic/kibana-telemetry
177178
/src/plugins/telemetry_management_section/ @elastic/kibana-telemetry
178179
/src/plugins/usage_collection/ @elastic/kibana-telemetry
179180
/x-pack/plugins/telemetry_collection_xpack/ @elastic/kibana-telemetry
181+
/.telemetryrc.json @elastic/kibana-telemetry
182+
/x-pack/.telemetryrc.json @elastic/kibana-telemetry
183+
src/plugins/telemetry/schema/legacy_oss_plugins.json @elastic/kibana-telemetry
184+
src/plugins/telemetry/schema/oss_plugins.json @elastic/kibana-telemetry
185+
x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @elastic/kibana-telemetry
180186

181187
# Kibana Alerting Services
182188
/x-pack/plugins/alerts/ @elastic/kibana-alerting-services

.telemetryrc.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[
2+
{
3+
"output": "src/plugins/telemetry/schema/legacy_oss_plugins.json",
4+
"root": "src/legacy/core_plugins/",
5+
"exclude": [
6+
"src/legacy/core_plugins/testbed",
7+
"src/legacy/core_plugins/elasticsearch",
8+
"src/legacy/core_plugins/tests_bundle"
9+
]
10+
},
11+
{
12+
"output": "src/plugins/telemetry/schema/oss_plugins.json",
13+
"root": "src/plugins/",
14+
"exclude": [
15+
"src/plugins/kibana_react/",
16+
"src/plugins/testbed/",
17+
"src/plugins/kibana_utils/",
18+
"src/plugins/kibana_usage_collection/server/collectors/kibana/kibana_usage_collector.ts",
19+
"src/plugins/kibana_usage_collection/server/collectors/application_usage/telemetry_application_usage_collector.ts",
20+
"src/plugins/kibana_usage_collection/server/collectors/management/telemetry_management_collector.ts",
21+
"src/plugins/kibana_usage_collection/server/collectors/ui_metric/telemetry_ui_metric_collector.ts",
22+
"src/plugins/telemetry/server/collectors/usage/telemetry_usage_collector.ts"
23+
]
24+
}
25+
]

docs/development/core/public/kibana-plugin-core-public.publicappinfo.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ Public information about a registered [application](./kibana-plugin-core-public.
1111
```typescript
1212
export declare type PublicAppInfo = Omit<App, 'mount' | 'updater$'> & {
1313
legacy: false;
14+
status: AppStatus;
15+
navLinkStatus: AppNavLinkStatus;
16+
appRoute: string;
1417
};
1518
```

docs/development/core/public/kibana-plugin-core-public.publiclegacyappinfo.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ Information about a registered [legacy application](./kibana-plugin-core-public.
1111
```typescript
1212
export declare type PublicLegacyAppInfo = Omit<LegacyApp, 'updater$'> & {
1313
legacy: true;
14+
status: AppStatus;
15+
navLinkStatus: AppNavLinkStatus;
1416
};
1517
```

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
"@kbn/babel-preset": "1.0.0",
140140
"@kbn/config-schema": "1.0.0",
141141
"@kbn/i18n": "1.0.0",
142+
"@kbn/telemetry-tools": "1.0.0",
142143
"@kbn/interpreter": "1.0.0",
143144
"@kbn/pm": "1.0.0",
144145
"@kbn/test-subj-selector": "0.2.1",
@@ -201,6 +202,7 @@
201202
"inline-style": "^2.0.0",
202203
"joi": "^13.5.2",
203204
"jquery": "^3.5.0",
205+
"js-levenshtein": "^1.1.6",
204206
"js-yaml": "3.13.1",
205207
"json-stable-stringify": "^1.0.1",
206208
"json-stringify-pretty-compact": "1.2.0",

packages/kbn-monaco/src/xjson/grammar.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,13 @@ export const createParser = () => {
200200

201201
try {
202202
value();
203+
white();
203204
} catch (e) {
204205
errored = true;
205206
annos.push({ type: AnnoTypes.error, at: e.at - 1, text: e.message });
206207
}
207208
if (!errored && ch) {
208-
error('Syntax error');
209+
annos.push({ type: AnnoTypes.error, at: at, text: 'Syntax Error' });
209210
}
210211
return { annotations: annos };
211212
}

packages/kbn-monaco/src/xjson/language.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ export const registerGrammarChecker = (editor: monaco.editor.IEditor) => {
5252

5353
const updateAnnos = async () => {
5454
const { annotations } = await wps.getAnnos();
55-
const model = editor.getModel() as monaco.editor.ITextModel;
55+
const model = editor.getModel() as monaco.editor.ITextModel | null;
56+
if (!model) {
57+
return;
58+
}
5659
monaco.editor.setModelMarkers(
5760
model,
5861
OWNER,
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Telemetry Tools
2+
3+
## Schema extraction tool
4+
5+
### Description
6+
7+
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.
8+
9+
It uses typescript parser to build an AST for each file. The tool is able to validate, extract and match collector schemas.
10+
11+
### Examples and restrictions
12+
13+
**Global restrictions**:
14+
15+
The `id` can be only a string literal, it cannot be a template literals w/o expressions or string-only concatenation expressions or anything else.
16+
17+
```
18+
export const myCollector = makeUsageCollector<Usage>({
19+
type: 'string_literal_only',
20+
...
21+
});
22+
```
23+
24+
### Usage
25+
26+
```bash
27+
node scripts/telemetry_extract.js
28+
```
29+
30+
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.
31+
32+
33+
### Output
34+
35+
36+
The generated JSON files contain an ES mapping for each schema. This mapping is used to verify changes in the collectors and as the basis to map those fields into the external telemetry cluster.
37+
38+
**Example**:
39+
40+
```json
41+
{
42+
"properties": {
43+
"cloud": {
44+
"properties": {
45+
"isCloudEnabled": {
46+
"type": "boolean"
47+
}
48+
}
49+
}
50+
}
51+
}
52+
```
53+
54+
## Schema validation tool
55+
56+
### Description
57+
58+
The tool performs a number of checks on all telemetry collectors and verifies the following:
59+
60+
1. Verifies the collector structure, fields, and returned values are using the appropriate types.
61+
2. Verifies that the collector `fetch` function Type matches the specified `schema` in the collector.
62+
3. Verifies that the collector `schema` matches the stored json schema .
63+
64+
### Notes
65+
66+
We don't catch every possible misuse of the collectors, but only the most common and critical ones.
67+
68+
What will not be caught by the validator:
69+
70+
* Mistyped SavedObject/CallCluster return value. Since the hits returned from ES can be typed to anything without any checks. It is advised to add functional tests that grabs the schema json file and checks that the returned usage matches the types exactly.
71+
72+
* 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.
73+
74+
The tool looks for `.telemetryrc.json` files in the root of the project and in the `x-pack` dir for its runtime configurations.
75+
76+
Currently auto-fixer (`--fix`) can automatically fix the json files with the following errors:
77+
78+
* incompatible schema - this error means that the collector schema was changed but the stored json schema file was not updated.
79+
80+
* unused schemas - this error means that a collector was removed or its `type` renamed, the json schema file contains a schema that does not have a corrisponding collector.
81+
82+
### Usage
83+
84+
```bash
85+
node scripts/telemetry_check --fix
86+
```
87+
88+
* `--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.
89+
* `--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.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
module.exports = {
21+
presets: ['@kbn/babel-preset/node_preset'],
22+
ignore: ['**/*.test.ts', '**/__fixture__/**'],
23+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "@kbn/telemetry-tools",
3+
"version": "1.0.0",
4+
"license": "Apache-2.0",
5+
"main": "./target/index.js",
6+
"private": true,
7+
"scripts": {
8+
"build": "babel src --out-dir target --delete-dir-on-start --extensions .ts --source-maps=inline",
9+
"kbn:bootstrap": "yarn build",
10+
"kbn:watch": "yarn build --watch"
11+
},
12+
"devDependencies": {
13+
"lodash": "npm:@elastic/lodash@3.10.1-kibana4",
14+
"@kbn/dev-utils": "1.0.0",
15+
"@kbn/utility-types": "1.0.0",
16+
"@types/normalize-path": "^3.0.0",
17+
"normalize-path": "^3.0.0",
18+
"@types/lodash": "^3.10.1",
19+
"moment": "^2.24.0",
20+
"typescript": "3.9.5"
21+
}
22+
}

0 commit comments

Comments
 (0)