Skip to content

[server] Add counter metric for image build starts #14204

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 2 commits 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
10 changes: 10 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(instanceStartsFailedTotal);
registry.registerMetric(prebuildsStartedTotal);
registry.registerMetric(stripeClientRequestsCompletedDurationSeconds);
registry.registerMetric(imageBuildsStartedTotal);
}

const loginCounter = new prometheusClient.Counter({
Expand Down Expand Up @@ -176,3 +177,12 @@ export const stripeClientRequestsCompletedDurationSeconds = new prometheusClient
export function observeStripeClientRequestsCompleted(operation: string, outcome: string, durationInSeconds: number) {
stripeClientRequestsCompletedDurationSeconds.observe({ operation, outcome }, durationInSeconds);
}

export const imageBuildsStartedTotal = new prometheusClient.Counter({
name: "gitpod_server_image_builds_started_total",
help: "counter of the total number of image builds started on server",
});

export function increaseImageBuildsStartedTotal() {
imageBuildsStartedTotal.inc();
}
5 changes: 5 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,
increaseImageBuildsStartedTotal,
increaseSuccessfulInstanceStartCounter,
} from "../prometheus-metrics";
import { ContextParser } from "./context-parser-service";
Expand Down Expand Up @@ -1255,6 +1256,10 @@ export class WorkspaceStarter {

const result = await client.build({ span }, req, imageBuildLogInfo);

if (result.actuallyNeedsBuild) {
increaseImageBuildsStartedTotal();
Copy link
Member

Choose a reason for hiding this comment

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

At what point does this increment? Is it after we've completed the build? Or is the build method async and it tells us it needs to be build and returns?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the build call on line 1257 awaits until the build starts:

// build returns a nested promise. The outer one resolves/rejects with the build start,
// the inner one resolves/rejects when the build is done.

so we're incrementing on build start here, not completion.

The build completion is awaited further down this file on line 1281:

buildResult = await result.buildPromise;

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

}

// Update the workspace now that we know what the name of the workspace image will be (which doubles as buildID)
workspace.imageNameResolved = result.ref;
span.log({ ref: workspace.imageNameResolved });
Expand Down