Path: blob/main/components/gitpod-protocol/src/workspace-instance.ts
2498 views
/**1* Copyright (c) 2020 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { EnvVar, NamedWorkspaceFeatureFlag, TaskConfig } from "./protocol";7import { WorkspaceRegion } from "./workspace-cluster";89// WorkspaceInstance describes a part of a workspace's lifetime, specifically a single running session of it10export interface WorkspaceInstance {11// ID is the unique identifier of this instance12id: string;1314// workspaceId is the unique identifier of the workspace this is an instance of15workspaceId: string;1617// The time an instance has been created in the backend (before DB!)18creationTime: string;1920// The time an instance has switched phase to 'Pending'21deployedTime?: string;2223// The time an instance has switched phase to 'Running'24startedTime?: string;2526// The time an instance has switched phase to 'Stopping' */27stoppingTime?: string;2829// The time an instance has switched phase to 'Stopped' */30stoppedTime?: string;3132// ideUrl is the URL at which the workspace is available on the internet33// Note: this is initially empty, filled during starting process!34ideUrl: string;3536// region is the name of the workspace cluster this instance runs in37// Note: this is initially empty, filled during starting process!38region: string;3940// workspaceImage is the name of the Docker image this instance runs41// Note: this is initially empty, filled during starting process!42workspaceImage: string;4344// status is the latest status of the instance that we're aware of45status: WorkspaceInstanceStatus;4647// repo contains information about the Git working copy inside the workspace48gitStatus?: WorkspaceInstanceRepoStatus;4950// configuration captures the per-instance configuration variance of a workspace51configuration: WorkspaceInstanceConfiguration;5253// instance is hard-deleted on the database and about to be collected by periodic deleter54readonly deleted?: boolean;5556/**57* Contains information about the image build, if there was any58*/59imageBuildInfo?: ImageBuildInfo;6061/**62* workspace class, also known as workspace size, determines the type of63* resources that are provided to the workspace.64*/65workspaceClass?: string;6667/**68* Identifies the team or user to which this instance's runtime should be attributed to69* (e.g. for usage analytics or billing purposes).70*/71usageAttributionId?: string;72}7374// WorkspaceInstanceStatus describes the current state of a workspace instance75export interface WorkspaceInstanceStatus {76// version is the current version of the workspace instance status77// Note: consider this value opaque. The only guarantee given is that it imposes78// a partial order on status updates, i.e. a.version > b.version -> a newer than b.79version?: number;8081// phase describes a high-level state of the workspace instance82phase: WorkspaceInstancePhase;8384// conditions further specify the phase85conditions: WorkspaceInstanceConditions;8687// message is a user-readable message containing information about the workspace88message?: string;8990// exposedPorts is the list of currently exposed ports91exposedPorts?: WorkspaceInstancePort[];9293// timeout is a non-default timeout value configured for a workspace94timeout?: string;9596// nodeName is the name of the node the instance was scheduled onto97nodeName?: string;9899// podName is the name of the pod of this instance100podName?: string;101102// nodeIp is the IP of the node the workspace is running on103nodeIp?: string;104105// ownerToken is the token one needs to access the workspace. Its presence is checked by ws-proxy.106ownerToken?: string;107108// metrics contains metrics about the workspace instance109metrics?: WorkspaceInstanceMetrics;110}111112// WorkspaceInstancePhase describes a high-level state of a workspace instance113export type WorkspaceInstancePhase =114// unknown indicates an issue within the system in that it cannot determine the actual phase of115// a workspace. This phase is usually accompanied by an error.116| "unknown"117118// Preparing means that we haven't actually started the workspace instance just yet, but rather119// are still preparing for launch.120| "preparing"121122// Building means that we are building the Docker image for the workspace. A workspace will enter this phase only123// if an image build is required for that workspace.124| "building"125126// Pending means the workspace does not yet consume resources in the cluster, but rather is looking for127// some space within the cluster. If for example the cluster needs to scale up to accommodate the128// workspace, the workspace will be in Pending state until that happened.129| "pending"130131// Creating means the workspace is currently being created. That includes downloading the images required132// to run the workspace over the network. The time spent in this phase varies widely and depends on the current133// network speed, image size and cache states.134| "creating"135136// Initializing is the phase in which the workspace is executing the appropriate workspace initializer (e.g. Git137// clone or backup download). After this phase one can expect the workspace to either be Running or Failed.138| "initializing"139140// Running means the workspace is able to actively perform work, either by serving a user through Theia,141// or as a headless workspace.142| "running"143144// Interrupted is an exceptional state where the container should be running but is temporarily unavailable.145// When in this state, we expect it to become running or stopping anytime soon.146| "interrupted"147148// Stopping means that the workspace is currently shutting down. It could go to stopped every moment.149| "stopping"150151// Stopped means the workspace ended regularly because it was shut down.152| "stopped";153154export interface WorkspaceInstanceConditions {155// Failed contains the reason the workspace failed to operate. If this field is empty, the workspace has not failed.156// failed contains technical details for the failure of the workspace.157failed?: string;158159// timeout contains the reason the workspace has timed out. If this field is empty, the workspace has not timed out.160timeout?: string;161162// PullingImages marks if the workspace is currently pulling its images. This condition can only be set during PhaseCreating163pullingImages?: boolean;164165// deployed marks that a workspace instance was sent/deployed at a workspace manager166deployed?: boolean;167168// Whether the workspace start triggered an image build169neededImageBuild?: boolean;170171// ISO8601 timestamp when the first user activity was registered in the frontend. Only set if the workspace is running.172firstUserActivity?: string;173174// headlessTaskFailed indicates that a headless workspace task failed175// headlessTaskFailed is only set if:176// * this workspace is headless177// * the task being run returned a non 0 exit status code178headlessTaskFailed?: string;179180// stopped_by_request is true if the workspace was stopped using a StopWorkspace call181stoppedByRequest?: boolean;182}183184// AdmissionLevel describes who can access a workspace instance and its ports.185export type AdmissionLevel = "owner_only" | "everyone";186187// PortVisibility describes how a port can be accessed188export type PortVisibility = "public" | "private";189190// PortProtocol191export type PortProtocol = "http" | "https";192193// WorkspaceInstancePort describes a port exposed on a workspace instance194export interface WorkspaceInstancePort {195// The outward-facing port number196port: number;197198// The visibility of this port. Optional for backwards compatibility.199visibility?: PortVisibility;200201// Public, outward-facing URL where the port can be accessed on.202url?: string;203204protocol?: PortProtocol;205}206207// WorkspaceInstanceRepoStatus describes the status of th Git working copy of a workspace208export interface WorkspaceInstanceRepoStatus {209// branch is branch we're currently on210branch?: string;211212// latestCommit is the last commit on the current branch213latestCommit?: string;214215// uncommitedFiles is list of uncommitted files, possibly truncated216uncommitedFiles?: string[];217218// the total number of uncommited files219totalUncommitedFiles?: number;220221// untrackedFiles is the list of untracked files in the workspace, possibly truncated222untrackedFiles?: string[];223224// the total number of untracked files225totalUntrackedFiles?: number;226227// unpushedCommits is the list of unpushed changes in the workspace, possibly truncated228unpushedCommits?: string[];229230// the total number of unpushed changes231totalUnpushedCommits?: number;232}233export namespace WorkspaceInstanceRepoStatus {234export function equals(235a: WorkspaceInstanceRepoStatus | undefined,236b: WorkspaceInstanceRepoStatus | undefined,237): boolean {238if (!a && !b) {239return true;240}241if (!a || !b) {242return false;243}244return (245a.branch === b.branch &&246a.latestCommit === b.latestCommit &&247a.totalUncommitedFiles === b.totalUncommitedFiles &&248a.totalUnpushedCommits === b.totalUnpushedCommits &&249a.totalUntrackedFiles === b.totalUntrackedFiles &&250stringArrayEquals(a.uncommitedFiles, b.uncommitedFiles) &&251stringArrayEquals(a.untrackedFiles, b.untrackedFiles) &&252stringArrayEquals(a.unpushedCommits, b.unpushedCommits)253);254}255function stringArrayEquals(a: string[] | undefined, b: string[] | undefined): boolean {256if (a === undefined && b === undefined) return true;257258if (a === undefined || b === undefined) return false;259260if (a.length !== b.length) return false;261262for (let i = 0; i < a.length; i++) {263if (a[i] !== b[i]) return false;264}265266return true;267}268}269270// ConfigurationIdeConfig ide config of WorkspaceInstanceConfiguration271export interface ConfigurationIdeConfig {272useLatest?: boolean;273ide?: string;274preferToolbox?: boolean;275}276277export interface IdeSetup {278tasks?: TaskConfig[];279envvars?: EnvVar[];280}281282// WorkspaceInstanceConfiguration contains all per-instance configuration283export interface WorkspaceInstanceConfiguration {284// theiaVersion is the version of Theia this workspace instance uses285// @deprecated: replaced with the ideImage field286theiaVersion?: string;287288// feature flags are the lowercase feature-flag names as passed to ws-manager289featureFlags?: NamedWorkspaceFeatureFlag[];290291// ideImage is the ref of the IDE image this instance uses.292ideImage: string;293294// ideImageLayers are images needed for the ide to run,295// including ide-desktop, desktop-plugin and so on296ideImageLayers?: string[];297298// supervisorImage is the ref of the supervisor image this instance uses.299supervisorImage?: string;300301// ideSetup contains all piece that are necessary to get the IDE running302// TODO(gpl) ideally also contains the fields above: ideImage, ideImageLayers and supervisorImage303ideSetup?: IdeSetup;304305// ideConfig contains user-controlled IDE configuration306ideConfig?: ConfigurationIdeConfig;307308// The region the user passed as a preference for this workspace309regionPreference?: WorkspaceRegion;310311// Whether this instance is started from a backup312fromBackup?: boolean;313}314315/**316* Holds information about the image build (if there was one) for this WorkspaceInstance317*/318export interface ImageBuildInfo {319log?: ImageBuildLogInfo;320}321322/**323* Holds information about how to access logs for this an image build324*/325export interface ImageBuildLogInfo {326url: string;327headers: { [key: string]: string };328}329330/**331* Holds metrics about the workspace instance332*/333export interface WorkspaceInstanceMetrics {334image?: ImageMetrics;335336/**337* Metrics about the workspace initializer338*/339initializerMetrics?: InitializerMetrics;340}341342export interface ImageMetrics {343/**344* the total size of the image in bytes (includes Gitpod-specific layers like IDE)345*/346totalSize?: number;347348/**349* the size of the workspace image in bytes350*/351workspaceImageSize?: number;352}353354export interface InitializerMetrics {355git?: InitializerMetric;356fileDownload?: InitializerMetric;357snapshot?: InitializerMetric;358backup?: InitializerMetric;359prebuild?: InitializerMetric;360composite?: InitializerMetric;361}362363export interface InitializerMetric {364/**365* Duration in milliseconds366*/367duration: number;368369/**370* Size in bytes371*/372size: number;373}374375376