Dashboard: Track every panel type usage (count) (#79421)

This commit is contained in:
Nathan Marrs 2023-12-18 14:49:13 -07:00 committed by GitHub
parent 2165c9b3f0
commit 3fc7aa97d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 3 deletions

View File

@ -11,7 +11,12 @@ describe('trackDashboardLoaded', () => {
title: 'Test Dashboard',
panels: [
{ id: 1, type: 'row', repeat: 'dc', gridPos: { x: 0, y: 0, h: 1, w: 24 } },
{ id: 2, repeat: 'app', repeatDirection: 'h', gridPos: { x: 0, y: 1, h: 2, w: 8 } },
{ id: 2, type: 'stat', repeat: 'app', repeatDirection: 'h', gridPos: { x: 0, y: 1, h: 2, w: 8 } },
{ id: 3, type: 'graph', repeatDirection: 'h', gridPos: { x: 0, y: 1, h: 2, w: 8 } },
{ id: 4, type: 'timeseries', repeatDirection: 'h', gridPos: { x: 0, y: 1, h: 2, w: 8 } },
{ id: 5, type: 'grafana-worldmap-panel', repeatDirection: 'h', gridPos: { x: 0, y: 1, h: 2, w: 8 } },
{ id: 6, type: 'geomap', repeatDirection: 'h', gridPos: { x: 0, y: 1, h: 2, w: 8 } },
{ id: 7, type: 'graph', repeatDirection: 'h', gridPos: { x: 0, y: 1, h: 2, w: 8 } },
],
templating: {
list: [
@ -30,10 +35,16 @@ describe('trackDashboardLoaded', () => {
uid: 'dashboard-123',
title: 'Test Dashboard',
schemaVersion: model.schemaVersion, // This value is based on public/app/features/dashboard/state/DashboardMigrator.ts#L81
panels_count: 2,
panels_count: 7,
variable_type_query_count: 2,
variable_type_interval_count: 1,
version_before_migration: 16,
panel_type_row_count: 1,
panel_type_stat_count: 1,
panel_type_graph_count: 2,
panel_type_timeseries_count: 1,
'panel_type_grafana-worldmap-panel_count': 1,
panel_type_geomap_count: 1,
});
});
});

View File

@ -6,11 +6,19 @@ export function trackDashboardLoaded(dashboard: DashboardModel, versionBeforeMig
// Count the different types of variables
const variables = dashboard.templating.list
.map((v) => v.type)
.reduce((r, k) => {
.reduce((r: Record<string, number>, k) => {
r[variableName(k)] = 1 + r[variableName(k)] || 1;
return r;
}, {});
// Count the different types of panels
const panels = dashboard.panels
.map((p) => p.type)
.reduce((r: Record<string, number>, p) => {
r[panelName(p)] = 1 + r[panelName(p)] || 1;
return r;
}, {});
DashboardInteractions.dashboardInitialized({
uid: dashboard.uid,
title: dashboard.title,
@ -18,8 +26,10 @@ export function trackDashboardLoaded(dashboard: DashboardModel, versionBeforeMig
schemaVersion: dashboard.schemaVersion,
version_before_migration: versionBeforeMigration,
panels_count: dashboard.panels.length,
...panels,
...variables,
});
}
const variableName = (type: string) => `variable_type_${type}_count`;
const panelName = (type: string) => `panel_type_${type}_count`;