Skip to content

Commit 43e8ba0

Browse files
authored
feat(api): add prometheus metric coderd_workspace_builds_total (#6314)
This PR adds the prometheus metric coderd_workspace_builds_total. It measures the total number of workspace builds, along with a number of labels intended to be useful for an operator debugging a failed workspace build trying to discover the scope of the issue.
1 parent 2a8a147 commit 43e8ba0

File tree

8 files changed

+101
-50
lines changed

8 files changed

+101
-50
lines changed

coderd/provisionerdserver/provisionerdserver.go

+2
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ func (server *Server) AcquireJob(ctx context.Context, _ *proto.Empty) (*proto.Ac
210210
WorkspaceOwnerEmail: owner.Email,
211211
WorkspaceId: workspace.ID.String(),
212212
WorkspaceOwnerId: owner.ID.String(),
213+
TemplateName: template.Name,
214+
TemplateVersion: templateVersion.Name,
213215
},
214216
},
215217
}

coderd/provisionerdserver/provisionerdserver_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ func TestAcquireJob(t *testing.T) {
206206
WorkspaceOwnerEmail: user.Email,
207207
WorkspaceId: workspace.ID.String(),
208208
WorkspaceOwnerId: user.ID.String(),
209+
TemplateName: template.Name,
210+
TemplateVersion: version.Name,
209211
},
210212
},
211213
})

docs/admin/prometheus.md

+48-47
Large diffs are not rendered by default.

provisionerd/provisionerd.go

+6
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ func NewMetrics(reg prometheus.Registerer) Metrics {
157157
60 * 60, // 1hr
158158
},
159159
}, []string{"provisioner", "status"}),
160+
WorkspaceBuilds: auto.NewCounterVec(prometheus.CounterOpts{
161+
Namespace: "coderd",
162+
Subsystem: "", // Explicitly empty to make this a top-level metric.
163+
Name: "workspace_builds_total",
164+
Help: "The number of workspaces started, updated, or deleted.",
165+
}, []string{"owner_email", "workspace_name", "template_name", "template_version", "action", "status"}),
160166
},
161167
}
162168
}

provisionerd/runner/runner.go

+12
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ type Metrics struct {
7777
ConcurrentJobs *prometheus.GaugeVec
7878
// JobTimings also counts the total amount of jobs.
7979
JobTimings *prometheus.HistogramVec
80+
// WorkspaceBuilds counts workspace build successes and failures.
81+
WorkspaceBuilds *prometheus.CounterVec
8082
}
8183

8284
type JobUpdater interface {
@@ -161,6 +163,16 @@ func (r *Runner) Run() {
161163
}
162164

163165
concurrentGauge.Dec()
166+
if build := r.job.GetWorkspaceBuild(); build != nil {
167+
r.metrics.WorkspaceBuilds.WithLabelValues(
168+
build.Metadata.WorkspaceOwnerEmail,
169+
build.Metadata.WorkspaceName,
170+
build.Metadata.TemplateName,
171+
build.Metadata.TemplateVersion,
172+
build.Metadata.WorkspaceTransition.String(),
173+
status,
174+
).Inc()
175+
}
164176
r.metrics.JobTimings.WithLabelValues(r.job.Provisioner, status).Observe(time.Since(start).Seconds())
165177
}()
166178

provisionersdk/proto/provisioner.pb.go

+24-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisionersdk/proto/provisioner.proto

+2
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ message Provision {
220220
string workspace_id = 5;
221221
string workspace_owner_id = 6;
222222
string workspace_owner_email = 7;
223+
string template_name = 8;
224+
string template_version = 9;
223225
}
224226

225227
// Config represents execution configuration shared by both Plan and

scripts/metricsdocgen/metrics

+5
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,11 @@ coderd_provisionerd_job_timings_seconds_count{provisioner="terraform",status="su
584584
# HELP coderd_provisionerd_jobs_current The number of currently running provisioner jobs.
585585
# TYPE coderd_provisionerd_jobs_current gauge
586586
coderd_provisionerd_jobs_current{provisioner="terraform"} 0
587+
# HELP coderd_workspace_builds_total The number of workspaces started, updated, or deleted.
588+
# TYPE coderd_workspace_builds_total counter
589+
coderd_workspace_builds_total{action="START",owner_email="admin@coder.com",status="failed",template_name="docker",template_version="gallant_wright0",workspace_name="test1"} 1
590+
coderd_workspace_builds_total{action="START",owner_email="admin@coder.com",status="success",template_name="docker",template_version="gallant_wright0",workspace_name="test1"} 1
591+
coderd_workspace_builds_total{action="STOP",owner_email="admin@coder.com",status="success",template_name="docker",template_version="gallant_wright0",workspace_name="test1"} 1
587592
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
588593
# TYPE go_gc_duration_seconds summary
589594
go_gc_duration_seconds{quantile="0"} 2.4056e-05

0 commit comments

Comments
 (0)