mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Azure Monitor: Updated grafana_ds_azuremonitor_dashboard_loaded event, replaced array of queries for stats (#54286)
* Replaced array of queries for stats * Added ds_version prop * Added ds_version to tests * Extracted event name to tracking file * Extracted event to tracking file * Removed ds_version - useless for core plugin * Addressed comments * Added note to event documentation
This commit is contained in:
@@ -17,8 +17,10 @@ jest.mock('@grafana/runtime', () => {
|
||||
grafanaVersion: 'v9.0.0',
|
||||
queries: {
|
||||
'grafana-azure-monitor-datasource': [
|
||||
{ queryType: 'Azure Monitor', hide: true },
|
||||
{ queryType: 'Azure Resource Graph', hide: false },
|
||||
{ queryType: 'Azure Monitor', hide: false },
|
||||
{ queryType: 'Azure Log Analytics', hide: false },
|
||||
{ queryType: 'Azure Resource Graph', hide: true },
|
||||
{ queryType: 'Azure Monitor', hide: false },
|
||||
],
|
||||
},
|
||||
})
|
||||
@@ -35,11 +37,12 @@ describe('queriesOnInitDashboard', () => {
|
||||
dashboard_id: 'dashboard123',
|
||||
grafana_version: 'v9.0.0',
|
||||
org_id: 1,
|
||||
user_id: 2,
|
||||
queries: [
|
||||
{ query_type: 'Azure Monitor', hidden: true },
|
||||
{ query_type: 'Azure Resource Graph', hidden: false },
|
||||
],
|
||||
azure_monitor_queries: 2,
|
||||
azure_log_analytics_queries: 1,
|
||||
azure_resource_graph_queries: 0,
|
||||
azure_monitor_queries_hidden: 0,
|
||||
azure_log_analytics_queries_hidden: 0,
|
||||
azure_resource_graph_queries_hidden: 1,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { DataSourcePlugin, DashboardLoadedEvent } from '@grafana/data';
|
||||
import { reportInteraction, getAppEvents } from '@grafana/runtime';
|
||||
import { getAppEvents } from '@grafana/runtime';
|
||||
|
||||
import { ConfigEditor } from './components/ConfigEditor';
|
||||
import AzureMonitorQueryEditor from './components/QueryEditor';
|
||||
import Datasource from './datasource';
|
||||
import pluginJson from './plugin.json';
|
||||
import { AzureMonitorQuery, AzureDataSourceJsonData } from './types';
|
||||
import { trackAzureMonitorDashboardLoaded } from './tracking';
|
||||
import { AzureMonitorQuery, AzureDataSourceJsonData, AzureQueryType } from './types';
|
||||
|
||||
export const plugin = new DataSourcePlugin<Datasource, AzureMonitorQuery, AzureDataSourceJsonData>(Datasource)
|
||||
.setConfigEditor(ConfigEditor)
|
||||
@@ -16,16 +17,41 @@ getAppEvents().subscribe<DashboardLoadedEvent<AzureMonitorQuery>>(
|
||||
DashboardLoadedEvent,
|
||||
({ payload: { dashboardId, orgId, userId, grafanaVersion, queries } }) => {
|
||||
const azureQueries = queries[pluginJson.id];
|
||||
let stats = {
|
||||
[AzureQueryType.AzureMonitor]: {
|
||||
hidden: 0,
|
||||
visible: 0,
|
||||
},
|
||||
[AzureQueryType.LogAnalytics]: {
|
||||
hidden: 0,
|
||||
visible: 0,
|
||||
},
|
||||
[AzureQueryType.AzureResourceGraph]: {
|
||||
hidden: 0,
|
||||
visible: 0,
|
||||
},
|
||||
};
|
||||
azureQueries.forEach((query) => {
|
||||
if (
|
||||
query.queryType === AzureQueryType.AzureMonitor ||
|
||||
query.queryType === AzureQueryType.LogAnalytics ||
|
||||
query.queryType === AzureQueryType.AzureResourceGraph
|
||||
) {
|
||||
stats[query.queryType][query.hide ? 'hidden' : 'visible']++;
|
||||
}
|
||||
});
|
||||
|
||||
if (azureQueries && azureQueries.length > 0) {
|
||||
reportInteraction('grafana_ds_azuremonitor_dashboard_loaded', {
|
||||
trackAzureMonitorDashboardLoaded({
|
||||
grafana_version: grafanaVersion,
|
||||
dashboard_id: dashboardId,
|
||||
org_id: orgId,
|
||||
user_id: userId,
|
||||
queries: azureQueries.map((query: AzureMonitorQuery) => ({
|
||||
hidden: !!query.hide,
|
||||
query_type: query.queryType,
|
||||
})),
|
||||
azure_monitor_queries: stats[AzureQueryType.AzureMonitor].visible,
|
||||
azure_log_analytics_queries: stats[AzureQueryType.LogAnalytics].visible,
|
||||
azure_resource_graph_queries: stats[AzureQueryType.AzureResourceGraph].visible,
|
||||
azure_monitor_queries_hidden: stats[AzureQueryType.AzureMonitor].hidden,
|
||||
azure_log_analytics_queries_hidden: stats[AzureQueryType.LogAnalytics].hidden,
|
||||
azure_resource_graph_queries_hidden: stats[AzureQueryType.AzureResourceGraph].hidden,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { reportInteraction } from '@grafana/runtime';
|
||||
|
||||
/**
|
||||
* Loaded the first time a dashboard containing azure queries is loaded (not on every render)
|
||||
* Note: The queries used here are the ones pre-migration and pre-filterQuery
|
||||
*
|
||||
* This allows answering questions about:
|
||||
* - the adoption of the three query types (Azure Monitor, Azure Logs Analytics and Azure Resource Graph)
|
||||
* - stats about number of azure dashboards loaded, number of users
|
||||
* - stats about the grafana and plugins versions used by our users
|
||||
*
|
||||
* Dashboard: https://ops.grafana.net/d/Ad0pti0N/data-sources-adoption-tracking?orgId=1
|
||||
* Changelog:
|
||||
* - v9.1.0 : list of queries logged
|
||||
* - v9.1.2 : list removed in favour of stats, user_id removed
|
||||
*/
|
||||
export const trackAzureMonitorDashboardLoaded = (props: AzureMonitorDashboardLoadedProps) => {
|
||||
reportInteraction('grafana_ds_azuremonitor_dashboard_loaded', props);
|
||||
};
|
||||
|
||||
export type AzureMonitorDashboardLoadedProps = {
|
||||
grafana_version?: string;
|
||||
dashboard_id: string;
|
||||
org_id?: number;
|
||||
/** number of non hidden queries of type Azure Monitor if any */
|
||||
azure_monitor_queries: number;
|
||||
/** number of non hidden queries of type Azure Logs Analytics if any */
|
||||
azure_log_analytics_queries: number;
|
||||
/** number of non hidden queries of type Azure Resource Graph if any */
|
||||
azure_resource_graph_queries: number;
|
||||
/** number of hidden queries (not executed) of type Azure Monitor if any */
|
||||
azure_monitor_queries_hidden: number;
|
||||
/** number of hidden queries (not executed) of type Azure Logs Analytics if any */
|
||||
azure_log_analytics_queries_hidden: number;
|
||||
/** number of hidden queries (not executed) of type Azure Resource Graph if any */
|
||||
azure_resource_graph_queries_hidden: number;
|
||||
};
|
||||
Reference in New Issue
Block a user