[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>
This commit is contained in:
Alejandro Fernández Haro 2020-09-24 15:41:32 +01:00 committed by GitHub
parent d320bb96d6
commit 2def83024c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 397 additions and 3 deletions

View file

@ -6,7 +6,6 @@
"src/plugins/kibana_react/",
"src/plugins/testbed/",
"src/plugins/kibana_utils/",
"src/plugins/kibana_usage_collection/server/collectors/management/telemetry_management_collector.ts",
"src/plugins/kibana_usage_collection/server/collectors/ui_metric/telemetry_ui_metric_collector.ts"
]
}

View file

@ -47,6 +47,7 @@ export function checkCompatibleTypeDescriptor(
const typeDescriptorKinds = reduce(
typeDescriptorTypes,
(acc: any, type: number, key: string) => {
key = key.replace(/'/g, '');
try {
acc[key] = kindToDescriptorName(type);
} catch (err) {
@ -61,6 +62,7 @@ export function checkCompatibleTypeDescriptor(
const transformedMappingKinds = reduce(
schemaTypes,
(acc: any, type: string, key: string) => {
key = key.replace(/'/g, '');
try {
acc[key.replace(/.type$/, '.kind')] = compatibleSchemaTypes(type as any);
} catch (err) {

View file

@ -0,0 +1,116 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { MakeSchemaFrom } from 'src/plugins/usage_collection/server';
import { UsageStats } from './telemetry_management_collector';
// Retrieved by changing all the current settings in Kibana (we'll need to revisit it in the future).
// I would suggest we use flattened type for the mappings of this collector.
export const stackManagementSchema: MakeSchemaFrom<UsageStats> = {
'visualize:enableLabs': { type: 'boolean' },
'visualization:heatmap:maxBuckets': { type: 'long' },
'visualization:colorMapping': { type: 'text' },
'visualization:regionmap:showWarnings': { type: 'boolean' },
'visualization:dimmingOpacity': { type: 'float' },
'visualization:tileMap:maxPrecision': { type: 'long' },
'securitySolution:ipReputationLinks': { type: 'text' },
'csv:separator': { type: 'keyword' },
'visualization:tileMap:WMSdefaults': { type: 'text' },
'timelion:target_buckets': { type: 'long' },
'timelion:max_buckets': { type: 'long' },
'timelion:es.timefield': { type: 'keyword' },
'timelion:min_interval': { type: 'keyword' },
'timelion:default_rows': { type: 'long' },
'timelion:default_columns': { type: 'long' },
'timelion:quandl.key': { type: 'keyword' },
'timelion:es.default_index': { type: 'keyword' },
'timelion:showTutorial': { type: 'boolean' },
'securitySolution:timeDefaults': { type: 'keyword' },
'securitySolution:defaultAnomalyScore': { type: 'long' },
'securitySolution:defaultIndex': { type: 'keyword' }, // it's an array
'securitySolution:refreshIntervalDefaults': { type: 'keyword' },
'securitySolution:newsFeedUrl': { type: 'keyword' },
'securitySolution:enableNewsFeed': { type: 'boolean' },
'search:includeFrozen': { type: 'boolean' },
'courier:maxConcurrentShardRequests': { type: 'long' },
'courier:batchSearches': { type: 'boolean' },
'courier:setRequestPreference': { type: 'keyword' },
'courier:customRequestPreference': { type: 'keyword' },
'courier:ignoreFilterIfFieldNotInIndex': { type: 'boolean' },
'rollups:enableIndexPatterns': { type: 'boolean' },
'xpackReporting:customPdfLogo': { type: 'text' },
'notifications:lifetime:warning': { type: 'long' },
'notifications:lifetime:banner': { type: 'long' },
'notifications:lifetime:info': { type: 'long' },
'notifications:banner': { type: 'text' },
'notifications:lifetime:error': { type: 'long' },
'doc_table:highlight': { type: 'boolean' },
'discover:searchOnPageLoad': { type: 'boolean' },
// eslint-disable-next-line @typescript-eslint/naming-convention
'doc_table:hideTimeColumn': { type: 'boolean' },
'discover:sampleSize': { type: 'long' },
defaultColumns: { type: 'keyword' }, // it's an array
'context:defaultSize': { type: 'long' },
'discover:aggs:terms:size': { type: 'long' },
'context:tieBreakerFields': { type: 'keyword' }, // it's an array
'discover:sort:defaultOrder': { type: 'keyword' },
'context:step': { type: 'long' },
'accessibility:disableAnimations': { type: 'boolean' },
'ml:fileDataVisualizerMaxFileSize': { type: 'keyword' },
'ml:anomalyDetection:results:enableTimeDefaults': { type: 'boolean' },
'ml:anomalyDetection:results:timeDefaults': { type: 'keyword' },
'truncate:maxHeight': { type: 'long' },
'timepicker:timeDefaults': { type: 'keyword' },
'timepicker:refreshIntervalDefaults': { type: 'keyword' },
'timepicker:quickRanges': { type: 'keyword' },
'theme:version': { type: 'keyword' },
'theme:darkMode': { type: 'boolean' },
'state:storeInSessionStorage': { type: 'boolean' },
'savedObjects:perPage': { type: 'long' },
'search:queryLanguage': { type: 'keyword' },
'shortDots:enable': { type: 'boolean' },
'sort:options': { type: 'keyword' },
'savedObjects:listingLimit': { type: 'long' },
'query:queryString:options': { type: 'keyword' },
pageNavigation: { type: 'keyword' },
'metrics:max_buckets': { type: 'long' },
'query:allowLeadingWildcards': { type: 'boolean' },
metaFields: { type: 'keyword' }, // it's an array
'indexPattern:placeholder': { type: 'keyword' },
'histogram:barTarget': { type: 'long' },
'histogram:maxBars': { type: 'long' },
'format:number:defaultLocale': { type: 'keyword' },
'format:percent:defaultPattern': { type: 'keyword' },
'format:number:defaultPattern': { type: 'keyword' },
'history:limit': { type: 'long' },
'format:defaultTypeMap': { type: 'keyword' },
'format:currency:defaultPattern': { type: 'keyword' },
defaultIndex: { type: 'keyword' },
'format:bytes:defaultPattern': { type: 'keyword' },
'filters:pinnedByDefault': { type: 'boolean' },
'filterEditor:suggestValues': { type: 'boolean' },
'fields:popularLimit': { type: 'long' },
dateNanosFormat: { type: 'keyword' },
defaultRoute: { type: 'keyword' },
'dateFormat:tz': { type: 'keyword' },
'dateFormat:scaled': { type: 'keyword' },
'csv:quoteValues': { type: 'boolean' },
'dateFormat:dow': { type: 'keyword' },
dateFormat: { type: 'keyword' },
};

View file

@ -19,8 +19,13 @@
import { IUiSettingsClient } from 'kibana/server';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { stackManagementSchema } from './schema';
export type UsageStats = Record<string, any>;
export interface UsageStats extends Record<string, boolean | number | string> {
// We don't support `type` yet. Only interfaces. So I added at least 1 known key to the generic
// Record extension to avoid eslint reverting it back to a `type`
'visualize:enableLabs': boolean;
}
export function createCollectorFetch(getUiSettingsClient: () => IUiSettingsClient | undefined) {
return async function fetchUsageStats(): Promise<UsageStats | undefined> {
@ -45,10 +50,11 @@ export function registerManagementUsageCollector(
usageCollection: UsageCollectionSetup,
getUiSettingsClient: () => IUiSettingsClient | undefined
) {
const collector = usageCollection.makeUsageCollector({
const collector = usageCollection.makeUsageCollector<UsageStats | undefined>({
type: 'stack_management',
isReady: () => typeof getUiSettingsClient() !== 'undefined',
fetch: createCollectorFetch(getUiSettingsClient),
schema: stackManagementSchema,
});
usageCollection.registerCollector(collector);

View file

@ -1346,6 +1346,277 @@
}
}
},
"stack_management": {
"properties": {
"visualize:enableLabs": {
"type": "boolean"
},
"visualization:heatmap:maxBuckets": {
"type": "long"
},
"visualization:colorMapping": {
"type": "text"
},
"visualization:regionmap:showWarnings": {
"type": "boolean"
},
"visualization:dimmingOpacity": {
"type": "float"
},
"visualization:tileMap:maxPrecision": {
"type": "long"
},
"securitySolution:ipReputationLinks": {
"type": "text"
},
"csv:separator": {
"type": "keyword"
},
"visualization:tileMap:WMSdefaults": {
"type": "text"
},
"timelion:target_buckets": {
"type": "long"
},
"timelion:max_buckets": {
"type": "long"
},
"timelion:es.timefield": {
"type": "keyword"
},
"timelion:min_interval": {
"type": "keyword"
},
"timelion:default_rows": {
"type": "long"
},
"timelion:default_columns": {
"type": "long"
},
"timelion:quandl.key": {
"type": "keyword"
},
"timelion:es.default_index": {
"type": "keyword"
},
"timelion:showTutorial": {
"type": "boolean"
},
"securitySolution:timeDefaults": {
"type": "keyword"
},
"securitySolution:defaultAnomalyScore": {
"type": "long"
},
"securitySolution:defaultIndex": {
"type": "keyword"
},
"securitySolution:refreshIntervalDefaults": {
"type": "keyword"
},
"securitySolution:newsFeedUrl": {
"type": "keyword"
},
"securitySolution:enableNewsFeed": {
"type": "boolean"
},
"search:includeFrozen": {
"type": "boolean"
},
"courier:maxConcurrentShardRequests": {
"type": "long"
},
"courier:batchSearches": {
"type": "boolean"
},
"courier:setRequestPreference": {
"type": "keyword"
},
"courier:customRequestPreference": {
"type": "keyword"
},
"courier:ignoreFilterIfFieldNotInIndex": {
"type": "boolean"
},
"rollups:enableIndexPatterns": {
"type": "boolean"
},
"xpackReporting:customPdfLogo": {
"type": "text"
},
"notifications:lifetime:warning": {
"type": "long"
},
"notifications:lifetime:banner": {
"type": "long"
},
"notifications:lifetime:info": {
"type": "long"
},
"notifications:banner": {
"type": "text"
},
"notifications:lifetime:error": {
"type": "long"
},
"doc_table:highlight": {
"type": "boolean"
},
"discover:searchOnPageLoad": {
"type": "boolean"
},
"doc_table:hideTimeColumn": {
"type": "boolean"
},
"discover:sampleSize": {
"type": "long"
},
"defaultColumns": {
"type": "keyword"
},
"context:defaultSize": {
"type": "long"
},
"discover:aggs:terms:size": {
"type": "long"
},
"context:tieBreakerFields": {
"type": "keyword"
},
"discover:sort:defaultOrder": {
"type": "keyword"
},
"context:step": {
"type": "long"
},
"accessibility:disableAnimations": {
"type": "boolean"
},
"ml:fileDataVisualizerMaxFileSize": {
"type": "keyword"
},
"ml:anomalyDetection:results:enableTimeDefaults": {
"type": "boolean"
},
"ml:anomalyDetection:results:timeDefaults": {
"type": "keyword"
},
"truncate:maxHeight": {
"type": "long"
},
"timepicker:timeDefaults": {
"type": "keyword"
},
"timepicker:refreshIntervalDefaults": {
"type": "keyword"
},
"timepicker:quickRanges": {
"type": "keyword"
},
"theme:version": {
"type": "keyword"
},
"theme:darkMode": {
"type": "boolean"
},
"state:storeInSessionStorage": {
"type": "boolean"
},
"savedObjects:perPage": {
"type": "long"
},
"search:queryLanguage": {
"type": "keyword"
},
"shortDots:enable": {
"type": "boolean"
},
"sort:options": {
"type": "keyword"
},
"savedObjects:listingLimit": {
"type": "long"
},
"query:queryString:options": {
"type": "keyword"
},
"pageNavigation": {
"type": "keyword"
},
"metrics:max_buckets": {
"type": "long"
},
"query:allowLeadingWildcards": {
"type": "boolean"
},
"metaFields": {
"type": "keyword"
},
"indexPattern:placeholder": {
"type": "keyword"
},
"histogram:barTarget": {
"type": "long"
},
"histogram:maxBars": {
"type": "long"
},
"format:number:defaultLocale": {
"type": "keyword"
},
"format:percent:defaultPattern": {
"type": "keyword"
},
"format:number:defaultPattern": {
"type": "keyword"
},
"history:limit": {
"type": "long"
},
"format:defaultTypeMap": {
"type": "keyword"
},
"format:currency:defaultPattern": {
"type": "keyword"
},
"defaultIndex": {
"type": "keyword"
},
"format:bytes:defaultPattern": {
"type": "keyword"
},
"filters:pinnedByDefault": {
"type": "boolean"
},
"filterEditor:suggestValues": {
"type": "boolean"
},
"fields:popularLimit": {
"type": "long"
},
"dateNanosFormat": {
"type": "keyword"
},
"defaultRoute": {
"type": "keyword"
},
"dateFormat:tz": {
"type": "keyword"
},
"dateFormat:scaled": {
"type": "keyword"
},
"csv:quoteValues": {
"type": "boolean"
},
"dateFormat:dow": {
"type": "keyword"
},
"dateFormat": {
"type": "keyword"
}
}
},
"telemetry": {
"properties": {
"opt_in_status": {