Skip to content

Commit 0a00441

Browse files
authored
[server] add google cloud profiler (#18727)
1 parent 3444343 commit 0a00441

File tree

4 files changed

+810
-16
lines changed

4 files changed

+810
-16
lines changed

components/server/leeway.Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
FROM node:18.17.1-slim as builder
66
COPY components-server--app /installer/
77

8+
# Install Python, make, gcc and g++ for node-gyp
9+
RUN apt-get update && \
10+
apt-get install -y python3 make gcc g++ && \
11+
apt-get clean && \
12+
rm -rf /var/lib/apt/lists/*
13+
814
WORKDIR /app
915
RUN /installer/install.sh
1016

components/server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"@gitpod/supervisor-api-grpcweb": "0.1.5",
5757
"@gitpod/usage-api": "0.1.5",
5858
"@gitpod/ws-manager": "0.1.5",
59+
"@google-cloud/profiler": "^6.0.0",
5960
"@improbable-eng/grpc-web-node-http-transport": "^0.14.0",
6061
"@jmondi/oauth2-server": "^2.6.1",
6162
"@octokit/rest": "18.6.1",

components/server/src/init.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,35 @@ import { log, LogrusLogLevel } from "@gitpod/gitpod-protocol/lib/util/logging";
5858
import { TracingManager } from "@gitpod/gitpod-protocol/lib/util/tracing";
5959
import { TypeORM } from "@gitpod/gitpod-db/lib";
6060
import { dbConnectionsEnqueued, dbConnectionsFree, dbConnectionsTotal } from "./prometheus-metrics";
61+
import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";
6162
if (process.env.NODE_ENV === "development") {
6263
require("longjohn");
6364
}
6465

6566
log.enableJSONLogging("server", process.env.VERSION, LogrusLogLevel.getFromEnv());
6667

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+
6790
export async function start(container: Container) {
6891
const server = container.get(Server);
6992
const port = 3000;

0 commit comments

Comments
 (0)