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

track executed queries and panel clicks #1688

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 => {
gwdawson marked this conversation as resolved.
Show resolved Hide resolved
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