Skip to content

Commit 36e0af6

Browse files
authored
Add telemetry events when starting/stopping workbenches (opendatahub-io#913)
* Add telemetry events when starting/stopping workbenches * update type * update passing notebook name
1 parent 761e880 commit 36e0af6

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

frontend/src/pages/projects/notebook/NotebookStatusToggle.tsx

+27-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import useRefreshNotebookUntilStart from './useRefreshNotebookUntilStart';
66
import StopNotebookConfirmModal from './StopNotebookConfirmModal';
77
import useStopNotebookModalAvailability from './useStopNotebookModalAvailability';
88
import NotebookStatusText from './NotebookStatusText';
9+
import { fireTrackingEvent } from '../../../utilities/segmentIOUtils';
10+
import useNotebookGPUNumber from '../screens/detail/notebooks/useNotebookGPUNumber';
11+
import useNotebookDeploymentSize from '../screens/detail/notebooks/useNotebookDeploymentSize';
912

1013
type NotebookStatusToggleProps = {
1114
notebookState: NotebookState;
@@ -14,6 +17,8 @@ type NotebookStatusToggleProps = {
1417

1518
const NotebookStatusToggle: React.FC<NotebookStatusToggleProps> = ({ notebookState, doListen }) => {
1619
const { notebook, isStarting, isRunning, refresh } = notebookState;
20+
const gpuNumber = useNotebookGPUNumber(notebook);
21+
const { size } = useNotebookDeploymentSize(notebook);
1722
const [isOpenConfirm, setOpenConfirm] = React.useState(false);
1823
const [inProgress, setInProgress] = React.useState(false);
1924
const listenToNotebookStart = useRefreshNotebookUntilStart(notebookState, doListen);
@@ -34,13 +39,33 @@ const NotebookStatusToggle: React.FC<NotebookStatusToggleProps> = ({ notebookSta
3439
label = isRunning ? 'Running' : 'Stopped';
3540
}
3641

42+
const fireNotebookTrackingEvent = React.useCallback(
43+
(action: 'started' | 'stopped') => {
44+
fireTrackingEvent(`Workbench ${action}`, {
45+
GPU: gpuNumber,
46+
lastSelectedSize:
47+
size?.name ||
48+
notebook.metadata.annotations?.['notebooks.opendatahub.io/last-size-selection'],
49+
lastSelectedImage:
50+
notebook.metadata.annotations?.['notebooks.opendatahub.io/last-image-selection'],
51+
projectName: notebook.metadata.namespace,
52+
notebookName: notebook.metadata.name,
53+
...(action === 'stopped' && {
54+
lastActivity: notebook.metadata.annotations?.['notebooks.kubeflow.org/last-activity'],
55+
}),
56+
});
57+
},
58+
[gpuNumber, notebook, size],
59+
);
60+
3761
const handleStop = React.useCallback(() => {
62+
fireNotebookTrackingEvent('stopped');
3863
setInProgress(true);
3964
stopNotebook(notebookName, notebookNamespace).then(() => {
4065
refresh().then(() => setInProgress(false));
4166
listenToNotebookStart(false);
4267
});
43-
}, [notebookName, notebookNamespace, refresh, listenToNotebookStart]);
68+
}, [notebookName, notebookNamespace, refresh, listenToNotebookStart, fireNotebookTrackingEvent]);
4469

4570
return (
4671
<>
@@ -61,6 +86,7 @@ const NotebookStatusToggle: React.FC<NotebookStatusToggleProps> = ({ notebookSta
6186
} else {
6287
setInProgress(true);
6388
startNotebook(notebookName, notebookNamespace).then(() => {
89+
fireNotebookTrackingEvent('started');
6490
refresh().then(() => setInProgress(false));
6591
listenToNotebookStart(true);
6692
});

frontend/src/pages/projects/screens/spawner/SpawnerFooter.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ const SpawnerFooter: React.FC<SpawnerFooterProps> = ({
5757
!checkRequiredFieldsForNotebookStart(startNotebookData, storageData, envVariables);
5858
const { username } = useUser();
5959

60-
const afterStart = (type: 'created' | 'updated') => {
60+
const afterStart = (name: string, type: 'created' | 'updated') => {
6161
const { gpus, notebookSize, image } = startNotebookData;
6262
fireTrackingEvent(`Workbench ${type}`, {
6363
GPU: gpus,
6464
lastSelectedSize: notebookSize.name,
6565
lastSelectedImage: `${image.imageVersion?.from.name}`,
6666
projectName,
67+
notebookName: name,
6768
});
6869
refreshAllProjectData();
6970
navigate(`/projects/${projectName}`);
@@ -103,7 +104,7 @@ const SpawnerFooter: React.FC<SpawnerFooterProps> = ({
103104
tolerationSettings,
104105
};
105106
updateNotebook(editNotebook, newStartNotebookData, username)
106-
.then(() => afterStart('updated'))
107+
.then((notebook) => afterStart(notebook.metadata.name, 'updated'))
107108
.catch(handleError);
108109
}
109110
};
@@ -131,7 +132,7 @@ const SpawnerFooter: React.FC<SpawnerFooterProps> = ({
131132
};
132133

133134
createNotebook(newStartData, username)
134-
.then(() => afterStart('created'))
135+
.then((notebook) => afterStart(notebook.metadata.name, 'created'))
135136
.catch(handleError);
136137
};
137138

frontend/src/types.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,12 @@ export type TrackingEventProperties = {
282282
anonymousID?: string;
283283
type?: string;
284284
term?: string;
285-
GPU?: number;
285+
GPU?: GPUCount;
286286
lastSelectedSize?: string;
287287
lastSelectedImage?: string;
288288
projectName?: string;
289+
notebookName?: string;
290+
lastActivity?: string;
289291
};
290292

291293
export type NotebookPort = {

0 commit comments

Comments
 (0)