Skip to content

Commit

Permalink
Tighter default interval and timeout for cluster admin tab refresh
Browse files Browse the repository at this point in the history
+ Report connectivity issues more quickly.
+ Allow values to be optionally configured via `xhAdminAppConfig`.
  • Loading branch information
amcclain committed Nov 21, 2024
1 parent 2975272 commit 22c3f9a
Showing 1 changed file with 35 additions and 15 deletions.
50 changes: 35 additions & 15 deletions admin/tabs/cluster/ClusterTabModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
}
Expand All @@ -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,
Expand All @@ -78,7 +87,7 @@ export class ClusterTabModel extends HoistModel {
runFn: () => {
if (this.tabModel?.isActive) this.autoRefreshAsync();
},
interval: 5 * SECONDS,
interval: this.autoRefreshInterval,
delay: true
});

Expand All @@ -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: {
Expand Down Expand Up @@ -161,7 +180,7 @@ export class ClusterTabModel extends HoistModel {
});
}

createTabContainerModel() {
private createTabContainerModel() {
return new TabContainerModel({
route: 'default.cluster',
switcher: false,
Expand All @@ -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}?`,
Expand All @@ -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;
}
}

0 comments on commit 22c3f9a

Please sign in to comment.