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.
This commit is contained in:
Cian Johnston
2023-02-23 01:28:10 +00:00
committed by GitHub
parent 2a8a147e7d
commit 43e8ba0811
8 changed files with 101 additions and 50 deletions
+6
View File
@@ -157,6 +157,12 @@ func NewMetrics(reg prometheus.Registerer) Metrics {
60 * 60, // 1hr
},
}, []string{"provisioner", "status"}),
WorkspaceBuilds: auto.NewCounterVec(prometheus.CounterOpts{
Namespace: "coderd",
Subsystem: "", // Explicitly empty to make this a top-level metric.
Name: "workspace_builds_total",
Help: "The number of workspaces started, updated, or deleted.",
}, []string{"owner_email", "workspace_name", "template_name", "template_version", "action", "status"}),
},
}
}
+12
View File
@@ -77,6 +77,8 @@ type Metrics struct {
ConcurrentJobs *prometheus.GaugeVec
// JobTimings also counts the total amount of jobs.
JobTimings *prometheus.HistogramVec
// WorkspaceBuilds counts workspace build successes and failures.
WorkspaceBuilds *prometheus.CounterVec
}
type JobUpdater interface {
@@ -161,6 +163,16 @@ func (r *Runner) Run() {
}
concurrentGauge.Dec()
if build := r.job.GetWorkspaceBuild(); build != nil {
r.metrics.WorkspaceBuilds.WithLabelValues(
build.Metadata.WorkspaceOwnerEmail,
build.Metadata.WorkspaceName,
build.Metadata.TemplateName,
build.Metadata.TemplateVersion,
build.Metadata.WorkspaceTransition.String(),
status,
).Inc()
}
r.metrics.JobTimings.WithLabelValues(r.job.Provisioner, status).Observe(time.Since(start).Seconds())
}()