Skip to content

[server] Add metric for completed image builds #14296

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
Nov 1, 2022
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions components/server/src/prometheus-metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function registerServerMetrics(registry: prometheusClient.Registry) {
registry.registerMetric(prebuildsStartedTotal);
registry.registerMetric(stripeClientRequestsCompletedDurationSeconds);
registry.registerMetric(imageBuildsStartedTotal);
registry.registerMetric(imageBuildsCompletedTotal);
}

const loginCounter = new prometheusClient.Counter({
Expand Down Expand Up @@ -175,3 +176,13 @@ export const imageBuildsStartedTotal = new prometheusClient.Counter({
export function increaseImageBuildsStartedTotal() {
imageBuildsStartedTotal.inc();
}

export const imageBuildsCompletedTotal = new prometheusClient.Counter({
name: "gitpod_server_image_builds_completed_total",
help: "counter of the total number of image builds recorded as completed on server",
labelNames: ["outcome"],
});

export function increaseImageBuildsCompletedTotal(outcome: "succeeded" | "failed") {
imageBuildsCompletedTotal.inc({ outcome });
}
10 changes: 10 additions & 0 deletions components/server/src/workspace/workspace-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ import { ExtendedUser } from "@gitpod/ws-manager/lib/constraints";
import {
FailedInstanceStartReason,
increaseFailedInstanceStartCounter,
increaseImageBuildsCompletedTotal,
increaseImageBuildsStartedTotal,
increaseSuccessfulInstanceStartCounter,
} from "../prometheus-metrics";
Expand Down Expand Up @@ -1280,6 +1281,10 @@ export class WorkspaceStarter {
// ...and wait for the build to finish
buildResult = await result.buildPromise;
if (buildResult.getStatus() == BuildStatus.DONE_FAILURE) {
// Register a failed image build only if the image actually needed to be built; ie the build was not a no-op.
if (result.actuallyNeedsBuild) {
increaseImageBuildsCompletedTotal("failed");
}
throw new Error(buildResult.getMessage());
}
} catch (err) {
Expand All @@ -1302,6 +1307,11 @@ export class WorkspaceStarter {
}
}

// Register a successful image build only if the image actually needed to be built; ie the build was not a no-op.
if (result.actuallyNeedsBuild) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way to avoid this case would be to export both the started and completed metrics with a label of needed_build. This would still keep it semantic, and would give you the ability to filter these out in the SLO.

increaseImageBuildsCompletedTotal("succeeded");
}

// We have just found out how our base image is called - remember that.
// Note: it's intentional that we overwrite existing baseImageNameResolved values here so that one by one the refs here become absolute (i.e. digested form).
// This prevents the "rebuilds" for old workspaces.
Expand Down