[Usage Collection] [schema] ui_metric (#78827)

This commit is contained in:
Alejandro Fernández Haro 2020-10-01 08:22:51 +01:00 committed by GitHub
parent 3d9ea52803
commit 4c9a7bdf48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 860 additions and 4 deletions

View file

@ -5,8 +5,7 @@
"exclude": [
"src/plugins/kibana_react/",
"src/plugins/testbed/",
"src/plugins/kibana_utils/",
"src/plugins/kibana_usage_collection/server/collectors/ui_metric/telemetry_ui_metric_collector.ts"
"src/plugins/kibana_utils/"
]
}
]

View file

@ -0,0 +1,103 @@
/*
* 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 { UIMetricUsage } from './telemetry_ui_metric_collector';
const commonSchema: MakeSchemaFrom<UIMetricUsage>[string] = {
type: 'array',
items: {
key: { type: 'keyword' },
value: { type: 'long' },
},
};
// TODO: Find a way to retrieve it automatically
// plugin `data` registers all UI Metric for each appId where searches are performed (keys below are copy-pasted from application_usage)
const uiMetricFromDataPluginSchema: MakeSchemaFrom<UIMetricUsage> = {
// OSS
dashboards: commonSchema,
dev_tools: commonSchema,
discover: commonSchema,
home: commonSchema,
kibana: commonSchema, // It's a forward app so we'll likely never report it
management: commonSchema,
short_url_redirect: commonSchema, // It's a forward app so we'll likely never report it
timelion: commonSchema,
visualize: commonSchema,
// X-Pack
apm: commonSchema,
csm: commonSchema,
canvas: commonSchema,
dashboard_mode: commonSchema, // It's a forward app so we'll likely never report it
enterpriseSearch: commonSchema,
appSearch: commonSchema,
workplaceSearch: commonSchema,
graph: commonSchema,
logs: commonSchema,
metrics: commonSchema,
infra: commonSchema, // It's a forward app so we'll likely never report it
ingestManager: commonSchema,
lens: commonSchema,
maps: commonSchema,
ml: commonSchema,
monitoring: commonSchema,
'observability-overview': commonSchema,
security_account: commonSchema,
security_access_agreement: commonSchema,
security_capture_url: commonSchema, // It's a forward app so we'll likely never report it
security_logged_out: commonSchema,
security_login: commonSchema,
security_logout: commonSchema,
security_overwritten_session: commonSchema,
securitySolution: commonSchema,
'securitySolution:overview': commonSchema,
'securitySolution:detections': commonSchema,
'securitySolution:hosts': commonSchema,
'securitySolution:network': commonSchema,
'securitySolution:timelines': commonSchema,
'securitySolution:case': commonSchema,
'securitySolution:administration': commonSchema,
siem: commonSchema,
space_selector: commonSchema,
uptime: commonSchema,
};
// TODO: Find a way to retrieve it automatically
// Searching `reportUiStats` across Kibana
export const uiMetricSchema: MakeSchemaFrom<UIMetricUsage> = {
console: commonSchema,
DashboardPanelVersionInUrl: commonSchema,
Kibana_home: commonSchema, // eslint-disable-line @typescript-eslint/naming-convention
visualize: commonSchema,
canvas: commonSchema,
cross_cluster_replication: commonSchema,
index_lifecycle_management: commonSchema,
index_management: commonSchema,
ingest_pipelines: commonSchema,
apm: commonSchema,
infra_logs: commonSchema,
infra_metrics: commonSchema,
stack_monitoring: commonSchema,
remote_clusters: commonSchema,
rollup_jobs: commonSchema,
securitySolution: commonSchema,
snapshot_restore: commonSchema,
...uiMetricFromDataPluginSchema,
};

View file

@ -23,11 +23,19 @@ import {
SavedObjectsServiceSetup,
} from 'kibana/server';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { uiMetricSchema } from './schema';
interface UIMetricsSavedObjects extends SavedObjectAttributes {
count: number;
}
interface UIMetricElement {
key: string;
value: number;
}
export type UIMetricUsage = Record<string, UIMetricElement[]>;
export function registerUiMetricUsageCollector(
usageCollection: UsageCollectionSetup,
registerType: SavedObjectsServiceSetup['registerType'],
@ -46,8 +54,9 @@ export function registerUiMetricUsageCollector(
},
});
const collector = usageCollection.makeUsageCollector({
const collector = usageCollection.makeUsageCollector<UIMetricUsage | undefined>({
type: 'ui_metric',
schema: uiMetricSchema,
fetch: async () => {
const savedObjectsClient = getSavedObjectsClient();
if (typeof savedObjectsClient === 'undefined') {
@ -73,7 +82,7 @@ export function registerUiMetricUsageCollector(
...accum,
[appName]: [...(accum[appName] || []), pair],
};
}, {} as Record<string, Array<{ key: string; value: number }>>);
}, {} as UIMetricUsage);
return uiMetricsByAppName;
},

View file

@ -1623,6 +1623,751 @@
}
}
},
"ui_metric": {
"properties": {
"console": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"DashboardPanelVersionInUrl": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"Kibana_home": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"visualize": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"canvas": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"cross_cluster_replication": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"index_lifecycle_management": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"index_management": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"ingest_pipelines": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"apm": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"infra_logs": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"infra_metrics": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"stack_monitoring": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"remote_clusters": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"rollup_jobs": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"securitySolution": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"snapshot_restore": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"dashboards": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"dev_tools": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"discover": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"home": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"kibana": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"management": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"short_url_redirect": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"timelion": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"csm": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"dashboard_mode": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"enterpriseSearch": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"appSearch": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"workplaceSearch": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"graph": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"logs": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"metrics": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"infra": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"ingestManager": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"lens": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"maps": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"ml": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"monitoring": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"observability-overview": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"security_account": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"security_access_agreement": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"security_capture_url": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"security_logged_out": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"security_login": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"security_logout": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"security_overwritten_session": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"securitySolution:overview": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"securitySolution:detections": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"securitySolution:hosts": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"securitySolution:network": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"securitySolution:timelines": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"securitySolution:case": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"securitySolution:administration": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"siem": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"space_selector": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
},
"uptime": {
"type": "array",
"items": {
"properties": {
"key": {
"type": "keyword"
},
"value": {
"type": "long"
}
}
}
}
}
},
"telemetry": {
"properties": {
"opt_in_status": {