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

feat: User workspace start timeout defined in CheCluster CR #694

Merged
merged 2 commits into from
Dec 28, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/common/src/dto/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface IServerConfig {
timeouts: {
inactivityTimeout: number;
runTimeout: number;
startTimeout: number;
};
cheNamespace: string;
}
Expand Down
13 changes: 13 additions & 0 deletions packages/dashboard-backend/src/constants/server-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2018-2021 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

export const startTimeoutSeconds = 300; // 5 minutes
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '../types';
import { createError } from './helpers/createError';
import { CustomObjectAPI, prepareCustomObjectAPI } from './helpers/prepareCustomObjectAPI';
import { startTimeoutSeconds } from '../../constants/server-config';

const CUSTOM_RESOURCE_DEFINITIONS_API_ERROR_LABEL = 'CUSTOM_RESOURCE_DEFINITIONS_API_ERROR';

Expand Down Expand Up @@ -121,4 +122,8 @@ export class ServerConfigApiService implements IServerConfigApi {
getWorkspaceRunTimeout(cheCustomResource: CustomResourceDefinition): number {
return cheCustomResource.spec.devEnvironments?.secondsOfRunBeforeIdling || -1;
}

getWorkspaceStartTimeout(cheCustomResource: CustomResourceDefinition): number {
return cheCustomResource.spec.devEnvironments?.startTimeoutSeconds || startTimeoutSeconds;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export type CustomResourceDefinitionSpecDevEnvironments = {
disableContainerBuildCapabilities?: boolean;
secondsOfInactivityBeforeIdling?: number;
secondsOfRunBeforeIdling?: number;
startTimeoutSeconds?: number;
storage?: {
pvcStrategy?: string;
};
Expand Down Expand Up @@ -192,6 +193,11 @@ export interface IServerConfigApi {
* Returns the workspace run timeout
*/
getWorkspaceRunTimeout(cheCustomResource: CustomResourceDefinition): number;

/**
* Returns the workspace start timeout
*/
getWorkspaceStartTimeout(cheCustomResource: CustomResourceDefinition): number;
}

export interface IKubeConfigApi {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Server Config Route', () => {
},
defaults: { components: [], plugins: [], pvcStrategy: '' },
pluginRegistry: { openVSXURL: 'openvsx-url' },
timeouts: { inactivityTimeout: 0, runTimeout: 0 },
timeouts: { inactivityTimeout: 0, runTimeout: 0, startTimeout: 0 },
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const stubPvcStrategy = '';
export const stubRunningWorkspacesLimit = 2;
export const stubWorkspaceInactivityTimeout = 0;
export const stubWorkspaceRunTimeout = 0;
export const stubWorkspaceStartupTimeout = 0;

export const stubDevWorkspacesList: IDevWorkspaceList = {
apiVersion: 'workspace.devfile.io/v1alpha2',
Expand Down Expand Up @@ -90,6 +91,7 @@ export function getDevWorkspaceClient(_args: Parameters<typeof helper>): ReturnT
getRunningWorkspacesLimit: _cheCustomResource => stubRunningWorkspacesLimit,
getWorkspaceInactivityTimeout: _cheCustomResource => stubWorkspaceInactivityTimeout,
getWorkspaceRunTimeout: _cheCustomResource => stubWorkspaceRunTimeout,
getWorkspaceStartTimeout: _cheCustomResource => stubWorkspaceStartupTimeout,
} as IServerConfigApi,
devworkspaceApi: {
create: (_devworkspace, _namespace) => Promise.resolve(stubDevWorkspace),
Expand Down
2 changes: 2 additions & 0 deletions packages/dashboard-backend/src/routes/api/serverConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function registerServerConfigRoute(server: FastifyInstance) {
const components = serverConfigApi.getDefaultComponents(cheCustomResource);
const inactivityTimeout = serverConfigApi.getWorkspaceInactivityTimeout(cheCustomResource);
const runTimeout = serverConfigApi.getWorkspaceRunTimeout(cheCustomResource);
const startTimeout = serverConfigApi.getWorkspaceStartTimeout(cheCustomResource);
const openVSXURL = serverConfigApi.getOpenVSXURL(cheCustomResource);
const pvcStrategy = serverConfigApi.getPvcStrategy(cheCustomResource);

Expand All @@ -47,6 +48,7 @@ export function registerServerConfigRoute(server: FastifyInstance) {
timeouts: {
inactivityTimeout,
runTimeout,
startTimeout,
},
pluginRegistry: {
openVSXURL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import {
buildLoaderSteps,
getWorkspaceLoadingSteps,
} from '../../../../../../components/Loader/Step/buildSteps';
import { MIN_STEP_DURATION_MS, TIMEOUT_TO_RUN_SEC } from '../../../../const';
import { MIN_STEP_DURATION_MS } from '../../../../const';
import getComponentRenderer from '../../../../../../services/__mocks__/getComponentRenderer';
import StepStartWorkspace, { State } from '..';
import { StateMock } from '@react-mock/state';
import { api } from '@eclipse-che/common';

jest.mock('../../../../../../pages/Loader/Workspace');

Expand Down Expand Up @@ -61,6 +62,25 @@ const matchParams: WorkspaceParams = {
const stepId = LoadingStep.START_WORKSPACE.toString();
const currentStepIndex = 2;
const loadingSteps = getWorkspaceLoadingSteps();
const startTimeout = 300;
const serverConfig: api.IServerConfig = {
containerBuild: {},
defaults: {
editor: undefined,
components: [],
plugins: [],
pvcStrategy: '',
},
pluginRegistry: {
openVSXURL: '',
},
timeouts: {
inactivityTimeout: -1,
runTimeout: -1,
startTimeout,
},
cheNamespace: '',
};

describe('Workspace Loader, step START_WORKSPACE', () => {
let loaderSteps: List<LoaderStep>;
Expand Down Expand Up @@ -253,6 +273,7 @@ describe('Workspace Loader, step START_WORKSPACE', () => {

test('workspace is STARTING more than TIMEOUT_TO_RUN_SEC seconds', async () => {
const store = new FakeStoreBuilder()
.withDwServerConfig(serverConfig)
.withDevWorkspaces({
workspaces: [
new DevWorkspaceBuilder()
Expand All @@ -278,7 +299,7 @@ describe('Workspace Loader, step START_WORKSPACE', () => {
expect(hasError.textContent).toEqual('false');

// wait a bit more than necessary to end the workspace run timeout
const time = (TIMEOUT_TO_RUN_SEC + 1) * 1000;
const time = (startTimeout + 1) * 1000;
jest.advanceTimersByTime(time);

// there should be the error message
Expand All @@ -297,6 +318,7 @@ describe('Workspace Loader, step START_WORKSPACE', () => {

test('workspace is STARTING then RUNNING', async () => {
const store = new FakeStoreBuilder()
.withDwServerConfig(serverConfig)
.withDevWorkspaces({
workspaces: [
new DevWorkspaceBuilder()
Expand All @@ -316,7 +338,7 @@ describe('Workspace Loader, step START_WORKSPACE', () => {
await waitFor(() => expect(currentStepId.textContent).toEqual(stepId));

// wait less than necessary to end the workspace run timeout
const time = (TIMEOUT_TO_RUN_SEC - 1) * 1000;
const time = (startTimeout - 1) * 1000;
jest.advanceTimersByTime(time);

const currentStep = screen.getByTestId(stepId);
Expand Down Expand Up @@ -346,6 +368,7 @@ describe('Workspace Loader, step START_WORKSPACE', () => {

test('workspace is STARTING then STOPPING', async () => {
const store = new FakeStoreBuilder()
.withDwServerConfig(serverConfig)
.withDevWorkspaces({
workspaces: [
new DevWorkspaceBuilder()
Expand All @@ -365,7 +388,7 @@ describe('Workspace Loader, step START_WORKSPACE', () => {
await waitFor(() => expect(currentStepId.textContent).toEqual(stepId));

// wait less than necessary to end the workspace run timeout
const time = (TIMEOUT_TO_RUN_SEC - 1) * 1000;
const time = (startTimeout - 1) * 1000;
jest.advanceTimersByTime(time);

const currentStep = screen.getByTestId(stepId);
Expand Down Expand Up @@ -409,6 +432,7 @@ describe('Workspace Loader, step START_WORKSPACE', () => {

test('workspace is STARTING then STOPPED', async () => {
const store = new FakeStoreBuilder()
.withDwServerConfig(serverConfig)
.withDevWorkspaces({
workspaces: [
new DevWorkspaceBuilder()
Expand All @@ -428,7 +452,7 @@ describe('Workspace Loader, step START_WORKSPACE', () => {
await waitFor(() => expect(currentStepId.textContent).toEqual(stepId));

// wait less than necessary to end the workspace run timeout
const time = (TIMEOUT_TO_RUN_SEC - 1) * 1000;
const time = (startTimeout - 1) * 1000;
jest.advanceTimersByTime(time);

const currentStep = screen.getByTestId(stepId);
Expand Down Expand Up @@ -472,6 +496,7 @@ describe('Workspace Loader, step START_WORKSPACE', () => {

test('workspace is STARTING then FAILING', async () => {
const store = new FakeStoreBuilder()
.withDwServerConfig(serverConfig)
.withDevWorkspaces({
workspaces: [
new DevWorkspaceBuilder()
Expand All @@ -491,7 +516,7 @@ describe('Workspace Loader, step START_WORKSPACE', () => {
await waitFor(() => expect(currentStepId.textContent).toEqual(stepId));

// wait less than necessary to end the workspace run timeout
const time = (TIMEOUT_TO_RUN_SEC - 1) * 1000;
const time = (startTimeout - 1) * 1000;
jest.advanceTimersByTime(time);

const currentStep = screen.getByTestId(stepId);
Expand Down Expand Up @@ -535,6 +560,7 @@ describe('Workspace Loader, step START_WORKSPACE', () => {

test('workspace is STARTING then FAILED', async () => {
const store = new FakeStoreBuilder()
.withDwServerConfig(serverConfig)
.withDevWorkspaces({
workspaces: [
new DevWorkspaceBuilder()
Expand All @@ -554,7 +580,7 @@ describe('Workspace Loader, step START_WORKSPACE', () => {
await waitFor(() => expect(currentStepId.textContent).toEqual(stepId));

// wait less than necessary to end the workspace run timeout
const time = (TIMEOUT_TO_RUN_SEC - 1) * 1000;
const time = (startTimeout - 1) * 1000;
jest.advanceTimersByTime(time);

const currentStep = screen.getByTestId(stepId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import { AlertItem, DevWorkspaceStatus, LoaderTab } from '../../../../../service
import { DisposableCollection } from '../../../../../services/helpers/disposable';
import { delay } from '../../../../../services/helpers/delay';
import { filterErrorLogs } from '../../../../../services/helpers/filterErrorLogs';
import { MIN_STEP_DURATION_MS, TIMEOUT_TO_RUN_SEC } from '../../../const';
import { MIN_STEP_DURATION_MS } from '../../../const';
import findTargetWorkspace from '../../../findTargetWorkspace';
import workspaceStatusIs from '../workspaceStatusIs';
import { Workspace } from '../../../../../services/workspace-adapter';
import { AbstractLoaderStep, LoaderStepProps, LoaderStepState } from '../../../AbstractStep';
import { selectStartTimeout } from '../../../../../store/ServerConfig/selectors';

export type Props = MappedProps &
LoaderStepProps & {
Expand Down Expand Up @@ -143,7 +144,7 @@ class StepStartWorkspace extends AbstractLoaderStep<Props, State> {
await new Promise<void>((resolve, reject) => {
const timeoutId = window.setTimeout(() => {
reject();
}, TIMEOUT_TO_RUN_SEC * 1000);
}, this.props.startTimeout * 1000);
this.toDispose.push({
dispose: () => {
window.clearTimeout(timeoutId);
Expand All @@ -156,7 +157,7 @@ class StepStartWorkspace extends AbstractLoaderStep<Props, State> {
return false;
} catch (e) {
throw new Error(
`The workspace status remains "${workspace.status}" in the last ${TIMEOUT_TO_RUN_SEC} seconds.`,
`The workspace status remains "${workspace.status}" in the last ${this.props.startTimeout} seconds.`,
);
}
}
Expand Down Expand Up @@ -226,6 +227,7 @@ class StepStartWorkspace extends AbstractLoaderStep<Props, State> {
const mapStateToProps = (state: AppState) => ({
allWorkspaces: selectAllWorkspaces(state),
workspacesLogs: selectLogs(state),
startTimeout: selectStartTimeout(state),
});

const connector = connect(mapStateToProps, WorkspaceStore.actionCreators, null, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ export const MIN_STEP_DURATION_MS = 200;
export const TIMEOUT_TO_CREATE_SEC = 20;
export const TIMEOUT_TO_GET_URL_SEC = 20;
export const TIMEOUT_TO_RESOLVE_SEC = 20;
export const TIMEOUT_TO_RUN_SEC = 5 * 60;
export const TIMEOUT_TO_STOP_SEC = 60;
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ describe('dwPlugins store', () => {
timeouts: {
inactivityTimeout: -1,
runTimeout: -1,
startTimeout: 300,
},
cheNamespace: 'eclipse-che',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('dwPlugins store', () => {
timeouts: {
inactivityTimeout: -1,
runTimeout: -1,
startTimeout: 300,
},
cheNamespace: 'eclipse-che',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const unloadedState: State = {
timeouts: {
inactivityTimeout: -1,
runTimeout: -1,
startTimeout: 300,
},
cheNamespace: '',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ export const selectPvcStrategy = createSelector(
state => (state.config.defaults.pvcStrategy || '') as che.WorkspaceStorageType,
);

export const selectStartTimeout = createSelector(
selectState,
state => state.config.timeouts.startTimeout,
);

export const selectServerConfigError = createSelector(selectState, state => state.error);
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class FakeStoreBuilder {
timeouts: {
inactivityTimeout: -1,
runTimeout: -1,
startTimeout: 300,
},
cheNamespace: '',
} as api.IServerConfig,
Expand Down