Skip to content

[server] Don't raise alerts on unspecific startWorkspace errors #12574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions components/server/src/workspace/workspace-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ import { CachingBillingServiceClientProvider } from "@gitpod/usage-api/lib/usage
import { Timestamp } from "google-protobuf/google/protobuf/timestamp_pb";
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
import { System } from "@gitpod/usage-api/lib/usage/v1/billing_pb";
import { LogContext } from "@gitpod/gitpod-protocol/lib/util/logging";

export interface StartWorkspaceOptions {
rethrow?: boolean;
Expand Down Expand Up @@ -304,6 +305,7 @@ export class WorkspaceStarter {
}

options = options || {};
let instanceId: string | undefined = undefined;
try {
await this.checkBlockedRepository(user, workspace.contextURL);

Expand Down Expand Up @@ -371,6 +373,7 @@ export class WorkspaceStarter {
),
);
span.log({ newInstance: instance.id });
instanceId = instance.id;

const forceRebuild = !!workspace.context.forceImageBuild;

Expand Down Expand Up @@ -427,12 +430,7 @@ export class WorkspaceStarter {
forceRebuild,
);
} catch (e) {
let failedReason: FailedInstanceStartReason = "other";
if (e instanceof StartInstanceError) {
failedReason = e.reason;
}
increaseFailedInstanceStartCounter(failedReason);
TraceContext.setError({ span }, e);
this.logAndTraceStartWorkspaceError({ span }, { userId: user.id, instanceId }, e);
throw e;
} finally {
span.finish();
Expand Down Expand Up @@ -594,16 +592,7 @@ export class WorkspaceStarter {
if (rethrow) {
throw err;
} else {
TraceContext.setError({ span }, err);
let reason: FailedInstanceStartReason | undefined = undefined;
if (err instanceof StartInstanceError) {
reason = err.reason;
increaseFailedInstanceStartCounter(err.reason);
}
log.error({ userId: user.id, instanceId: instance.id }, "error starting instance", err, {
failedInstanceStartReason: reason,
});
span.setTag("failedInstanceStartReason", reason);
this.logAndTraceStartWorkspaceError({ span }, { userId: user.id, instanceId: instance.id }, err);
}

return { instanceID: instance.id };
Expand All @@ -612,6 +601,20 @@ export class WorkspaceStarter {
}
}

protected logAndTraceStartWorkspaceError(ctx: TraceContext, logCtx: LogContext, err: any) {
TraceContext.setError(ctx, err);

let reason: FailedInstanceStartReason | undefined = undefined;
if (err instanceof StartInstanceError) {
reason = err.reason;
increaseFailedInstanceStartCounter(reason);
}
log.error(logCtx, "error starting instance", err, {
failedInstanceStartReason: reason,
});
ctx.span?.setTag("failedInstanceStartReason", reason);
}

protected async createMetadata(workspace: Workspace): Promise<WorkspaceMetadata> {
let metadata = new WorkspaceMetadata();
metadata.setOwner(workspace.ownerId);
Expand Down Expand Up @@ -1275,12 +1278,13 @@ export class WorkspaceStarter {

TraceContext.setError({ span }, err);
const looksLikeUserError = (msg: string): boolean => {
return msg.startsWith("build failed:") || msg.startsWith("headless task failed:");
return msg.startsWith("build failed:") || msg.includes("headless task failed:");
};
if (looksLikeUserError(message)) {
log.debug(
log.info(
{ instanceId: instance.id, userId: user.id, workspaceId: workspace.id },
`workspace image build failed: ${message}`,
{ looksLikeUserError: true },
);
} else {
log.error(
Expand Down