4
4
* See License.AGPL.txt in the project root for license information.
5
5
*/
6
6
7
- import { inject , injectable , interfaces } from "inversify" ;
7
+ import { inject , injectable } from "inversify" ;
8
8
import { MessageBusIntegration } from "./messagebus-integration" ;
9
9
import {
10
10
Disposable ,
@@ -29,7 +29,6 @@ import { ClientProvider, WsmanSubscriber } from "./wsman-subscriber";
29
29
import { Timestamp } from "google-protobuf/google/protobuf/timestamp_pb" ;
30
30
import { Configuration } from "./config" ;
31
31
import { WorkspaceCluster } from "@gitpod/gitpod-protocol/lib/workspace-cluster" ;
32
- import { PreparingUpdateEmulator , PreparingUpdateEmulatorFactory } from "./preparing-update-emulator" ;
33
32
import { performance } from "perf_hooks" ;
34
33
import { PrebuildUpdater } from "./prebuild-updater" ;
35
34
import { WorkspaceInstanceController } from "./workspace-instance-controller" ;
@@ -44,7 +43,7 @@ function toBool(b: WorkspaceConditionBool | undefined): boolean | undefined {
44
43
return b === WorkspaceConditionBool . TRUE ;
45
44
}
46
45
47
- export type WorkspaceClusterInfo = Pick < WorkspaceCluster , "name" | "url" | "govern" > ;
46
+ export type WorkspaceClusterInfo = Pick < WorkspaceCluster , "name" | "url" > ;
48
47
49
48
@injectable ( )
50
49
export class WorkspaceManagerBridge implements Disposable {
@@ -60,9 +59,6 @@ export class WorkspaceManagerBridge implements Disposable {
60
59
@inject ( Configuration )
61
60
protected readonly config : Configuration ;
62
61
63
- @inject ( PreparingUpdateEmulatorFactory )
64
- protected readonly preparingUpdateEmulatorFactory : interfaces . Factory < PreparingUpdateEmulator > ;
65
-
66
62
@inject ( IAnalyticsWriter )
67
63
protected readonly analytics : IAnalyticsWriter ;
68
64
@@ -78,57 +74,43 @@ export class WorkspaceManagerBridge implements Disposable {
78
74
protected cluster : WorkspaceClusterInfo ;
79
75
80
76
public start ( cluster : WorkspaceClusterInfo , clientProvider : ClientProvider ) {
81
- const logPayload = { name : cluster . name , url : cluster . url , govern : cluster . govern } ;
77
+ const logPayload = { name : cluster . name , url : cluster . url } ;
82
78
log . info ( `Starting bridge to cluster...` , logPayload ) ;
83
79
this . cluster = cluster ;
84
80
85
- const startStatusUpdateHandler = ( writeToDB : boolean ) => {
81
+ const startStatusUpdateHandler = ( ) => {
86
82
log . debug ( `Starting status update handler: ${ cluster . name } ` , logPayload ) ;
87
- /* no await */ this . startStatusUpdateHandler ( clientProvider , writeToDB , logPayload )
83
+ /* no await */ this . startStatusUpdateHandler ( clientProvider , logPayload )
88
84
// this is a mere safe-guard: we do not expect the code inside to fail
89
85
. catch ( ( err ) => log . error ( "Cannot start status update handler" , err ) ) ;
90
86
} ;
91
87
92
- if ( cluster . govern ) {
93
- // notify servers and _update the DB_
94
- startStatusUpdateHandler ( true ) ;
95
-
96
- // the actual "governing" part
97
- const controllerIntervalSeconds = this . config . controllerIntervalSeconds ;
98
- if ( controllerIntervalSeconds <= 0 ) {
99
- throw new Error ( "controllerIntervalSeconds <= 0!" ) ;
100
- }
88
+ // notify servers and _update the DB_
89
+ startStatusUpdateHandler ( ) ;
101
90
102
- log . debug ( `Starting controller: ${ cluster . name } ` , logPayload ) ;
103
- // Control all workspace instances, either against ws-manager or configured timeouts
104
- this . workspaceInstanceController . start (
105
- cluster . name ,
106
- clientProvider ,
107
- controllerIntervalSeconds ,
108
- this . config . controllerMaxDisconnectSeconds ,
109
- ) ;
110
- } else {
111
- // _DO NOT_ update the DB (another bridge is responsible for that)
112
- // Still, listen to all updates, generate/derive new state and distribute it locally!
113
- startStatusUpdateHandler ( false ) ;
114
-
115
- // emulate WorkspaceInstance updates for all Workspaces in the "preparing" or "building" phase in this cluster
116
- const updateEmulator = this . preparingUpdateEmulatorFactory ( ) as PreparingUpdateEmulator ;
117
- this . disposables . push ( updateEmulator ) ;
118
- updateEmulator . start ( cluster . name ) ;
91
+ // the actual "governing" part
92
+ const controllerIntervalSeconds = this . config . controllerIntervalSeconds ;
93
+ if ( controllerIntervalSeconds <= 0 ) {
94
+ throw new Error ( "controllerIntervalSeconds <= 0!" ) ;
119
95
}
96
+
97
+ log . debug ( `Starting controller: ${ cluster . name } ` , logPayload ) ;
98
+ // Control all workspace instances, either against ws-manager or configured timeouts
99
+ this . workspaceInstanceController . start (
100
+ cluster . name ,
101
+ clientProvider ,
102
+ controllerIntervalSeconds ,
103
+ this . config . controllerMaxDisconnectSeconds ,
104
+ ) ;
105
+
120
106
log . info ( `Started bridge to cluster.` , logPayload ) ;
121
107
}
122
108
123
109
public stop ( ) {
124
110
this . dispose ( ) ;
125
111
}
126
112
127
- protected async startStatusUpdateHandler (
128
- clientProvider : ClientProvider ,
129
- writeToDB : boolean ,
130
- logPayload : { } ,
131
- ) : Promise < void > {
113
+ protected async startStatusUpdateHandler ( clientProvider : ClientProvider , logPayload : { } ) : Promise < void > {
132
114
const subscriber = new WsmanSubscriber ( clientProvider ) ;
133
115
this . disposables . push ( subscriber ) ;
134
116
@@ -138,7 +120,7 @@ export class WorkspaceManagerBridge implements Disposable {
138
120
ctx ,
139
121
sx ,
140
122
( m ) => m . getId ( ) ,
141
- ( ctx , msg ) => this . handleStatusUpdate ( ctx , msg , writeToDB ) ,
123
+ ( ctx , msg ) => this . handleStatusUpdate ( ctx , msg ) ,
142
124
) ,
143
125
) ;
144
126
} ;
@@ -147,7 +129,7 @@ export class WorkspaceManagerBridge implements Disposable {
147
129
ctx ,
148
130
s ,
149
131
( msg ) => msg . getId ( ) ,
150
- ( ctx , s ) => this . handleStatusUpdate ( ctx , s , writeToDB ) ,
132
+ ( ctx , s ) => this . handleStatusUpdate ( ctx , s ) ,
151
133
) ;
152
134
} ;
153
135
await subscriber . subscribe ( { onReconnect, onStatusUpdate } , logPayload ) ;
@@ -172,7 +154,7 @@ export class WorkspaceManagerBridge implements Disposable {
172
154
this . queues . set ( instanceId , q ) ;
173
155
}
174
156
175
- protected async handleStatusUpdate ( ctx : TraceContext , rawStatus : WorkspaceStatus , writeToDB : boolean ) {
157
+ protected async handleStatusUpdate ( ctx : TraceContext , rawStatus : WorkspaceStatus ) {
176
158
const start = performance . now ( ) ;
177
159
const status = rawStatus . toObject ( ) ;
178
160
log . info ( "Handling WorkspaceStatus update" , filterStatus ( status ) ) ;
@@ -189,17 +171,12 @@ export class WorkspaceManagerBridge implements Disposable {
189
171
} ;
190
172
191
173
try {
192
- this . prometheusExporter . reportWorkspaceInstanceUpdateStarted (
193
- writeToDB ,
194
- this . cluster . name ,
195
- status . spec . type ,
196
- ) ;
197
- await this . statusUpdate ( ctx , rawStatus , writeToDB ) ;
174
+ this . prometheusExporter . reportWorkspaceInstanceUpdateStarted ( this . cluster . name , status . spec . type ) ;
175
+ await this . statusUpdate ( ctx , rawStatus ) ;
198
176
} catch ( e ) {
199
177
const durationMs = performance . now ( ) - start ;
200
178
this . prometheusExporter . reportWorkspaceInstanceUpdateCompleted (
201
179
durationMs / 1000 ,
202
- writeToDB ,
203
180
this . cluster . name ,
204
181
status . spec . type ,
205
182
e ,
@@ -210,14 +187,13 @@ export class WorkspaceManagerBridge implements Disposable {
210
187
const durationMs = performance . now ( ) - start ;
211
188
this . prometheusExporter . reportWorkspaceInstanceUpdateCompleted (
212
189
durationMs / 1000 ,
213
- writeToDB ,
214
190
this . cluster . name ,
215
191
status . spec . type ,
216
192
) ;
217
193
log . info ( logCtx , "Successfully completed WorkspaceInstance status update" ) ;
218
194
}
219
195
220
- private async statusUpdate ( ctx : TraceContext , rawStatus : WorkspaceStatus , writeToDB : boolean ) {
196
+ private async statusUpdate ( ctx : TraceContext , rawStatus : WorkspaceStatus ) {
221
197
const status = rawStatus . toObject ( ) ;
222
198
223
199
if ( ! status . spec || ! status . metadata || ! status . conditions ) {
@@ -226,7 +202,6 @@ export class WorkspaceManagerBridge implements Disposable {
226
202
227
203
const span = TraceContext . startSpan ( "handleStatusUpdate" , ctx ) ;
228
204
span . setTag ( "status" , JSON . stringify ( filterStatus ( status ) ) ) ;
229
- span . setTag ( "writeToDB" , writeToDB ) ;
230
205
span . setTag ( "statusVersion" , status . statusVersion ) ;
231
206
try {
232
207
// Beware of the ID mapping here: What's a workspace to the ws-manager is a workspace instance to the rest of the system.
@@ -388,16 +363,14 @@ export class WorkspaceManagerBridge implements Disposable {
388
363
span . setTag ( "after" , JSON . stringify ( instance ) ) ;
389
364
390
365
// now notify all prebuild listeners about updates - and update DB if needed
391
- await this . prebuildUpdater . updatePrebuiltWorkspace ( { span } , userId , status , writeToDB ) ;
366
+ await this . prebuildUpdater . updatePrebuiltWorkspace ( { span } , userId , status ) ;
392
367
393
- if ( writeToDB ) {
394
- await this . workspaceDB . trace ( ctx ) . storeInstance ( instance ) ;
368
+ await this . workspaceDB . trace ( ctx ) . storeInstance ( instance ) ;
395
369
396
- // cleanup
397
- // important: call this after the DB update
398
- if ( ! ! lifecycleHandler ) {
399
- await lifecycleHandler ( ) ;
400
- }
370
+ // cleanup
371
+ // important: call this after the DB update
372
+ if ( ! ! lifecycleHandler ) {
373
+ await lifecycleHandler ( ) ;
401
374
}
402
375
await this . messagebus . notifyOnInstanceUpdate ( ctx , userId , instance ) ;
403
376
} catch ( e ) {
0 commit comments