Skip to content

feat(api): add prometheus metric coderd_workspace_builds_total #6314

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
Feb 23, 2023
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
2 changes: 2 additions & 0 deletions coderd/provisionerdserver/provisionerdserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ func (server *Server) AcquireJob(ctx context.Context, _ *proto.Empty) (*proto.Ac
WorkspaceOwnerEmail: owner.Email,
WorkspaceId: workspace.ID.String(),
WorkspaceOwnerId: owner.ID.String(),
TemplateName: template.Name,
TemplateVersion: templateVersion.Name,
},
},
}
Expand Down
2 changes: 2 additions & 0 deletions coderd/provisionerdserver/provisionerdserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ func TestAcquireJob(t *testing.T) {
WorkspaceOwnerEmail: user.Email,
WorkspaceId: workspace.ID.String(),
WorkspaceOwnerId: user.ID.String(),
TemplateName: template.Name,
TemplateVersion: version.Name,
},
},
})
Expand Down
95 changes: 48 additions & 47 deletions docs/admin/prometheus.md

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions provisionerd/provisionerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}),
},
}
}
Expand Down
12 changes: 12 additions & 0 deletions provisionerd/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
}()

Expand Down
27 changes: 24 additions & 3 deletions provisionersdk/proto/provisioner.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions provisionersdk/proto/provisioner.proto
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ message Provision {
string workspace_id = 5;
string workspace_owner_id = 6;
string workspace_owner_email = 7;
string template_name = 8;
string template_version = 9;
}

// Config represents execution configuration shared by both Plan and
Expand Down
5 changes: 5 additions & 0 deletions scripts/metricsdocgen/metrics
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,11 @@ coderd_provisionerd_job_timings_seconds_count{provisioner="terraform",status="su
# HELP coderd_provisionerd_jobs_current The number of currently running provisioner jobs.
# TYPE coderd_provisionerd_jobs_current gauge
coderd_provisionerd_jobs_current{provisioner="terraform"} 0
# HELP coderd_workspace_builds_total The number of workspaces started, updated, or deleted.
# TYPE coderd_workspace_builds_total counter
coderd_workspace_builds_total{action="START",owner_email="admin@coder.com",status="failed",template_name="docker",template_version="gallant_wright0",workspace_name="test1"} 1
coderd_workspace_builds_total{action="START",owner_email="admin@coder.com",status="success",template_name="docker",template_version="gallant_wright0",workspace_name="test1"} 1
coderd_workspace_builds_total{action="STOP",owner_email="admin@coder.com",status="success",template_name="docker",template_version="gallant_wright0",workspace_name="test1"} 1
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 2.4056e-05
Expand Down