|
1 |
| -import { CoreApp } from '@grafana/data'; |
2 |
| -import { reportInteraction, config } from '@grafana/runtime'; |
| 1 | +import { CoreApp, DataSourcePluginMeta } from '@grafana/data'; |
| 2 | +import { reportInteraction, config, HealthCheckResult } from '@grafana/runtime'; |
3 | 3 | import { isBackendQuery } from './../app/utils';
|
4 | 4 | import { InfinityInstanceSettings, InfinityQuery } from './../types';
|
5 | 5 |
|
6 | 6 | type Report_Action = 'grafana_infinity_query_executed' | 'grafana_infinity_health_check_executed';
|
7 | 7 |
|
8 |
| -const reportActivity = (action: Report_Action, meta?: Record<string, any>) => { |
| 8 | +const reportActivity = (action: Report_Action, data: Record<string, any> = {}, instance_settings?: InfinityInstanceSettings, plugin_meta?: DataSourcePluginMeta) => { |
9 | 9 | try {
|
10 |
| - reportInteraction(action, { ...meta, plugin_name: 'yesoreyeram-infinity-datasource', ts: new Date().getTime() }); |
| 10 | + // Grafana related meta |
| 11 | + data['grafana_licenseInfo_stateInfo'] = config?.licenseInfo?.stateInfo || ''; |
| 12 | + data['grafana_buildInfo_edition'] = config?.buildInfo?.edition || ''; |
| 13 | + data['grafana_buildInfo_version'] = config?.buildInfo?.version || ''; |
| 14 | + data['grafana_buildInfo_version_short'] = (config?.buildInfo?.version || '').split('-')[0]; |
| 15 | + data['grafana_app_url'] = config?.appUrl || ''; |
| 16 | + const grafana_url = new URL(window?.document?.URL); |
| 17 | + data['grafana_host'] = grafana_url?.host || grafana_url?.hostname || 'unknown'; |
| 18 | + // Plugin meta |
| 19 | + data['plugin_id'] = plugin_meta?.id || 'yesoreyeram-infinity-datasource'; |
| 20 | + data['plugin_version'] = plugin_meta?.info?.version || 'unknown'; |
| 21 | + // Plugin configuration |
| 22 | + data['config_authType'] = instance_settings?.jsonData?.auth_method || instance_settings?.jsonData?.authType || 'unknown'; |
| 23 | + data['config_oauth2_type'] = instance_settings?.jsonData?.oauth2?.oauth2_type || 'unknown'; |
| 24 | + data['config_global_queries_count'] = (instance_settings?.jsonData?.global_queries || []).length; |
| 25 | + data['config_reference_data_count'] = (instance_settings?.jsonData?.refData || []).length; |
| 26 | + data['config_allowed_hosts_count'] = (instance_settings?.jsonData?.allowedHosts || []).length; |
| 27 | + data['config_custom_health_check_enabled'] = instance_settings?.jsonData?.customHealthCheckEnabled ? 'enabled' : 'unknown'; |
| 28 | + reportInteraction(action, { ...data, ts: new Date().getTime() }); |
11 | 29 | } catch (ex) {
|
12 | 30 | console.error('error while reporting infinity query', ex);
|
13 | 31 | }
|
14 | 32 | };
|
15 | 33 |
|
16 |
| -export const reportHealthCheck = (meta: Record<string, string> = {}) => { |
17 |
| - reportActivity('grafana_infinity_health_check_executed', meta); |
| 34 | +export const reportHealthCheck = (o?: Omit<HealthCheckResult, 'details'>, instance_settings?: InfinityInstanceSettings, plugin_meta?: DataSourcePluginMeta) => { |
| 35 | + let meta: Record<string, any> = { |
| 36 | + plugin_healthcheck_status: o?.status || 'unknown', |
| 37 | + plugin_healthcheck_message: o?.message || 'unknown', |
| 38 | + }; |
| 39 | + reportActivity('grafana_infinity_health_check_executed', meta, instance_settings, plugin_meta); |
18 | 40 | };
|
19 | 41 |
|
20 |
| -export const reportQuery = (queries: InfinityQuery[] = [], instance_settings?: InfinityInstanceSettings, app = 'unknown') => { |
| 42 | +export const reportQuery = (queries: InfinityQuery[] = [], instance_settings?: InfinityInstanceSettings, plugin_meta?: DataSourcePluginMeta, app = 'unknown') => { |
21 | 43 | if (app === CoreApp.Dashboard || app === CoreApp.PanelViewer) {
|
22 | 44 | return;
|
23 | 45 | }
|
24 |
| - let input: Record<string, number | string> = {}; |
| 46 | + let meta: Record<string, number | string> = {}; |
25 | 47 | for (const query of queries) {
|
26 |
| - input['grafana_buildInfo_edition'] = config?.buildInfo?.edition || ''; |
27 |
| - input['grafana_buildInfo_version'] = config?.buildInfo?.version || ''; |
28 |
| - input['grafana_licenseInfo_stateInfo'] = config?.licenseInfo?.stateInfo || ''; |
29 |
| - if (instance_settings) { |
30 |
| - input['config_authType'] = instance_settings.jsonData?.authType || 'unknown'; |
31 |
| - input['config_oauth2_type'] = instance_settings.jsonData?.oauth2?.oauth2_type || 'unknown'; |
32 |
| - } |
33 |
| - input['query_type'] = query.type; |
34 |
| - input['query_source'] = (query as any).source || 'unknown'; |
35 |
| - input['query_parser'] = (query as any).parser || 'unknown'; |
| 48 | + meta['grafana_app'] = app; |
| 49 | + meta['query_type'] = (query as any).type || 'unknown'; |
| 50 | + meta['query_source'] = (query as any).source || 'unknown'; |
| 51 | + meta['query_parser'] = (query as any).parser || 'unknown'; |
| 52 | + meta['query_format'] = (query as any).format || 'unknown'; |
36 | 53 | const queryUrl = (query as any).url || '';
|
37 | 54 | if (queryUrl) {
|
38 | 55 | try {
|
39 | 56 | const baseUrl = new URL(queryUrl);
|
40 |
| - input['query_url_host'] = baseUrl.host || baseUrl.hostname; |
41 |
| - input['query_url_path'] = baseUrl.pathname; |
| 57 | + meta['query_url_host'] = baseUrl.host || baseUrl.hostname; |
42 | 58 | } catch (ex) {
|
43 | 59 | console.error(ex);
|
44 | 60 | }
|
45 | 61 | }
|
46 | 62 | if (isBackendQuery(query)) {
|
47 | 63 | if (query.summarizeExpression) {
|
48 |
| - input['query_summarizeExpression'] = 'in_use'; |
| 64 | + meta['query_summarizeExpression'] = 'in_use'; |
49 | 65 | }
|
50 | 66 | if (query.summarizeBy) {
|
51 |
| - input['query_summarizeBy'] = 'in_use'; |
| 67 | + meta['query_summarizeBy'] = 'in_use'; |
52 | 68 | }
|
53 | 69 | if (query.filterExpression) {
|
54 |
| - input['query_filterExpression'] = 'in_use'; |
| 70 | + meta['query_filterExpression'] = 'in_use'; |
55 | 71 | }
|
56 | 72 | if (query.computed_columns && query.computed_columns.length > 0) {
|
57 |
| - input['query_computed_columns'] = query.computed_columns.length; |
| 73 | + meta['query_computed_columns'] = query.computed_columns.length; |
58 | 74 | }
|
| 75 | + meta['query_pagination_mode'] = query.pagination_mode || 'none'; |
59 | 76 | }
|
60 |
| - reportActivity('grafana_infinity_query_executed', input); |
| 77 | + reportActivity('grafana_infinity_query_executed', meta, instance_settings, plugin_meta); |
61 | 78 | }
|
62 | 79 | };
|
0 commit comments