mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboard: Track every panel type usage (count) (#79421)
This commit is contained in:
parent
2165c9b3f0
commit
3fc7aa97d6
@ -11,7 +11,12 @@ describe('trackDashboardLoaded', () => {
|
|||||||
title: 'Test Dashboard',
|
title: 'Test Dashboard',
|
||||||
panels: [
|
panels: [
|
||||||
{ id: 1, type: 'row', repeat: 'dc', gridPos: { x: 0, y: 0, h: 1, w: 24 } },
|
{ 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: {
|
templating: {
|
||||||
list: [
|
list: [
|
||||||
@ -30,10 +35,16 @@ describe('trackDashboardLoaded', () => {
|
|||||||
uid: 'dashboard-123',
|
uid: 'dashboard-123',
|
||||||
title: 'Test Dashboard',
|
title: 'Test Dashboard',
|
||||||
schemaVersion: model.schemaVersion, // This value is based on public/app/features/dashboard/state/DashboardMigrator.ts#L81
|
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_query_count: 2,
|
||||||
variable_type_interval_count: 1,
|
variable_type_interval_count: 1,
|
||||||
version_before_migration: 16,
|
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,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -6,11 +6,19 @@ export function trackDashboardLoaded(dashboard: DashboardModel, versionBeforeMig
|
|||||||
// Count the different types of variables
|
// Count the different types of variables
|
||||||
const variables = dashboard.templating.list
|
const variables = dashboard.templating.list
|
||||||
.map((v) => v.type)
|
.map((v) => v.type)
|
||||||
.reduce((r, k) => {
|
.reduce((r: Record<string, number>, k) => {
|
||||||
r[variableName(k)] = 1 + r[variableName(k)] || 1;
|
r[variableName(k)] = 1 + r[variableName(k)] || 1;
|
||||||
return r;
|
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({
|
DashboardInteractions.dashboardInitialized({
|
||||||
uid: dashboard.uid,
|
uid: dashboard.uid,
|
||||||
title: dashboard.title,
|
title: dashboard.title,
|
||||||
@ -18,8 +26,10 @@ export function trackDashboardLoaded(dashboard: DashboardModel, versionBeforeMig
|
|||||||
schemaVersion: dashboard.schemaVersion,
|
schemaVersion: dashboard.schemaVersion,
|
||||||
version_before_migration: versionBeforeMigration,
|
version_before_migration: versionBeforeMigration,
|
||||||
panels_count: dashboard.panels.length,
|
panels_count: dashboard.panels.length,
|
||||||
|
...panels,
|
||||||
...variables,
|
...variables,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const variableName = (type: string) => `variable_type_${type}_count`;
|
const variableName = (type: string) => `variable_type_${type}_count`;
|
||||||
|
const panelName = (type: string) => `panel_type_${type}_count`;
|
||||||
|
Loading…
Reference in New Issue
Block a user