@@ -112,7 +112,11 @@ import { WithReferrerContext } from "@gitpod/gitpod-protocol/lib/protocol";
112
112
import { IDEOption , IDEOptions } from "@gitpod/gitpod-protocol/lib/ide-protocol" ;
113
113
import { Deferred } from "@gitpod/gitpod-protocol/lib/util/deferred" ;
114
114
import { ExtendedUser } from "@gitpod/ws-manager/lib/constraints" ;
115
- import { increaseFailedInstanceStartCounter , increaseSuccessfulInstanceStartCounter } from "../prometheus-metrics" ;
115
+ import {
116
+ FailedInstanceStartReason ,
117
+ increaseFailedInstanceStartCounter ,
118
+ increaseSuccessfulInstanceStartCounter ,
119
+ } from "../prometheus-metrics" ;
116
120
import { ContextParser } from "./context-parser-service" ;
117
121
import { IDEService } from "../ide-service" ;
118
122
import { WorkspaceClusterImagebuilderClientProvider } from "./workspace-cluster-imagebuilder-client-provider" ;
@@ -244,6 +248,12 @@ export async function getWorkspaceClassForInstance(
244
248
}
245
249
}
246
250
251
+ class StartInstanceError extends Error {
252
+ constructor ( public readonly reason : FailedInstanceStartReason , public readonly cause : Error ) {
253
+ super ( "Starting workspace instance failed: " + cause . message ) ;
254
+ }
255
+ }
256
+
247
257
@injectable ( )
248
258
export class WorkspaceStarter {
249
259
@inject ( WorkspaceManagerClientProvider ) protected readonly clientProvider : WorkspaceManagerClientProvider ;
@@ -414,6 +424,11 @@ export class WorkspaceStarter {
414
424
forceRebuild ,
415
425
) ;
416
426
} catch ( e ) {
427
+ let failedReason : FailedInstanceStartReason = "other" ;
428
+ if ( e instanceof StartInstanceError ) {
429
+ failedReason = e . reason ;
430
+ }
431
+ increaseFailedInstanceStartCounter ( failedReason ) ;
417
432
TraceContext . setError ( { span } , e ) ;
418
433
throw e ;
419
434
} finally {
@@ -523,16 +538,14 @@ export class WorkspaceStarter {
523
538
await new Promise ( ( resolve ) => setTimeout ( resolve , INSTANCE_START_RETRY_INTERVAL_SECONDS * 1000 ) ) ;
524
539
}
525
540
} catch ( err ) {
526
- increaseFailedInstanceStartCounter ( "startOnClusterFailed" ) ;
527
541
await this . failInstanceStart ( { span } , err , workspace , instance ) ;
528
- throw err ;
542
+ throw new StartInstanceError ( "startOnClusterFailed" , err ) ;
529
543
}
530
544
531
545
if ( ! resp ) {
532
- increaseFailedInstanceStartCounter ( "clusterSelectionFailed" ) ;
533
546
const err = new Error ( "cannot start a workspace because no workspace clusters are available" ) ;
534
547
await this . failInstanceStart ( { span } , err , workspace , instance ) ;
535
- throw err ;
548
+ throw new StartInstanceError ( "clusterSelectionFailed" , err ) ;
536
549
}
537
550
increaseSuccessfulInstanceStartCounter ( retries ) ;
538
551
@@ -579,6 +592,11 @@ export class WorkspaceStarter {
579
592
throw err ;
580
593
} else {
581
594
log . error ( "error starting instance" , err , { instanceId : instance . id } ) ;
595
+ let failedReason : FailedInstanceStartReason = "other" ;
596
+ if ( err instanceof StartInstanceError ) {
597
+ failedReason = err . reason ;
598
+ }
599
+ increaseFailedInstanceStartCounter ( failedReason ) ;
582
600
}
583
601
584
602
return { instanceID : instance . id } ;
0 commit comments