Skip to content

Commit 2def830

Browse files
[7.x] [Usage Collection] Add schema to stack_management (#77897) (#78417)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent d320bb9 commit 2def830

File tree

5 files changed

+397
-3
lines changed

5 files changed

+397
-3
lines changed

.telemetryrc.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"src/plugins/kibana_react/",
77
"src/plugins/testbed/",
88
"src/plugins/kibana_utils/",
9-
"src/plugins/kibana_usage_collection/server/collectors/management/telemetry_management_collector.ts",
109
"src/plugins/kibana_usage_collection/server/collectors/ui_metric/telemetry_ui_metric_collector.ts"
1110
]
1211
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export function checkCompatibleTypeDescriptor(
4747
const typeDescriptorKinds = reduce(
4848
typeDescriptorTypes,
4949
(acc: any, type: number, key: string) => {
50+
key = key.replace(/'/g, '');
5051
try {
5152
acc[key] = kindToDescriptorName(type);
5253
} catch (err) {
@@ -61,6 +62,7 @@ export function checkCompatibleTypeDescriptor(
6162
const transformedMappingKinds = reduce(
6263
schemaTypes,
6364
(acc: any, type: string, key: string) => {
65+
key = key.replace(/'/g, '');
6466
try {
6567
acc[key.replace(/.type$/, '.kind')] = compatibleSchemaTypes(type as any);
6668
} catch (err) {
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
import { MakeSchemaFrom } from 'src/plugins/usage_collection/server';
21+
import { UsageStats } from './telemetry_management_collector';
22+
23+
// Retrieved by changing all the current settings in Kibana (we'll need to revisit it in the future).
24+
// I would suggest we use flattened type for the mappings of this collector.
25+
export const stackManagementSchema: MakeSchemaFrom<UsageStats> = {
26+
'visualize:enableLabs': { type: 'boolean' },
27+
'visualization:heatmap:maxBuckets': { type: 'long' },
28+
'visualization:colorMapping': { type: 'text' },
29+
'visualization:regionmap:showWarnings': { type: 'boolean' },
30+
'visualization:dimmingOpacity': { type: 'float' },
31+
'visualization:tileMap:maxPrecision': { type: 'long' },
32+
'securitySolution:ipReputationLinks': { type: 'text' },
33+
'csv:separator': { type: 'keyword' },
34+
'visualization:tileMap:WMSdefaults': { type: 'text' },
35+
'timelion:target_buckets': { type: 'long' },
36+
'timelion:max_buckets': { type: 'long' },
37+
'timelion:es.timefield': { type: 'keyword' },
38+
'timelion:min_interval': { type: 'keyword' },
39+
'timelion:default_rows': { type: 'long' },
40+
'timelion:default_columns': { type: 'long' },
41+
'timelion:quandl.key': { type: 'keyword' },
42+
'timelion:es.default_index': { type: 'keyword' },
43+
'timelion:showTutorial': { type: 'boolean' },
44+
'securitySolution:timeDefaults': { type: 'keyword' },
45+
'securitySolution:defaultAnomalyScore': { type: 'long' },
46+
'securitySolution:defaultIndex': { type: 'keyword' }, // it's an array
47+
'securitySolution:refreshIntervalDefaults': { type: 'keyword' },
48+
'securitySolution:newsFeedUrl': { type: 'keyword' },
49+
'securitySolution:enableNewsFeed': { type: 'boolean' },
50+
'search:includeFrozen': { type: 'boolean' },
51+
'courier:maxConcurrentShardRequests': { type: 'long' },
52+
'courier:batchSearches': { type: 'boolean' },
53+
'courier:setRequestPreference': { type: 'keyword' },
54+
'courier:customRequestPreference': { type: 'keyword' },
55+
'courier:ignoreFilterIfFieldNotInIndex': { type: 'boolean' },
56+
'rollups:enableIndexPatterns': { type: 'boolean' },
57+
'xpackReporting:customPdfLogo': { type: 'text' },
58+
'notifications:lifetime:warning': { type: 'long' },
59+
'notifications:lifetime:banner': { type: 'long' },
60+
'notifications:lifetime:info': { type: 'long' },
61+
'notifications:banner': { type: 'text' },
62+
'notifications:lifetime:error': { type: 'long' },
63+
'doc_table:highlight': { type: 'boolean' },
64+
'discover:searchOnPageLoad': { type: 'boolean' },
65+
// eslint-disable-next-line @typescript-eslint/naming-convention
66+
'doc_table:hideTimeColumn': { type: 'boolean' },
67+
'discover:sampleSize': { type: 'long' },
68+
defaultColumns: { type: 'keyword' }, // it's an array
69+
'context:defaultSize': { type: 'long' },
70+
'discover:aggs:terms:size': { type: 'long' },
71+
'context:tieBreakerFields': { type: 'keyword' }, // it's an array
72+
'discover:sort:defaultOrder': { type: 'keyword' },
73+
'context:step': { type: 'long' },
74+
'accessibility:disableAnimations': { type: 'boolean' },
75+
'ml:fileDataVisualizerMaxFileSize': { type: 'keyword' },
76+
'ml:anomalyDetection:results:enableTimeDefaults': { type: 'boolean' },
77+
'ml:anomalyDetection:results:timeDefaults': { type: 'keyword' },
78+
'truncate:maxHeight': { type: 'long' },
79+
'timepicker:timeDefaults': { type: 'keyword' },
80+
'timepicker:refreshIntervalDefaults': { type: 'keyword' },
81+
'timepicker:quickRanges': { type: 'keyword' },
82+
'theme:version': { type: 'keyword' },
83+
'theme:darkMode': { type: 'boolean' },
84+
'state:storeInSessionStorage': { type: 'boolean' },
85+
'savedObjects:perPage': { type: 'long' },
86+
'search:queryLanguage': { type: 'keyword' },
87+
'shortDots:enable': { type: 'boolean' },
88+
'sort:options': { type: 'keyword' },
89+
'savedObjects:listingLimit': { type: 'long' },
90+
'query:queryString:options': { type: 'keyword' },
91+
pageNavigation: { type: 'keyword' },
92+
'metrics:max_buckets': { type: 'long' },
93+
'query:allowLeadingWildcards': { type: 'boolean' },
94+
metaFields: { type: 'keyword' }, // it's an array
95+
'indexPattern:placeholder': { type: 'keyword' },
96+
'histogram:barTarget': { type: 'long' },
97+
'histogram:maxBars': { type: 'long' },
98+
'format:number:defaultLocale': { type: 'keyword' },
99+
'format:percent:defaultPattern': { type: 'keyword' },
100+
'format:number:defaultPattern': { type: 'keyword' },
101+
'history:limit': { type: 'long' },
102+
'format:defaultTypeMap': { type: 'keyword' },
103+
'format:currency:defaultPattern': { type: 'keyword' },
104+
defaultIndex: { type: 'keyword' },
105+
'format:bytes:defaultPattern': { type: 'keyword' },
106+
'filters:pinnedByDefault': { type: 'boolean' },
107+
'filterEditor:suggestValues': { type: 'boolean' },
108+
'fields:popularLimit': { type: 'long' },
109+
dateNanosFormat: { type: 'keyword' },
110+
defaultRoute: { type: 'keyword' },
111+
'dateFormat:tz': { type: 'keyword' },
112+
'dateFormat:scaled': { type: 'keyword' },
113+
'csv:quoteValues': { type: 'boolean' },
114+
'dateFormat:dow': { type: 'keyword' },
115+
dateFormat: { type: 'keyword' },
116+
};

src/plugins/kibana_usage_collection/server/collectors/management/telemetry_management_collector.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@
1919

2020
import { IUiSettingsClient } from 'kibana/server';
2121
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
22+
import { stackManagementSchema } from './schema';
2223

23-
export type UsageStats = Record<string, any>;
24+
export interface UsageStats extends Record<string, boolean | number | string> {
25+
// We don't support `type` yet. Only interfaces. So I added at least 1 known key to the generic
26+
// Record extension to avoid eslint reverting it back to a `type`
27+
'visualize:enableLabs': boolean;
28+
}
2429

2530
export function createCollectorFetch(getUiSettingsClient: () => IUiSettingsClient | undefined) {
2631
return async function fetchUsageStats(): Promise<UsageStats | undefined> {
@@ -45,10 +50,11 @@ export function registerManagementUsageCollector(
4550
usageCollection: UsageCollectionSetup,
4651
getUiSettingsClient: () => IUiSettingsClient | undefined
4752
) {
48-
const collector = usageCollection.makeUsageCollector({
53+
const collector = usageCollection.makeUsageCollector<UsageStats | undefined>({
4954
type: 'stack_management',
5055
isReady: () => typeof getUiSettingsClient() !== 'undefined',
5156
fetch: createCollectorFetch(getUiSettingsClient),
57+
schema: stackManagementSchema,
5258
});
5359

5460
usageCollection.registerCollector(collector);

0 commit comments

Comments
 (0)