Skip to content

Commit

Permalink
Merge pull request #1688 from grafana/gareth/add-feature-tracking
Browse files Browse the repository at this point in the history
track executed queries and panel clicks
  • Loading branch information
gwdawson committed Sep 28, 2023
2 parents 4f69034 + 5143dd2 commit 209fea4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/datasource/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
toDataFrame,
} from '@grafana/data';
import { AnnotationQueryEditor } from './components/AnnotationQueryEditor';
import { trackRequest } from './tracking';

export class ZabbixDatasource extends DataSourceApi<ZabbixMetricsQuery, ZabbixDSOptions> {
name: string;
Expand Down Expand Up @@ -113,6 +114,8 @@ export class ZabbixDatasource extends DataSourceApi<ZabbixMetricsQuery, ZabbixDS
* @return {Object} Grafana metrics object with timeseries data for each target.
*/
query(request: DataQueryRequest<ZabbixMetricsQuery>) {
trackRequest(request);

// Migrate old targets
const requestTargets = request.targets.map((t) => {
// Prevent changes of original object
Expand Down
1 change: 1 addition & 0 deletions src/datasource/specs/datasource.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jest.mock(
getTemplateSrv: () => ({
replace: jest.fn().mockImplementation((query) => query),
}),
reportInteraction: jest.fn(),
}),
{ virtual: true }
);
Expand Down
46 changes: 46 additions & 0 deletions src/datasource/tracking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { DataQueryRequest } from '@grafana/data';
import { ZabbixMetricsQuery } from './types';
import { reportInteraction } from '@grafana/runtime';
import {
MODE_ITEMID,
MODE_ITSERVICE,
MODE_MACROS,
MODE_METRICS,
MODE_PROBLEMS,
MODE_TEXT,
MODE_TRIGGERS,
} from './constants';

export const trackRequest = (request: DataQueryRequest<ZabbixMetricsQuery>): void => {
request.targets.forEach((target) => {
const properties: any = {
app: request.app,
};

switch (target.queryType) {
case MODE_METRICS:
properties.queryType = 'Metrics';
break;
case MODE_ITSERVICE:
properties.queryType = 'Services';
break;
case MODE_TEXT:
properties.queryType = 'Text';
break;
case MODE_ITEMID:
properties.queryType = 'Item Id';
break;
case MODE_TRIGGERS:
properties.queryType = 'Triggers';
break;
case MODE_PROBLEMS:
properties.queryType = 'Problems';
break;
case MODE_MACROS:
properties.queryType = 'Macros';
break;
}

reportInteraction('grafana_zabbix_query_executed', properties);
});
};
11 changes: 10 additions & 1 deletion src/panel-triggers/components/Problems/Problems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ProblemDTO, ZBXAlert, ZBXEvent, ZBXTag } from '../../../datasource/type
import { APIExecuteScriptResponse, ZBXScript } from '../../../datasource/zabbix/connectors/zabbix_api/types';
import { AckCell } from './AckCell';
import { DataSourceRef, TimeRange } from '@grafana/data';
import { reportInteraction } from '@grafana/runtime';

export interface ProblemListProps {
problems: ProblemDTO[];
Expand Down Expand Up @@ -77,6 +78,8 @@ export default class ProblemList extends PureComponent<ProblemListProps, Problem
};

handleExpandedChange = (expanded: any, event: any) => {
reportInteraction('grafana_zabbix_panel_row_expanded', {});

const { problems, pageSize } = this.props;
const { page } = this.state;
const expandedProblems = {};
Expand Down Expand Up @@ -259,7 +262,13 @@ export default class ProblemList extends PureComponent<ProblemListProps, Problem
)}
expanded={this.getExpandedPage(this.state.page)}
onExpandedChange={this.handleExpandedChange}
onPageChange={(page) => this.setState({ page })}
onPageChange={(page) => {
reportInteraction('grafana_zabbix_panel_page_change', {
action: page > this.state.page ? 'next' : 'prev',
});

this.setState({ page });
}}
onPageSizeChange={this.handlePageSizeChange}
onResizedChange={this.handleResizedChange}
/>
Expand Down

0 comments on commit 209fea4

Please sign in to comment.