mirror of https://github.com/grafana/grafana
CloudMonitor: Add adoption metrics (#60706)
* Add adoption metrics for Cloud Monitoring - Add metrics to track each query type (MQL/Time Series Query, Builder/Time Series Filter, SLO, Annotation) * Remove hidden fields and account for pre 9.4 queries * Simplify objectpull/60684/head
parent
76e822af39
commit
f319a5f740
@ -1,14 +1,64 @@ |
||||
import { DataSourcePlugin } from '@grafana/data'; |
||||
import { get } from 'lodash'; |
||||
|
||||
import { DataSourcePlugin, DashboardLoadedEvent } from '@grafana/data'; |
||||
import { getAppEvents } from '@grafana/runtime'; |
||||
|
||||
import CloudMonitoringCheatSheet from './components/CloudMonitoringCheatSheet'; |
||||
import { ConfigEditor } from './components/ConfigEditor/ConfigEditor'; |
||||
import { QueryEditor } from './components/QueryEditor'; |
||||
import { CloudMonitoringVariableQueryEditor } from './components/VariableQueryEditor'; |
||||
import CloudMonitoringDatasource from './datasource'; |
||||
import { CloudMonitoringQuery } from './types'; |
||||
import pluginJson from './plugin.json'; |
||||
import { trackCloudMonitoringDashboardLoaded } from './tracking'; |
||||
import { CloudMonitoringQuery, QueryType } from './types'; |
||||
|
||||
export const plugin = new DataSourcePlugin<CloudMonitoringDatasource, CloudMonitoringQuery>(CloudMonitoringDatasource) |
||||
.setQueryEditorHelp(CloudMonitoringCheatSheet) |
||||
.setQueryEditor(QueryEditor) |
||||
.setConfigEditor(ConfigEditor) |
||||
.setVariableQueryEditor(CloudMonitoringVariableQueryEditor); |
||||
|
||||
// Track dashboard loads to RudderStack
|
||||
getAppEvents().subscribe<DashboardLoadedEvent<CloudMonitoringQuery>>( |
||||
DashboardLoadedEvent, |
||||
({ payload: { dashboardId, orgId, grafanaVersion, queries } }) => { |
||||
const cloudmonitorQueries = queries[pluginJson.id]; |
||||
let stats = { |
||||
[QueryType.TIME_SERIES_QUERY]: 0, |
||||
[QueryType.TIME_SERIES_LIST]: 0, |
||||
[QueryType.SLO]: 0, |
||||
[QueryType.ANNOTATION]: 0, |
||||
}; |
||||
cloudmonitorQueries.forEach((query) => { |
||||
if ( |
||||
query.queryType === QueryType.TIME_SERIES_QUERY || |
||||
query.queryType === QueryType.TIME_SERIES_LIST || |
||||
query.queryType === QueryType.SLO || |
||||
query.queryType === QueryType.ANNOTATION |
||||
) { |
||||
stats[query.queryType]++; |
||||
} else if (query.queryType === 'metrics') { |
||||
if (query.hasOwnProperty('type') && get(query, 'type') === 'annotationQuery') { |
||||
stats.annotation++; |
||||
} |
||||
if (get(query, 'metricQuery.editorMode') === 'mql') { |
||||
stats.timeSeriesQuery++; |
||||
} else { |
||||
stats.timeSeriesList++; |
||||
} |
||||
} |
||||
}); |
||||
|
||||
if (cloudmonitorQueries && cloudmonitorQueries.length > 0) { |
||||
trackCloudMonitoringDashboardLoaded({ |
||||
grafana_version: grafanaVersion, |
||||
dashboard_id: dashboardId, |
||||
org_id: orgId, |
||||
mql_queries: stats[QueryType.TIME_SERIES_QUERY], |
||||
time_series_filter_queries: stats[QueryType.TIME_SERIES_LIST], |
||||
slo_queries: stats[QueryType.SLO], |
||||
annotation_queries: stats[QueryType.ANNOTATION], |
||||
}); |
||||
} |
||||
} |
||||
); |
||||
|
@ -0,0 +1,23 @@ |
||||
import { reportInteraction } from '@grafana/runtime'; |
||||
|
||||
/** |
||||
* Loaded the first time a dashboard containing Cloudmonitoring queries is loaded (not on every render) |
||||
* Note: The queries used here are the ones pre-migration and pre-filterQuery |
||||
*/ |
||||
export const trackCloudMonitoringDashboardLoaded = (props: CloudMonitoringDashboardLoadedProps) => { |
||||
reportInteraction('grafana_ds_cloudmonitoring_dashboard_loaded', props); |
||||
}; |
||||
|
||||
export type CloudMonitoringDashboardLoadedProps = { |
||||
grafana_version?: string; |
||||
dashboard_id: string; |
||||
org_id?: number; |
||||
/** number of non hidden queries of type TimeSeriesQuery (MQL) if any */ |
||||
mql_queries: number; |
||||
/** number of non hidden queries of type TimeSeriesFilter (Builder) if any */ |
||||
time_series_filter_queries: number; |
||||
/** number of non hidden queries of type SLO if any */ |
||||
slo_queries: number; |
||||
/** number of non hidden queries of type annotation if any */ |
||||
annotation_queries: number; |
||||
}; |
Loading…
Reference in new issue