2022-08-11 02:30:14 -05:00
|
|
|
import { DataSourcePlugin, DashboardLoadedEvent } from '@grafana/data';
|
2022-08-30 02:55:40 -05:00
|
|
|
import { getAppEvents } from '@grafana/runtime';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2019-11-06 08:29:07 -06:00
|
|
|
import { ConfigEditor } from './components/ConfigEditor';
|
2021-08-05 04:12:25 -05:00
|
|
|
import AzureMonitorQueryEditor from './components/QueryEditor';
|
2022-04-22 08:33:13 -05:00
|
|
|
import Datasource from './datasource';
|
2022-08-12 08:53:35 -05:00
|
|
|
import pluginJson from './plugin.json';
|
2022-08-30 02:55:40 -05:00
|
|
|
import { trackAzureMonitorDashboardLoaded } from './tracking';
|
|
|
|
import { AzureMonitorQuery, AzureDataSourceJsonData, AzureQueryType } from './types';
|
2019-08-19 16:35:44 -05:00
|
|
|
|
2019-11-06 08:29:07 -06:00
|
|
|
export const plugin = new DataSourcePlugin<Datasource, AzureMonitorQuery, AzureDataSourceJsonData>(Datasource)
|
2019-08-19 16:35:44 -05:00
|
|
|
.setConfigEditor(ConfigEditor)
|
2021-08-13 05:05:57 -05:00
|
|
|
.setQueryEditor(AzureMonitorQueryEditor);
|
2022-08-11 02:30:14 -05:00
|
|
|
|
|
|
|
// Track dashboard loads to RudderStack
|
|
|
|
getAppEvents().subscribe<DashboardLoadedEvent<AzureMonitorQuery>>(
|
|
|
|
DashboardLoadedEvent,
|
|
|
|
({ payload: { dashboardId, orgId, userId, grafanaVersion, queries } }) => {
|
2022-08-12 08:53:35 -05:00
|
|
|
const azureQueries = queries[pluginJson.id];
|
2022-08-30 02:55:40 -05:00
|
|
|
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']++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-08-11 02:30:14 -05:00
|
|
|
if (azureQueries && azureQueries.length > 0) {
|
2022-08-30 02:55:40 -05:00
|
|
|
trackAzureMonitorDashboardLoaded({
|
2022-08-11 02:30:14 -05:00
|
|
|
grafana_version: grafanaVersion,
|
|
|
|
dashboard_id: dashboardId,
|
|
|
|
org_id: orgId,
|
2022-08-30 02:55:40 -05:00
|
|
|
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,
|
2022-08-11 02:30:14 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|