@@ -58,12 +58,35 @@ import { log, LogrusLogLevel } from "@gitpod/gitpod-protocol/lib/util/logging";
58
58
import { TracingManager } from "@gitpod/gitpod-protocol/lib/util/tracing" ;
59
59
import { TypeORM } from "@gitpod/gitpod-db/lib" ;
60
60
import { dbConnectionsEnqueued , dbConnectionsFree , dbConnectionsTotal } from "./prometheus-metrics" ;
61
+ import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server" ;
61
62
if ( process . env . NODE_ENV === "development" ) {
62
63
require ( "longjohn" ) ;
63
64
}
64
65
65
66
log . enableJSONLogging ( "server" , process . env . VERSION , LogrusLogLevel . getFromEnv ( ) ) ;
66
67
68
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
69
+ ( async ( ) => {
70
+ let isEnabled = await getExperimentsClientForBackend ( ) . getValueAsync ( "google_cloud_profiler" , false , { } ) ;
71
+ while ( ! isEnabled ) {
72
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 3000 ) ) ;
73
+ isEnabled = await getExperimentsClientForBackend ( ) . getValueAsync ( "google_cloud_profiler" , false , { } ) ;
74
+ }
75
+ try {
76
+ const profiler = await import ( "@google-cloud/profiler" ) ;
77
+ // there is no way to stop it: https://github.com/googleapis/cloud-profiler-nodejs/issues/876
78
+ // disable google_cloud_profiler and cycle servers
79
+ await profiler . start ( {
80
+ serviceContext : {
81
+ service : "server" ,
82
+ version : process . env . VERSION ,
83
+ } ,
84
+ } ) ;
85
+ } catch ( err ) {
86
+ console . error ( "failed to start cloud profiler" , err ) ;
87
+ }
88
+ } ) ( ) ;
89
+
67
90
export async function start ( container : Container ) {
68
91
const server = container . get ( Server ) ;
69
92
const port = 3000 ;
0 commit comments