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

Explore: Add feature tracking events #54514

Merged
merged 20 commits into from Sep 20, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions public/app/features/explore/ExploreQueryInspector.test.tsx
Expand Up @@ -29,6 +29,11 @@ jest.mock('app/core/services/context_srv', () => ({
},
}));

jest.mock('@grafana/runtime', () => ({
...jest.requireActual('@grafana/runtime'),
reportInteraction: () => null,
}));

const setup = (propOverrides = {}) => {
const props: ExploreQueryInspectorProps = {
loading: false,
Expand Down
7 changes: 6 additions & 1 deletion public/app/features/explore/ExploreQueryInspector.tsx
@@ -1,7 +1,8 @@
import React from 'react';
import React, { useEffect } from 'react';
import { connect, ConnectedProps } from 'react-redux';

import { CoreApp, TimeZone } from '@grafana/data';
import { reportInteraction } from '@grafana/runtime/src';
import { TabbedContainer, TabConfig } from '@grafana/ui';
import { ExploreDrawer } from 'app/features/explore/ExploreDrawer';
import { InspectDataTab } from 'app/features/inspector/InspectDataTab';
Expand All @@ -27,6 +28,10 @@ export function ExploreQueryInspector(props: Props) {
const dataFrames = queryResponse?.series || [];
const error = queryResponse?.error;

useEffect(() => {
reportInteraction('grafana_explore_query_inspector_opened');
}, []);

const statsTab: TabConfig = {
label: 'Stats',
value: 'stats',
Expand Down
6 changes: 6 additions & 0 deletions public/app/features/explore/ExploreTimeControls.tsx
@@ -1,6 +1,7 @@
import React, { Component } from 'react';

import { TimeRange, TimeZone, RawTimeRange, dateTimeForTimeZone, dateMath } from '@grafana/data';
import { reportInteraction } from '@grafana/runtime';
import { TimePickerWithHistory } from 'app/core/components/TimePicker/TimePickerWithHistory';
import { getShiftedTimeRange, getZoomedTimeRange } from 'app/core/utils/timePicker';
import { ExploreId } from 'app/types';
Expand Down Expand Up @@ -44,6 +45,11 @@ export class ExploreTimeControls extends Component<Props> {
from: adjustedFrom,
to: adjustedTo,
});

reportInteraction('grafana_explore_time_picker_time_range_changed', {
timeRangeFrom: adjustedFrom,
timeRangeTo: adjustedTo,
});
};

onZoom = () => {
Expand Down
28 changes: 22 additions & 6 deletions public/app/features/explore/ExploreToolbar.tsx
Expand Up @@ -38,7 +38,8 @@ type Props = OwnProps & ConnectedProps<typeof connector>;

class UnConnectedExploreToolbar extends PureComponent<Props> {
onChangeDatasource = async (dsSettings: DataSourceInstanceSettings) => {
this.props.changeDatasource(this.props.exploreId, dsSettings.uid, { importQueries: true });
const { changeDatasource, exploreId } = this.props;
changeDatasource(exploreId, dsSettings.uid, { importQueries: true });
};

onRunQuery = (loading = false) => {
Expand All @@ -60,6 +61,23 @@ class UnConnectedExploreToolbar extends PureComponent<Props> {
syncTimes(exploreId);
};

onCopyShortLink = async () => {
await createAndCopyShortLink(window.location.href);
reportInteraction('grafana_explore_shortened_link_clicked');
};

onOpenSplitView = () => {
const { split } = this.props;
split();
reportInteraction('grafana_explore_splitView_opened');
};

onCloseSplitView = () => {
const { closeSplit, exploreId } = this.props;
closeSplit(exploreId);
reportInteraction('grafana_explore_splitView_closed');
};

renderRefreshPicker = (showSmallTimePicker: boolean) => {
const { loading, refreshInterval, isLive } = this.props;

Expand Down Expand Up @@ -92,7 +110,6 @@ class UnConnectedExploreToolbar extends PureComponent<Props> {
render() {
const {
datasourceMissing,
closeSplit,
exploreId,
loading,
range,
Expand All @@ -102,7 +119,6 @@ class UnConnectedExploreToolbar extends PureComponent<Props> {
syncedTimes,
refreshInterval,
onChangeTime,
split,
hasLiveOption,
isLive,
isPaused,
Expand Down Expand Up @@ -131,7 +147,7 @@ class UnConnectedExploreToolbar extends PureComponent<Props> {
key="share"
tooltip="Copy shortened link"
icon="share-alt"
onClick={() => createAndCopyShortLink(window.location.href)}
onClick={this.onCopyShortLink}
aria-label="Copy shortened link"
/>
),
Expand All @@ -149,11 +165,11 @@ class UnConnectedExploreToolbar extends PureComponent<Props> {
>
<>
{!splitted ? (
<ToolbarButton tooltip="Split the pane" onClick={() => split()} icon="columns" disabled={isLive}>
<ToolbarButton tooltip="Split the pane" onClick={this.onOpenSplitView} icon="columns" disabled={isLive}>
Split
</ToolbarButton>
) : (
<ToolbarButton tooltip="Close split pane" onClick={() => closeSplit(exploreId)} icon="times">
<ToolbarButton tooltip="Close split pane" onClick={this.onCloseSplitView} icon="times">
Close
</ToolbarButton>
)}
Expand Down
5 changes: 5 additions & 0 deletions public/app/features/explore/QueryRows.test.tsx
Expand Up @@ -12,6 +12,11 @@ import { UserState } from '../profile/state/reducers';
import { QueryRows } from './QueryRows';
import { makeExplorePaneState } from './state/utils';

jest.mock('@grafana/runtime', () => ({
...jest.requireActual('@grafana/runtime'),
reportInteraction: () => null,
}));

function setup(queries: DataQuery[]) {
const defaultDs = {
name: 'newDs',
Expand Down
17 changes: 16 additions & 1 deletion public/app/features/explore/QueryRows.tsx
Expand Up @@ -3,7 +3,7 @@ import React, { useCallback, useMemo } from 'react';
import { useDispatch, useSelector } from 'react-redux';

import { CoreApp, DataQuery, DataSourceInstanceSettings } from '@grafana/data';
import { getDataSourceSrv } from '@grafana/runtime';
import { getDataSourceSrv, reportInteraction } from '@grafana/runtime';
import { getNextRefIdChar } from 'app/core/utils/query';
import { ExploreId } from 'app/types/explore';

Expand Down Expand Up @@ -73,6 +73,18 @@ export const QueryRows = ({ exploreId }: Props) => {
dispatch(importQueries(exploreId, queries, queryDatasource, targetDS, query.refId));
};

const onQueryCopied = () => {
reportInteraction('grafana_explore_query_row_copy');
};

const onQueryRemoved = () => {
reportInteraction('grafana_explore_query_row_remove');
};

const onQueryToggled = (queryStatus?: boolean) => {
reportInteraction('grafana_query_row_toggle', queryStatus === undefined ? {} : { queryEnabled: queryStatus });
};

return (
<QueryEditorRows
dsSettings={dsSettings}
Expand All @@ -81,6 +93,9 @@ export const QueryRows = ({ exploreId }: Props) => {
onQueriesChange={onChange}
onAddQuery={onAddQuery}
onRunQueries={onRunQueries}
onQueryCopied={onQueryCopied}
onQueryRemoved={onQueryRemoved}
onQueryToggled={onQueryToggled}
data={queryResponse}
app={CoreApp.Explore}
history={history}
Expand Down
29 changes: 23 additions & 6 deletions public/app/features/query/components/QueryEditorRow.tsx
Expand Up @@ -57,6 +57,9 @@ interface Props<TQuery extends DataQuery> {
history?: Array<HistoryItem<TQuery>>;
eventBus?: EventBusExtended;
alerting?: boolean;
onQueryCopied?: () => void;
onQueryRemoved?: () => void;
onQueryToggled?: (queryStatus?: boolean | undefined) => void;
L-M-K-B marked this conversation as resolved.
Show resolved Hide resolved
}

interface State<TQuery extends DataQuery> {
Expand Down Expand Up @@ -274,18 +277,32 @@ export class QueryEditorRow<TQuery extends DataQuery> extends PureComponent<Prop
};

onRemoveQuery = () => {
this.props.onRemoveQuery(this.props.query);
const { onRemoveQuery, query, onQueryRemoved } = this.props;
onRemoveQuery(query);

if (onQueryRemoved) {
onQueryRemoved();
}
};

onCopyQuery = () => {
const copy = cloneDeep(this.props.query);
this.props.onAddQuery(copy);
const { query, onAddQuery, onQueryCopied } = this.props;
const copy = cloneDeep(query);
onAddQuery(copy);

if (onQueryCopied) {
onQueryCopied();
}
};

onDisableQuery = () => {
const { query } = this.props;
this.props.onChange({ ...query, hide: !query.hide });
this.props.onRunQuery();
const { query, onChange, onRunQuery, onQueryToggled } = this.props;
onChange({ ...query, hide: !query.hide });
onRunQuery();

if (onQueryToggled) {
onQueryToggled(query.hide);
}
};

onToggleHelp = () => {
Expand Down
25 changes: 21 additions & 4 deletions public/app/features/query/components/QueryEditorRows.tsx
Expand Up @@ -31,7 +31,9 @@ interface Props {
app?: CoreApp;
history?: Array<HistoryItem<DataQuery>>;
eventBus?: EventBusExtended;

onQueryCopied?: () => void;
onQueryRemoved?: () => void;
onQueryToggled?: (queryStatus?: boolean | undefined) => void;
L-M-K-B marked this conversation as resolved.
Show resolved Hide resolved
onDatasourceChange?: (dataSource: DataSourceInstanceSettings, query: DataQuery) => void;
}

Expand Down Expand Up @@ -135,7 +137,19 @@ export class QueryEditorRows extends PureComponent<Props> {
};

render() {
const { dsSettings, data, queries, app, history, eventBus } = this.props;
const {
dsSettings,
data,
queries,
app,
history,
eventBus,
onAddQuery,
onRunQueries,
onQueryCopied,
onQueryRemoved,
onQueryToggled,
} = this.props;

return (
<DragDropContext onDragStart={this.onDragStart} onDragEnd={this.onDragEnd}>
Expand All @@ -160,8 +174,11 @@ export class QueryEditorRows extends PureComponent<Props> {
onChangeDataSource={onChangeDataSourceSettings}
onChange={(query) => this.onChangeQuery(query, index)}
onRemoveQuery={this.onRemoveQuery}
onAddQuery={this.props.onAddQuery}
onRunQuery={this.props.onRunQueries}
onAddQuery={onAddQuery}
onRunQuery={onRunQueries}
onQueryCopied={onQueryCopied}
onQueryRemoved={onQueryRemoved}
onQueryToggled={onQueryToggled}
queries={queries}
app={app}
history={history}
Expand Down