Skip to content

Commit

Permalink
[Usage Collection] Add schema to stack_management (#77897)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
afharo and elasticmachine authored Sep 24, 2020
1 parent 89e1f08 commit 18f7f04
Show file tree
Hide file tree
Showing 5 changed files with 397 additions and 3 deletions.
1 change: 0 additions & 1 deletion .telemetryrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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' },
};
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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);
Expand Down
Loading

0 comments on commit 18f7f04

Please sign in to comment.