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

Bug 1801762: Don't re-run discovery on modified APIService #4285

Merged
merged 1 commit into from
Feb 11, 2020
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
14 changes: 13 additions & 1 deletion frontend/public/actions/k8s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,19 @@ export const watchAPIServices = () => (dispatch, getState) => {

k8sList(APIServiceModel, {})
.then(() =>
dispatch(watchK8sList(makeReduxID(APIServiceModel, {}), {}, APIServiceModel, getResources)),
dispatch(
watchK8sList(
makeReduxID(APIServiceModel, {}),
{},
APIServiceModel,
(id: string, events: K8sEvent[]) => {
// Only re-run API discovery on added or removed API services. A
// misbehaving API service can trigger frequent watch updates,
// which could cause console to thrash.
return events.some(({ type }) => type !== 'MODIFIED') ? getResources() : _.noop;
},
),
),
)
.catch(() => {
const poller = () =>
Expand Down
7 changes: 1 addition & 6 deletions frontend/public/module/k8s/get-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export type DiscoveryResources = {
safeResources: string[];
};

const getResources_ = () =>
export const getResources = () =>
coFetchJSON('api/kubernetes/apis').then((res) => {
const preferredVersions = res.groups.map((group) => group.preferredVersion);
const all: Promise<APIResourceList>[] = _.flatten(
Expand Down Expand Up @@ -152,11 +152,6 @@ const getResources_ = () =>
});
});

// Never attemp to re-run API discovery more than once every 30s. This will
// prevent the console from thrashing when one of the API services is
// misbehaving, which can cause frequent WebSocket updates.
export const getResources = _.throttle(getResources_, 30 * 1000);

export type APIResourceList = {
kind: 'APIResourceList';
apiVersion: 'v1';
Expand Down