mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 10:03:33 -06:00
* Introduce Echo for collecting frontend metrics * Update public/app/core/services/echo/Echo.ts Co-Authored-By: Peter Holmberg <peterholmberg@users.noreply.github.com> * Custom meta when adding event * Rename consumer to backend * Remove buffer from Echo * Minor tweaks * Update package.json * Update public/app/app.ts * Update public/app/app.ts * Collect paint metrics when collecting tti. Remove echoBackendFactory * Update yarn.lock * Move Echo interfaces to runtime * progress on meta and echo * Collect meta analytics events * Move MetaanalyticsBackend to enterprise repo * Fixed unit tests * Removed unused type from test * Fixed issues with chunk loading (reverted index-template changes) * Restored changes * Fixed webpack prod
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import { getDashboardSrv } from '../services/DashboardSrv';
|
|
|
|
import { PanelData, LoadingState, DataSourceApi } from '@grafana/data';
|
|
|
|
import { reportMetaAnalytics, MetaAnalyticsEventPayload } from '@grafana/runtime';
|
|
|
|
export function getAnalyticsProcessor(datasource: DataSourceApi) {
|
|
let done = false;
|
|
|
|
return (data: PanelData) => {
|
|
if (!data.request || done) {
|
|
return;
|
|
}
|
|
|
|
if (data.state !== LoadingState.Done && data.state !== LoadingState.Error) {
|
|
return;
|
|
}
|
|
|
|
const eventData: MetaAnalyticsEventPayload = {
|
|
datasourceName: datasource.name,
|
|
datasourceId: datasource.id,
|
|
panelId: data.request.panelId,
|
|
dashboardId: data.request.dashboardId,
|
|
// app: 'dashboard',
|
|
// count: 1,
|
|
dataSize: 0,
|
|
duration: data.request.endTime - data.request.startTime,
|
|
eventName: 'data-request',
|
|
// sessionId: '',
|
|
};
|
|
|
|
// enrich with dashboard info
|
|
const dashboard = getDashboardSrv().getCurrent();
|
|
if (dashboard) {
|
|
eventData.dashboardId = dashboard.id;
|
|
eventData.dashboardName = dashboard.title;
|
|
eventData.dashboardUid = dashboard.uid;
|
|
eventData.folderName = dashboard.meta.folderTitle;
|
|
}
|
|
|
|
if (data.series.length > 0) {
|
|
// estimate size
|
|
eventData.dataSize = data.series.length * data.series[0].length;
|
|
}
|
|
|
|
if (data.error) {
|
|
eventData.error = data.error.message;
|
|
}
|
|
|
|
reportMetaAnalytics(eventData);
|
|
|
|
// this done check is to make sure we do not double emit events in case
|
|
// there are multiple responses with done state
|
|
done = true;
|
|
};
|
|
}
|