Skip to content

Commit

Permalink
Bug 1801762: Don't re-run discovery on modified APIService
Browse files Browse the repository at this point in the history
Only re-run discovery when an APIService is added or removed. This
prevents the console from thrashing when an APIService is unhealthy.

https://bugzilla.redhat.com/show_bug.cgi?id=1801762
  • Loading branch information
spadgett committed Feb 11, 2020
1 parent e57533e commit 81da92e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
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

0 comments on commit 81da92e

Please sign in to comment.