Skip to content

Commit 0a74f9f

Browse files
Merge branch 'master' into fix-78191
2 parents 736e355 + 3618cef commit 0a74f9f

File tree

92 files changed

+2086
-3428
lines changed

Some content is hidden

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

92 files changed

+2086
-3428
lines changed

.telemetryrc.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
"src/plugins/kibana_react/",
77
"src/plugins/testbed/",
88
"src/plugins/kibana_utils/",
9-
"src/plugins/kibana_usage_collection/server/collectors/kibana/kibana_usage_collector.ts",
109
"src/plugins/kibana_usage_collection/server/collectors/management/telemetry_management_collector.ts",
11-
"src/plugins/kibana_usage_collection/server/collectors/ui_metric/telemetry_ui_metric_collector.ts",
12-
"src/plugins/telemetry/server/collectors/usage/telemetry_usage_collector.ts"
10+
"src/plugins/kibana_usage_collection/server/collectors/ui_metric/telemetry_ui_metric_collector.ts"
1311
]
1412
}
1513
]
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
[[ci-metrics]]
2+
== CI Metrics
3+
4+
In addition to running our tests, CI collects metrics about the Kibana build. These metrics are sent to an external service to track changes over time, and to provide PR authors insights into the impact of their changes.
5+
6+
7+
[[ci-metric-types]]
8+
=== Metric types
9+
10+
11+
[[ci-metric-types-bundle-size-metrics]]
12+
==== Bundle size
13+
14+
These metrics help contributors know how they are impacting the size of the bundles Kibana creates, and help make sure that Kibana loads as fast as possible.
15+
16+
[[ci-metric-page-load-bundle-size]] `page load bundle size` ::
17+
The size of the entry file produced for each bundle/plugin. This file is always loaded on every page load, so it should be as small as possible. To reduce this metric you can put any code that isn't necessary on every page load behind an https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports[`async import()`].
18+
+
19+
Code that is shared statically with other plugins will contribute to the `page load bundle size` of that plugin. This includes exports from the `public/index.ts` file and any file referenced by the `extraPublicDirs` manifest property.
20+
21+
[[ci-metric-async-chunks-size]] `async chunks size` ::
22+
An "async chunk" is created for the files imported by each https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports[`async import()`] statement. This metric tracks the sum size of these chunks, in bytes, broken down by plugin/bundle id. You can think of this as the amount of code users will have to download if they access all the components/applications within a bundle.
23+
24+
[[ci-metric-misc-asset-size]] `miscellaneous assets size` ::
25+
A "miscellaneous asset" is anything that isn't an async chunk or entry chunk, often images. This metric tracks the sum size of these assets, in bytes, broken down by plugin/bundle id.
26+
27+
[[ci-metric-bundle-module-count]] `@kbn/optimizer bundle module count` ::
28+
The number of separate modules included in each bundle/plugin. This is the best indicator we have for how long a specific bundle will take to be built by the `@kbn/optimizer`, so we report it to help people know when they've imported a module which might include a surprising number of sub-modules.
29+
30+
31+
[[ci-metric-types-distributable-size]]
32+
==== Distributable size
33+
34+
The size of the Kibana distributable is an essential metric as it not only contributes to the time it takes to download, but it also impacts time it takes to extract the archive once downloaded.
35+
36+
There are several metrics that we don't report on PRs because gzip-compression produces different file sizes even when provided the same input, so this metric would regularly show changes even though PR authors hadn't made any relevant changes.
37+
38+
All metrics are collected from the `tar.gz` archive produced for the linux platform.
39+
40+
[[ci-metric-distributable-file-count]] `distributable file count` ::
41+
The number of files included in the default distributable.
42+
43+
[[ci-metric-oss-distributable-file-count]] `oss distributable file count` ::
44+
The number of files included in the OSS distributable.
45+
46+
[[ci-metric-distributable-size]] `distributable size` ::
47+
The size, in bytes, of the default distributable. _(not reported on PRs)_
48+
49+
[[ci-metric-oss-distributable-size]] `oss distributable size` ::
50+
The size, in bytes, of the OSS distributable. _(not reported on PRs)_
51+
52+
53+
[[ci-metric-types-saved-object-field-counts]]
54+
==== Saved Object field counts
55+
56+
Elasticsearch limits the number of fields in an index to 1000 by default, and we want to avoid raising that limit.
57+
58+
[[ci-metric-saved-object-field-count]] `Saved Objects .kibana field count` ::
59+
The number of saved object fields broken down by saved object type.
60+
61+
62+
[[ci-metric-adding-new-metrics]]
63+
=== Adding new metrics
64+
65+
You can report new metrics by using the `CiStatsReporter` class provided by the `@kbn/dev-utils` package. This class is automatically configured on CI and its methods noop when running outside of CI. For more details checkout the {kib-repo}blob/{branch}/packages/kbn-dev-utils/src/ci_stats_reporter[`CiStatsReporter` readme].

docs/developer/contributing/index.asciidoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Read <<development-getting-started>> to get your environment up and running, the
99
* <<development-tests>>
1010
* <<development-github>>
1111
* <<interpreting-ci-failures>>
12+
* <<ci-metrics>>
1213
* <<development-documentation>>
1314
* <<development-pull-request>>
1415
* <<kibana-issue-reporting>>
@@ -78,6 +79,8 @@ include::development-tests.asciidoc[leveloffset=+1]
7879

7980
include::interpreting-ci-failures.asciidoc[leveloffset=+1]
8081

82+
include::development-ci-metrics.asciidoc[leveloffset=+1]
83+
8184
include::development-documentation.asciidoc[leveloffset=+1]
8285

8386
include::development-pull-request.asciidoc[leveloffset=+1]

packages/kbn-telemetry-tools/src/tools/__fixture__/parsed_working_collector.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,9 @@ export const parsedWorkingCollector: ParsedUsageCollection = [
7575
type: 'StringKeyword',
7676
},
7777
my_index_signature_prop: {
78-
'': {
79-
'@@INDEX@@': {
80-
kind: SyntaxKind.NumberKeyword,
81-
type: 'NumberKeyword',
82-
},
78+
'@@INDEX@@': {
79+
kind: SyntaxKind.NumberKeyword,
80+
type: 'NumberKeyword',
8381
},
8482
},
8583
my_objects: {

packages/kbn-telemetry-tools/src/tools/__snapshots__/extract_collectors.test.ts.snap

Lines changed: 11 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/kbn-telemetry-tools/src/tools/serializer.test.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ export function loadFixtureProgram(fixtureName: string) {
4444
}
4545

4646
describe('getDescriptor', () => {
47-
const usageInterfaces = new Map<string, ts.InterfaceDeclaration>();
47+
const usageInterfaces = new Map<string, ts.InterfaceDeclaration | ts.TypeAliasDeclaration>();
4848
let tsProgram: ts.Program;
4949
beforeAll(() => {
5050
const { program, sourceFile } = loadFixtureProgram('constants');
5151
tsProgram = program;
5252
for (const node of traverseNodes(sourceFile)) {
53-
if (ts.isInterfaceDeclaration(node)) {
53+
if (ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)) {
5454
const interfaceName = node.name.getText();
5555
usageInterfaces.set(interfaceName, node);
5656
}
@@ -102,4 +102,26 @@ describe('getDescriptor', () => {
102102
'Mapping does not support conflicting union types.'
103103
);
104104
});
105+
106+
it('serializes TypeAliasDeclaration', () => {
107+
const usageInterface = usageInterfaces.get('TypeAliasWithUnion')!;
108+
const descriptor = getDescriptor(usageInterface, tsProgram);
109+
expect(descriptor).toEqual({
110+
locale: { kind: ts.SyntaxKind.StringKeyword, type: 'StringKeyword' },
111+
prop1: { kind: ts.SyntaxKind.StringKeyword, type: 'StringKeyword' },
112+
prop2: { kind: ts.SyntaxKind.StringKeyword, type: 'StringKeyword' },
113+
prop3: { kind: ts.SyntaxKind.StringKeyword, type: 'StringKeyword' },
114+
prop4: { kind: ts.SyntaxKind.StringLiteral, type: 'StringLiteral' },
115+
prop5: { kind: ts.SyntaxKind.FirstLiteralToken, type: 'FirstLiteralToken' },
116+
});
117+
});
118+
119+
it('serializes Record entries', () => {
120+
const usageInterface = usageInterfaces.get('TypeAliasWithRecord')!;
121+
const descriptor = getDescriptor(usageInterface, tsProgram);
122+
expect(descriptor).toEqual({
123+
locale: { kind: ts.SyntaxKind.StringKeyword, type: 'StringKeyword' },
124+
'@@INDEX@@': { kind: ts.SyntaxKind.NumberKeyword, type: 'NumberKeyword' },
125+
});
126+
});
105127
});

packages/kbn-telemetry-tools/src/tools/serializer.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,13 @@ export function getDescriptor(node: ts.Node, program: ts.Program): Descriptor |
7979
}
8080
if (ts.isTypeLiteralNode(node) || ts.isInterfaceDeclaration(node)) {
8181
return node.members.reduce((acc, m) => {
82-
acc[m.name?.getText() || ''] = getDescriptor(m, program);
83-
return acc;
84-
}, {} as any);
82+
const key = m.name?.getText();
83+
if (key) {
84+
return { ...acc, [key]: getDescriptor(m, program) };
85+
} else {
86+
return { ...acc, ...getDescriptor(m, program) };
87+
}
88+
}, {});
8589
}
8690

8791
// If it's defined as signature { [key: string]: OtherInterface }
@@ -114,6 +118,10 @@ export function getDescriptor(node: ts.Node, program: ts.Program): Descriptor |
114118
if (symbolName === 'Date') {
115119
return { kind: TelemetryKinds.Date, type: 'Date' };
116120
}
121+
// Support `Record<string, SOMETHING>`
122+
if (symbolName === 'Record' && node.typeArguments![0].kind === ts.SyntaxKind.StringKeyword) {
123+
return { '@@INDEX@@': getDescriptor(node.typeArguments![1], program) };
124+
}
117125
const declaration = (symbol?.getDeclarations() || [])[0];
118126
if (declaration) {
119127
return getDescriptor(declaration, program);
@@ -157,6 +165,19 @@ export function getDescriptor(node: ts.Node, program: ts.Program): Descriptor |
157165
return uniqueKinds[0];
158166
}
159167

168+
// Support `type MyUsageType = SomethingElse`
169+
if (ts.isTypeAliasDeclaration(node)) {
170+
return getDescriptor(node.type, program);
171+
}
172+
173+
// Support `&` unions
174+
if (ts.isIntersectionTypeNode(node)) {
175+
return node.types.reduce(
176+
(acc, unionNode) => ({ ...acc, ...getDescriptor(unionNode, program) }),
177+
{}
178+
);
179+
}
180+
160181
switch (node.kind) {
161182
case ts.SyntaxKind.NumberKeyword:
162183
case ts.SyntaxKind.BooleanKeyword:

packages/kbn-telemetry-tools/src/tools/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export function difference(actual: any, expected: any) {
249249
function (result, value, key) {
250250
if (key && /@@INDEX@@/.test(`${key}`)) {
251251
// The type definition is an Index Signature, fuzzy searching for similar keys
252-
const regexp = new RegExp(`${key}`.replace(/@@INDEX@@/g, '(.+)?'));
252+
const regexp = new RegExp(`^${key}`.replace(/@@INDEX@@/g, '(.+)?'));
253253
const keysInBase = Object.keys(base)
254254
.map((k) => {
255255
const match = k.match(regexp);

src/fixtures/telemetry_collectors/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@ export const externallyDefinedSchema: MakeSchemaFrom<{ locale: string }> = {
5151
type: 'keyword',
5252
},
5353
};
54+
55+
export type TypeAliasWithUnion = Usage & WithUnion;
56+
57+
export type TypeAliasWithRecord = Usage & Record<string, number>;

src/plugins/discover/public/application/angular/context.js

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,18 @@ const k7Breadcrumbs = ($route) => {
4545
};
4646

4747
getAngularModule().config(($routeProvider) => {
48-
$routeProvider
49-
// deprecated route, kept for compatibility
50-
// should be removed in the future
51-
.when('/context/:indexPatternId/:type/:id*', {
52-
redirectTo: '/context/:indexPatternId/:id',
53-
})
54-
.when('/context/:indexPatternId/:id*', {
55-
controller: ContextAppRouteController,
56-
k7Breadcrumbs,
57-
controllerAs: 'contextAppRoute',
58-
resolve: {
59-
indexPattern: ($route, Promise) => {
60-
const indexPattern = getServices().indexPatterns.get(
61-
$route.current.params.indexPatternId
62-
);
63-
return Promise.props({ ip: indexPattern });
64-
},
48+
$routeProvider.when('/context/:indexPatternId/:id*', {
49+
controller: ContextAppRouteController,
50+
k7Breadcrumbs,
51+
controllerAs: 'contextAppRoute',
52+
resolve: {
53+
indexPattern: ($route, Promise) => {
54+
const indexPattern = getServices().indexPatterns.get($route.current.params.indexPatternId);
55+
return Promise.props({ ip: indexPattern });
6556
},
66-
template: contextAppRouteTemplate,
67-
});
57+
},
58+
template: contextAppRouteTemplate,
59+
});
6860
});
6961

7062
function ContextAppRouteController($routeParams, $scope, $route) {

0 commit comments

Comments
 (0)