mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 21:19:28 -06:00
AzureMonitor: Update query tracking (#68114)
* Update tracking - Add traces tracking - Update other query type tracking * Fix lint * More tracking * Lint
This commit is contained in:
parent
a5e9a1f140
commit
5a044ac4b4
@ -1,6 +1,8 @@
|
||||
import { DashboardLoadedEvent } from '@grafana/data';
|
||||
import { reportInteraction } from '@grafana/runtime';
|
||||
|
||||
import './module';
|
||||
import { AzureMonitorQuery } from './types';
|
||||
|
||||
jest.mock('@grafana/runtime', () => {
|
||||
return {
|
||||
@ -17,11 +19,45 @@ jest.mock('@grafana/runtime', () => {
|
||||
grafanaVersion: 'v9.0.0',
|
||||
queries: {
|
||||
'grafana-azure-monitor-datasource': [
|
||||
{ queryType: 'Azure Monitor', hide: false },
|
||||
{ queryType: 'Azure Log Analytics', hide: false },
|
||||
{ queryType: 'Azure Resource Graph', hide: true },
|
||||
{ queryType: 'Azure Monitor', hide: false },
|
||||
],
|
||||
{
|
||||
queryType: 'Azure Monitor',
|
||||
hide: false,
|
||||
azureMonitor: { resources: ['test_resource_1', 'test_resource_2'] },
|
||||
},
|
||||
{ queryType: 'Azure Monitor', hide: true },
|
||||
{
|
||||
queryType: 'Azure Log Analytics',
|
||||
hide: false,
|
||||
azureLogAnalytics: { resources: ['test_workspace_1', 'test_workspace_2'] },
|
||||
},
|
||||
{
|
||||
queryType: 'Azure Log Analytics',
|
||||
hide: true,
|
||||
},
|
||||
{ queryType: 'Azure Resource Graph', hide: true, subscriptions: ['sub1', 'sub2'] },
|
||||
{ queryType: 'Azure Resource Graph', hide: false },
|
||||
{
|
||||
queryType: 'Azure Traces',
|
||||
hide: false,
|
||||
azureTraces: {
|
||||
resources: ['test-ai-1', 'test-ai-2'],
|
||||
operationId: 'test-op-id',
|
||||
resultFormat: 'table',
|
||||
traceTypes: ['trace'],
|
||||
filters: [{ filters: 'test-filter', operation: 'eq', property: 'test-property' }],
|
||||
},
|
||||
},
|
||||
{ queryType: 'Azure Traces', hide: true, azureTraces: { resultFormat: 'trace' } },
|
||||
{ queryType: 'Azure Subscriptions' },
|
||||
{ queryType: 'Azure Resource Groups' },
|
||||
{ queryType: 'Azure Namespaces' },
|
||||
{ queryType: 'Azure Resource Names' },
|
||||
{ queryType: 'Azure Metric Names' },
|
||||
{ queryType: 'Azure Workspaces' },
|
||||
{ queryType: 'Azure Regions' },
|
||||
{ queryType: 'Grafana Template Variable Function' },
|
||||
{ queryType: 'unknown' },
|
||||
] as AzureMonitorQuery[],
|
||||
},
|
||||
})
|
||||
);
|
||||
@ -37,12 +73,40 @@ describe('queriesOnInitDashboard', () => {
|
||||
dashboard_id: 'dashboard123',
|
||||
grafana_version: 'v9.0.0',
|
||||
org_id: 1,
|
||||
azure_monitor_queries: 2,
|
||||
azure_monitor_queries: 1,
|
||||
azure_monitor_queries_hidden: 1,
|
||||
azure_monitor_multiple_resource: 1,
|
||||
azure_monitor_query: 2,
|
||||
|
||||
azure_log_analytics_queries: 1,
|
||||
azure_resource_graph_queries: 0,
|
||||
azure_monitor_queries_hidden: 0,
|
||||
azure_log_analytics_queries_hidden: 0,
|
||||
azure_log_analytics_queries_hidden: 1,
|
||||
azure_log_multiple_resource: 1,
|
||||
azure_log_query: 2,
|
||||
|
||||
azure_resource_graph_queries: 1,
|
||||
azure_resource_graph_queries_hidden: 1,
|
||||
azure_resource_graph_multiple_subscription: 1,
|
||||
azure_resource_graph_query: 2,
|
||||
|
||||
azure_traces_queries: 1,
|
||||
azure_traces_queries_hidden: 1,
|
||||
azure_traces_multiple_resource: 1,
|
||||
azure_traces_table: 1,
|
||||
azure_traces_trace: 1,
|
||||
azure_traces_operation_id_specified: 1,
|
||||
azure_traces_event_type_specified: 1,
|
||||
azure_traces_filters: 1,
|
||||
azure_traces_query: 2,
|
||||
|
||||
azure_subscriptions_query: 1,
|
||||
azure_resource_groups_query: 1,
|
||||
azure_namespaces_query: 1,
|
||||
azure_resource_names_query: 1,
|
||||
azure_metric_names_query: 1,
|
||||
azure_workspaces_query: 1,
|
||||
azure_grafana_template_variable_query: 1,
|
||||
azure_locations_query: 1,
|
||||
azure_unknown_query: 1,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -6,38 +6,119 @@ import AzureMonitorQueryEditor from './components/QueryEditor';
|
||||
import Datasource from './datasource';
|
||||
import pluginJson from './plugin.json';
|
||||
import { trackAzureMonitorDashboardLoaded } from './tracking';
|
||||
import { AzureMonitorQuery, AzureDataSourceJsonData, AzureQueryType } from './types';
|
||||
import { AzureMonitorQuery, AzureDataSourceJsonData, AzureQueryType, ResultFormat } from './types';
|
||||
|
||||
export const plugin = new DataSourcePlugin<Datasource, AzureMonitorQuery, AzureDataSourceJsonData>(Datasource)
|
||||
.setConfigEditor(ConfigEditor)
|
||||
.setQueryEditor(AzureMonitorQueryEditor);
|
||||
|
||||
interface Statistics {
|
||||
hidden: number;
|
||||
visible: number;
|
||||
multiResource: number;
|
||||
count: number;
|
||||
[key: string]: number;
|
||||
}
|
||||
|
||||
// Track dashboard loads to RudderStack
|
||||
getAppEvents().subscribe<DashboardLoadedEvent<AzureMonitorQuery>>(
|
||||
DashboardLoadedEvent,
|
||||
({ payload: { dashboardId, orgId, userId, grafanaVersion, queries } }) => {
|
||||
const azureQueries = queries[pluginJson.id];
|
||||
let stats = {
|
||||
const common = {
|
||||
hidden: 0,
|
||||
visible: 0,
|
||||
multiResource: 0,
|
||||
count: 0,
|
||||
};
|
||||
let stats: { [key in AzureQueryType | string]: Statistics } = {
|
||||
[AzureQueryType.AzureMonitor]: {
|
||||
hidden: 0,
|
||||
visible: 0,
|
||||
...common,
|
||||
},
|
||||
[AzureQueryType.LogAnalytics]: {
|
||||
hidden: 0,
|
||||
visible: 0,
|
||||
...common,
|
||||
},
|
||||
[AzureQueryType.AzureResourceGraph]: {
|
||||
hidden: 0,
|
||||
visible: 0,
|
||||
...common,
|
||||
},
|
||||
[AzureQueryType.AzureTraces]: {
|
||||
...common,
|
||||
table: 0,
|
||||
trace: 0,
|
||||
operationIdSpecified: 0,
|
||||
eventTypesSpecified: 0,
|
||||
filtersSpecified: 0,
|
||||
},
|
||||
[AzureQueryType.SubscriptionsQuery]: { ...common },
|
||||
[AzureQueryType.ResourceGroupsQuery]: { ...common },
|
||||
[AzureQueryType.NamespacesQuery]: { ...common },
|
||||
[AzureQueryType.ResourceNamesQuery]: { ...common },
|
||||
[AzureQueryType.MetricNamesQuery]: { ...common },
|
||||
[AzureQueryType.WorkspacesQuery]: { ...common },
|
||||
[AzureQueryType.GrafanaTemplateVariableFn]: { ...common },
|
||||
[AzureQueryType.LocationsQuery]: { ...common },
|
||||
unknown: { ...common },
|
||||
};
|
||||
|
||||
azureQueries.forEach((query) => {
|
||||
if (
|
||||
query.queryType === AzureQueryType.AzureMonitor ||
|
||||
query.queryType === AzureQueryType.LogAnalytics ||
|
||||
query.queryType === AzureQueryType.AzureResourceGraph
|
||||
) {
|
||||
stats[query.queryType][query.hide ? 'hidden' : 'visible']++;
|
||||
if (query.queryType === AzureQueryType.AzureMonitor) {
|
||||
stats[AzureQueryType.AzureMonitor][query.hide ? 'hidden' : 'visible']++;
|
||||
if (query.azureMonitor?.resources && query.azureMonitor.resources.length > 1) {
|
||||
stats[AzureQueryType.AzureMonitor].multiResource++;
|
||||
}
|
||||
}
|
||||
if (query.queryType === AzureQueryType.LogAnalytics) {
|
||||
stats[AzureQueryType.LogAnalytics][query.hide ? 'hidden' : 'visible']++;
|
||||
if (query.azureLogAnalytics?.resources && query.azureLogAnalytics.resources.length > 1) {
|
||||
stats[AzureQueryType.LogAnalytics].multiResource++;
|
||||
}
|
||||
}
|
||||
if (query.queryType === AzureQueryType.AzureResourceGraph) {
|
||||
stats[AzureQueryType.AzureResourceGraph][query.hide ? 'hidden' : 'visible']++;
|
||||
if (query.subscriptions && query.subscriptions.length > 1) {
|
||||
stats[AzureQueryType.AzureResourceGraph].multiResource++;
|
||||
}
|
||||
}
|
||||
if (query.queryType === AzureQueryType.AzureTraces) {
|
||||
stats[AzureQueryType.AzureTraces][query.hide ? 'hidden' : 'visible']++;
|
||||
if (query.azureTraces) {
|
||||
if (query.azureTraces.resultFormat) {
|
||||
stats[AzureQueryType.AzureTraces][
|
||||
query.azureTraces.resultFormat === ResultFormat.Trace ? ResultFormat.Trace : ResultFormat.Table
|
||||
]++;
|
||||
}
|
||||
if (query.azureTraces.resources && query.azureTraces.resources.length > 1) {
|
||||
stats[AzureQueryType.AzureTraces].multiResource++;
|
||||
}
|
||||
if (query.azureTraces.operationId && query.azureTraces.operationId !== '') {
|
||||
stats[AzureQueryType.AzureTraces].operationIdSpecified++;
|
||||
}
|
||||
if (query.azureTraces.traceTypes && query.azureTraces.traceTypes.length > 0) {
|
||||
stats[AzureQueryType.AzureTraces].eventTypesSpecified++;
|
||||
}
|
||||
if (query.azureTraces.filters && query.azureTraces.filters.length > 0) {
|
||||
stats[AzureQueryType.AzureTraces].filtersSpecified++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (query.queryType) {
|
||||
case AzureQueryType.AzureMonitor:
|
||||
case AzureQueryType.LogAnalytics:
|
||||
case AzureQueryType.AzureResourceGraph:
|
||||
case AzureQueryType.AzureTraces:
|
||||
case AzureQueryType.SubscriptionsQuery:
|
||||
case AzureQueryType.ResourceGroupsQuery:
|
||||
case AzureQueryType.NamespacesQuery:
|
||||
case AzureQueryType.ResourceNamesQuery:
|
||||
case AzureQueryType.MetricNamesQuery:
|
||||
case AzureQueryType.WorkspacesQuery:
|
||||
case AzureQueryType.GrafanaTemplateVariableFn:
|
||||
case AzureQueryType.LocationsQuery:
|
||||
stats[query.queryType].count++;
|
||||
break;
|
||||
default:
|
||||
stats.unknown.count++;
|
||||
}
|
||||
});
|
||||
|
||||
@ -46,12 +127,47 @@ getAppEvents().subscribe<DashboardLoadedEvent<AzureMonitorQuery>>(
|
||||
grafana_version: grafanaVersion,
|
||||
dashboard_id: dashboardId,
|
||||
org_id: orgId,
|
||||
// Metrics queries stats
|
||||
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_monitor_multiple_resource: stats[AzureQueryType.AzureMonitor].multiResource,
|
||||
azure_monitor_query: stats[AzureQueryType.AzureMonitor].count,
|
||||
|
||||
// Logs queries stats
|
||||
azure_log_analytics_queries: stats[AzureQueryType.LogAnalytics].visible,
|
||||
azure_log_analytics_queries_hidden: stats[AzureQueryType.LogAnalytics].hidden,
|
||||
azure_log_multiple_resource: stats[AzureQueryType.LogAnalytics].multiResource,
|
||||
azure_log_query: stats[AzureQueryType.LogAnalytics].count,
|
||||
|
||||
// ARG queries stats
|
||||
azure_resource_graph_queries: stats[AzureQueryType.AzureResourceGraph].visible,
|
||||
azure_resource_graph_queries_hidden: stats[AzureQueryType.AzureResourceGraph].hidden,
|
||||
azure_resource_graph_multiple_subscription: stats[AzureQueryType.AzureResourceGraph].multiResource,
|
||||
azure_resource_graph_query: stats[AzureQueryType.AzureResourceGraph].count,
|
||||
|
||||
// Traces queries stats
|
||||
azure_traces_queries: stats[AzureQueryType.AzureTraces].visible,
|
||||
azure_traces_queries_hidden: stats[AzureQueryType.AzureTraces].hidden,
|
||||
azure_traces_multiple_resource: stats[AzureQueryType.AzureTraces].multiResource,
|
||||
azure_traces_table: stats[AzureQueryType.AzureTraces].table,
|
||||
azure_traces_trace: stats[AzureQueryType.AzureTraces].trace,
|
||||
azure_traces_operation_id_specified: stats[AzureQueryType.AzureTraces].operationIdSpecified,
|
||||
azure_traces_event_type_specified: stats[AzureQueryType.AzureTraces].eventTypesSpecified,
|
||||
azure_traces_filters: stats[AzureQueryType.AzureTraces].filtersSpecified,
|
||||
azure_traces_query: stats[AzureQueryType.AzureTraces].count,
|
||||
|
||||
// Variable queries stats
|
||||
azure_subscriptions_query: stats[AzureQueryType.SubscriptionsQuery].count,
|
||||
azure_resource_groups_query: stats[AzureQueryType.ResourceGroupsQuery].count,
|
||||
azure_namespaces_query: stats[AzureQueryType.NamespacesQuery].count,
|
||||
azure_resource_names_query: stats[AzureQueryType.ResourceNamesQuery].count,
|
||||
azure_metric_names_query: stats[AzureQueryType.MetricNamesQuery].count,
|
||||
azure_workspaces_query: stats[AzureQueryType.WorkspacesQuery].count,
|
||||
azure_grafana_template_variable_query: stats[AzureQueryType.GrafanaTemplateVariableFn].count,
|
||||
azure_locations_query: stats[AzureQueryType.LocationsQuery].count,
|
||||
|
||||
// Unknown query type
|
||||
azure_unknown_query: stats.unknown.count,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -22,16 +22,61 @@ 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 Azure Monitor queries using multiple resources */
|
||||
azure_monitor_multiple_resource: number;
|
||||
/** number of Azure Monitor queries */
|
||||
azure_monitor_query: number;
|
||||
|
||||
/** number of non hidden queries of type Azure Logs Analytics if any */
|
||||
azure_log_analytics_queries: number;
|
||||
/** number of hidden queries (not executed) of type Azure Logs Analytics if any */
|
||||
azure_log_analytics_queries_hidden: number;
|
||||
/** number of Azure Log Analytics queries using multiple resources */
|
||||
azure_log_multiple_resource: number;
|
||||
/** number of Azure Log Analytics queries */
|
||||
azure_log_query: 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 Resource Graph if any */
|
||||
azure_resource_graph_queries_hidden: number;
|
||||
/** number of Azure Resource Graph queries using multiple subscriptions */
|
||||
azure_resource_graph_multiple_subscription: number;
|
||||
/** number of Azure Resource Graph queries */
|
||||
azure_resource_graph_query: number;
|
||||
|
||||
/** number of non hidden queries of type Azure Traces if any */
|
||||
azure_traces_queries: number;
|
||||
/** number of hidden queries of type Azure Traces if any */
|
||||
azure_traces_queries_hidden: number;
|
||||
/** number of trace queries using multiple resources */
|
||||
azure_traces_multiple_resource: number;
|
||||
/** number of trace queries using table format */
|
||||
azure_traces_table: number;
|
||||
/** number of trace queries using trace format */
|
||||
azure_traces_trace: number;
|
||||
/** number of trace queries specifying operation ID */
|
||||
azure_traces_operation_id_specified: number;
|
||||
/** number of trace queries specifying event types */
|
||||
azure_traces_event_type_specified: number;
|
||||
/** number of trace queries using filters */
|
||||
azure_traces_filters: number;
|
||||
/** number of Azure Traces queries */
|
||||
azure_traces_query: number;
|
||||
|
||||
/** variable query tracking */
|
||||
azure_subscriptions_query: number;
|
||||
azure_resource_groups_query: number;
|
||||
azure_namespaces_query: number;
|
||||
azure_resource_names_query: number;
|
||||
azure_metric_names_query: number;
|
||||
azure_workspaces_query: number;
|
||||
azure_grafana_template_variable_query: number;
|
||||
azure_locations_query: number;
|
||||
azure_unknown_query: number;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user