From 22c3f9afe60ac2677cac8b125160ebc239486e49 Mon Sep 17 00:00:00 2001 From: Anselm McClain Date: Thu, 21 Nov 2024 12:21:23 -0800 Subject: [PATCH] Tighter default interval and timeout for cluster admin tab refresh + Report connectivity issues more quickly. + Allow values to be optionally configured via `xhAdminAppConfig`. --- admin/tabs/cluster/ClusterTabModel.ts | 50 +++++++++++++++++++-------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/admin/tabs/cluster/ClusterTabModel.ts b/admin/tabs/cluster/ClusterTabModel.ts index df452a22b..7554c10ab 100644 --- a/admin/tabs/cluster/ClusterTabModel.ts +++ b/admin/tabs/cluster/ClusterTabModel.ts @@ -32,6 +32,10 @@ export class ClusterTabModel extends HoistModel { @lookup(TabModel) private tabModel: TabModel; + @managed readonly gridModel: GridModel = this.createGridModel(); + @managed readonly tabContainerModel: TabContainerModel = this.createTabContainerModel(); + @managed readonly timer: Timer; + shutdownAction: RecordActionSpec = { icon: Icon.skull(), text: 'Shutdown Instance', @@ -41,10 +45,6 @@ export class ClusterTabModel extends HoistModel { recordsRequired: 1 }; - @managed readonly gridModel: GridModel = this.createGridModel(); - @managed readonly tabContainerModel: TabContainerModel = this.createTabContainerModel(); - @managed readonly timer: Timer; - get instance(): PlainObject { return this.gridModel.selectedRecord?.data; } @@ -59,7 +59,16 @@ export class ClusterTabModel extends HoistModel { override async doLoadAsync(loadSpec: LoadSpec) { const {gridModel} = this; - let data = await XH.fetchJson({url: 'clusterAdmin/allInstances', loadSpec}); + + let data = await XH.fetchJson({ + url: 'clusterAdmin/allInstances', + // Tighter default timeout for background auto-refresh, to ensure we report connectivity + // issues promptly. This call should be quick, but still allow full default timeout for + // a manual refresh. + timeout: loadSpec.isAutoRefresh ? this.autoRefreshTimeout : undefined, + loadSpec + }); + data = data.map(row => ({ ...row, isLocal: row.name == XH.environmentService.serverInstance, @@ -78,7 +87,7 @@ export class ClusterTabModel extends HoistModel { runFn: () => { if (this.tabModel?.isActive) this.autoRefreshAsync(); }, - interval: 5 * SECONDS, + interval: this.autoRefreshInterval, delay: true }); @@ -96,6 +105,16 @@ export class ClusterTabModel extends HoistModel { ); } + formatInstance(instance: PlainObject): ReactNode { + const content = [instance.name]; + if (instance.isPrimary) content.push(badge({item: 'primary', intent: 'primary'})); + if (instance.isLocal) content.push(badge('local')); + return hbox(content); + } + + //------------------ + // Implementation + //------------------ private createGridModel() { return new GridModel({ store: { @@ -161,7 +180,7 @@ export class ClusterTabModel extends HoistModel { }); } - createTabContainerModel() { + private createTabContainerModel() { return new TabContainerModel({ route: 'default.cluster', switcher: false, @@ -187,14 +206,7 @@ export class ClusterTabModel extends HoistModel { }); } - formatInstance(instance: PlainObject): ReactNode { - const content = [instance.name]; - if (instance.isPrimary) content.push(badge({item: 'primary', intent: 'primary'})); - if (instance.isLocal) content.push(badge('local')); - return hbox(content); - } - - async shutdownInstanceAsync(instance: PlainObject) { + private async shutdownInstanceAsync(instance: PlainObject) { if ( !(await XH.confirm({ message: `Are you SURE you want to shutdown instance ${instance.name}?`, @@ -216,4 +228,12 @@ export class ClusterTabModel extends HoistModel { .linkTo({observer: this.loadModel, message: 'Attempting instance shutdown'}) .catchDefault(); } + + private get autoRefreshInterval(): number { + return XH.getConf('xhAdminAppConfig', {}).clusterTabAutoRefreshInterval ?? 4 * SECONDS; + } + + private get autoRefreshTimeout(): number { + return XH.getConf('xhAdminAppConfig', {}).clusterTabAutoRefreshTimeout ?? 2 * SECONDS; + } }