Skip to content

Commit

Permalink
[Usage Collection] [schema] ui_metric
Browse files Browse the repository at this point in the history
  • Loading branch information
afharo committed Sep 29, 2020
1 parent d37e6f5 commit 420fbc7
Show file tree
Hide file tree
Showing 4 changed files with 860 additions and 4 deletions.
3 changes: 1 addition & 2 deletions .telemetryrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
]
}
]
Original file line number Diff line number Diff line change
@@ -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,
};
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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') {
Expand All @@ -73,7 +82,7 @@ export function registerUiMetricUsageCollector(
...accum,
[appName]: [...(accum[appName] || []), pair],
};
}, {} as Record<string, Array<{ key: string; value: number }>>);
}, {} as UIMetricUsage);

return uiMetricsByAppName;
},
Expand Down
Loading

0 comments on commit 420fbc7

Please sign in to comment.