Skip to content

Commit 16323e1

Browse files
Merge branch 'master' into chore/rest-graphql-cleanup
2 parents 1d218e2 + 3618cef commit 16323e1

File tree

28 files changed

+869
-85
lines changed

28 files changed

+869
-85
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
]

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) {

src/plugins/discover/public/plugin.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,14 @@ export class DiscoverPlugin
277277
return `#${path}`;
278278
});
279279
plugins.urlForwarding.forwardApp('context', 'discover', (path) => {
280+
const urlParts = path.split('/');
281+
// take care of urls containing legacy url, those split in the following way
282+
// ["", "context", indexPatternId, _type, id + params]
283+
if (urlParts[4]) {
284+
// remove _type part
285+
const newPath = [...urlParts.slice(0, 3), ...urlParts.slice(4)].join('/');
286+
return `#${newPath}`;
287+
}
280288
return `#${path}`;
281289
});
282290
plugins.urlForwarding.forwardApp('discover', 'discover', (path) => {

src/plugins/kibana_usage_collection/server/collectors/kibana/get_saved_object_counts.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ const TYPES = [
3939
];
4040

4141
export interface KibanaSavedObjectCounts {
42-
[pluginName: string]: {
43-
total: number;
44-
};
42+
dashboard: { total: number };
43+
visualization: { total: number };
44+
search: { total: number };
45+
index_pattern: { total: number };
46+
graph_workspace: { total: number };
47+
timelion_sheet: { total: number };
4548
}
4649

4750
export async function getSavedObjectsCounts(
@@ -71,7 +74,7 @@ export async function getSavedObjectsCounts(
7174
// Initialise the object with all zeros for all the types
7275
const allZeros: KibanaSavedObjectCounts = TYPES.reduce(
7376
(acc, type) => ({ ...acc, [snakeCase(type)]: { total: 0 } }),
74-
{}
77+
{} as KibanaSavedObjectCounts
7578
);
7679

7780
// Add the doc_count from each bucket

0 commit comments

Comments
 (0)