Skip to content

Commit

Permalink
Improve performance in nb-events (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucferbux authored Oct 6, 2022
1 parent 5e9f2bc commit 64da86e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
16 changes: 10 additions & 6 deletions backend/src/routes/api/nb-events/eventUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ export const getNotebookEvents = async (
namespace: string,
nbName: string,
): Promise<V1Event[]> => {
const eventList = await fastify.kube.coreV1Api
.listNamespacedEvent(namespace, undefined, undefined, undefined, 'involvedObject.kind=Pod')
return fastify.kube.coreV1Api
.listNamespacedEvent(
namespace,
undefined,
undefined,
undefined,
`involvedObject.kind=Pod,involvedObject.name=${nbName}-0`,
)
.then((res) => {
return res.body as V1EventList;
const body = res.body as V1EventList;
return body.items;
});

// Filter the events by pods that have the same name as the notebook
return eventList.items.filter((event) => event.involvedObject.name.startsWith(nbName));
};
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const StartServerModal: React.FC<StartServerModalProps> = ({ open, spawnInProgre
const [logsExpanded, setLogsExpanded] = React.useState<boolean>(false);
const [spawnPercentile, setSpawnPercentile] = React.useState<number>(0);
const [spawnStatus, setSpawnStatus] = React.useState<SpawnStatus | null>(null);
const [unstableNotebookStatus, events] = useNotebookStatus(spawnInProgress);
const [unstableNotebookStatus, events] = useNotebookStatus(spawnInProgress && !isNotebookRunning);
const [isUsingCurrentTab] = useBrowserTabPreference();
const notebookStatus = useDeepCompareMemoize(unstableNotebookStatus);
const getNotebookLink = useNotebookRedirectLink();
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/utilities/useWatchNotebookEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ export const useWatchNotebookEvents = (
.catch((e) => {
notification.error('Error fetching notebook events', e.response.data.message);
clear();
})
.finally(() => {
watchHandle = setTimeout(watchNotebookEvents, FAST_POLL_INTERVAL);
});
watchHandle = setTimeout(watchNotebookEvents, FAST_POLL_INTERVAL);
}
};

watchNotebookEvents();
}
return clear;
Expand Down

0 comments on commit 64da86e

Please sign in to comment.