Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated rudderstack events #761

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/friendly-months-tell.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'grafana-infinity-datasource': patch
---

Fixed a bug where query columns editor is unusable when sanbox enabled
Fixed a bug where query columns editor is unusable when sandbox enabled
5 changes: 5 additions & 0 deletions .changeset/late-hats-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'grafana-infinity-datasource': patch
---

Updated rudderstack analytics events
1 change: 1 addition & 0 deletions cspell.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"popperjs",
"prismjs",
"promhttp",
"rudderstack",
"scroller",
"seriesgen",
"sigv",
Expand Down
9 changes: 4 additions & 5 deletions src/datasource.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LoadingState, toDataFrame, DataFrame, DataQueryRequest, DataQueryResponse, ScopedVars, TimeRange } from '@grafana/data';
import { DataSourceWithBackend } from '@grafana/runtime';
import { DataSourceWithBackend, HealthStatus } from '@grafana/runtime';
import { flatten, sample } from 'lodash';
import { Observable } from 'rxjs';
import { applyGroq } from './app/GROQProvider';
Expand All @@ -25,7 +25,7 @@ export class Datasource extends DataSourceWithBackend<InfinityQuery, InfinityOpt
query(options: DataQueryRequest<InfinityQuery>): Observable<DataQueryResponse> {
return new Observable<DataQueryResponse>((subscriber) => {
let request = getUpdatedDataRequest(options, this.instanceSettings);
reportQuery(request?.targets || [], this.instanceSettings, request?.app);
reportQuery(request?.targets || [], this.instanceSettings, this.meta, request?.app);
super
.query(request)
.toPromise()
Expand Down Expand Up @@ -98,17 +98,16 @@ export class Datasource extends DataSourceWithBackend<InfinityQuery, InfinityOpt
return super
.testDatasource()
.then((o) => {
reportHealthCheck(o, this.instanceSettings, this.meta);
switch (o?.message) {
case 'OK':
reportHealthCheck({ status: 'success', message: 'OK. Settings saved', authMethod: this.instanceSettings?.jsonData?.auth_method || '' });
return Promise.resolve({ status: 'success', message: 'OK. Settings saved' });
default:
reportHealthCheck({ status: o?.status || 'success', message: o?.message || 'Settings saved' });
return Promise.resolve({ status: o?.status || 'success', message: o?.message || 'Settings saved' });
}
})
.catch((ex) => {
reportHealthCheck({ status: 'error', message: ex.message });
reportHealthCheck({ status: HealthStatus.Error, message: ex }, this.instanceSettings, this.meta);
return Promise.resolve({ status: 'error', message: ex.message });
});
}
Expand Down
66 changes: 41 additions & 25 deletions src/utils/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,78 @@
import { CoreApp } from '@grafana/data';
import { reportInteraction, config } from '@grafana/runtime';
import { CoreApp, DataSourcePluginMeta } from '@grafana/data';
import { reportInteraction, config, HealthCheckResult } from '@grafana/runtime';
import { isBackendQuery } from './../app/utils';
import { InfinityInstanceSettings, InfinityQuery } from './../types';

type Report_Action = 'grafana_infinity_query_executed' | 'grafana_infinity_health_check_executed';

const reportActivity = (action: Report_Action, meta?: Record<string, any>) => {
const reportActivity = (action: Report_Action, data: Record<string, any> = {}, instance_settings?: InfinityInstanceSettings, plugin_meta?: DataSourcePluginMeta) => {
try {
reportInteraction(action, { ...meta, plugin_name: 'yesoreyeram-infinity-datasource', ts: new Date().getTime() });
// Grafana related meta
data['grafana_licenseInfo_stateInfo'] = config?.licenseInfo?.stateInfo || '';
data['grafana_buildInfo_edition'] = config?.buildInfo?.edition || '';
data['grafana_buildInfo_version'] = config?.buildInfo?.version || '';
data['grafana_buildInfo_version_short'] = (config?.buildInfo?.version || '').split('-')[0];
data['grafana_app_url'] = config?.appUrl || '';
const grafana_url = new URL(window?.document?.URL);
data['grafana_host'] = grafana_url?.host || grafana_url?.hostname || 'unknown';
// Plugin meta
data['plugin_id'] = plugin_meta?.id || 'yesoreyeram-infinity-datasource';
data['plugin_version'] = plugin_meta?.info?.version || 'unknown';
// Plugin configuration
data['config_authType'] = instance_settings?.jsonData?.auth_method || instance_settings?.jsonData?.authType || 'unknown';
data['config_oauth2_type'] = instance_settings?.jsonData?.oauth2?.oauth2_type || 'unknown';
data['config_global_queries_count'] = (instance_settings?.jsonData?.global_queries || []).length;
data['config_reference_data_count'] = (instance_settings?.jsonData?.refData || []).length;
data['config_allowed_hosts_count'] = (instance_settings?.jsonData.allowedHosts || []).length;
reportInteraction(action, { ...data, ts: new Date().getTime() });
} catch (ex) {
console.error('error while reporting infinity query', ex);
}
};

export const reportHealthCheck = (meta: Record<string, string> = {}) => {
reportActivity('grafana_infinity_health_check_executed', meta);
export const reportHealthCheck = (o?: Omit<HealthCheckResult, 'details'>, instance_settings?: InfinityInstanceSettings, plugin_meta?: DataSourcePluginMeta) => {
let meta: Record<string, any> = {
plugin_healthcheck_status: o?.status || 'unknown',
plugin_healthcheck_message: o?.message || 'unknown',
};
reportActivity('grafana_infinity_health_check_executed', meta, instance_settings, plugin_meta);
};

export const reportQuery = (queries: InfinityQuery[] = [], instance_settings?: InfinityInstanceSettings, app = 'unknown') => {
export const reportQuery = (queries: InfinityQuery[] = [], instance_settings?: InfinityInstanceSettings, plugin_meta?: DataSourcePluginMeta, app = 'unknown') => {
if (app === CoreApp.Dashboard || app === CoreApp.PanelViewer) {
return;
}
let input: Record<string, number | string> = {};
let meta: Record<string, number | string> = {};
for (const query of queries) {
input['grafana_buildInfo_edition'] = config?.buildInfo?.edition || '';
input['grafana_buildInfo_version'] = config?.buildInfo?.version || '';
input['grafana_licenseInfo_stateInfo'] = config?.licenseInfo?.stateInfo || '';
if (instance_settings) {
input['config_authType'] = instance_settings.jsonData?.authType || 'unknown';
input['config_oauth2_type'] = instance_settings.jsonData?.oauth2?.oauth2_type || 'unknown';
}
input['query_type'] = query.type;
input['query_source'] = (query as any).source || 'unknown';
input['query_parser'] = (query as any).parser || 'unknown';
meta['grafana_app'] = app;
meta['query_type'] = (query as any).type || 'unknown';
meta['query_source'] = (query as any).source || 'unknown';
meta['query_parser'] = (query as any).parser || 'unknown';
meta['query_format'] = (query as any).format || 'unknown';
const queryUrl = (query as any).url || '';
if (queryUrl) {
try {
const baseUrl = new URL(queryUrl);
input['query_url_host'] = baseUrl.host || baseUrl.hostname;
input['query_url_path'] = baseUrl.pathname;
meta['query_url_host'] = baseUrl.host || baseUrl.hostname;
} catch (ex) {
console.error(ex);
}
}
if (isBackendQuery(query)) {
if (query.summarizeExpression) {
input['query_summarizeExpression'] = 'in_use';
meta['query_summarizeExpression'] = 'in_use';
}
if (query.summarizeBy) {
input['query_summarizeBy'] = 'in_use';
meta['query_summarizeBy'] = 'in_use';
}
if (query.filterExpression) {
input['query_filterExpression'] = 'in_use';
meta['query_filterExpression'] = 'in_use';
}
if (query.computed_columns && query.computed_columns.length > 0) {
input['query_computed_columns'] = query.computed_columns.length;
meta['query_computed_columns'] = query.computed_columns.length;
}
meta['query_pagination_mode'] = query.pagination_mode || 'none';
}
reportActivity('grafana_infinity_query_executed', input);
reportActivity('grafana_infinity_query_executed', meta, instance_settings, plugin_meta);
}
};
Loading