Skip to content

Commit

Permalink
Add 'type' label to workspace stop metric
Browse files Browse the repository at this point in the history
Signed-off-by: ArthurSens <arthursens2005@gmail.com>
  • Loading branch information
ArthurSens committed Aug 27, 2021
1 parent e039c1b commit 019de34
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions components/ws-manager/pkg/manager/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func newMetrics(m *Manager) *metrics {
Subsystem: metricsWorkspaceSubsystem,
Name: "workspace_stops_total",
Help: "total number of workspaces stopped",
}, []string{"reason"}),
}, []string{"reason", "type"}),
totalOpenPortGauge: prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: metricsNamespace,
Subsystem: metricsWorkspaceSubsystem,
Expand Down Expand Up @@ -144,6 +144,7 @@ func (m *metrics) OnWorkspaceStarted(tpe api.WorkspaceType) {

func (m *metrics) OnChange(status *api.WorkspaceStatus) {
var removeFromState bool
tpe := api.WorkspaceType_name[int32(status.Spec.Type)]
m.mu.Lock()
defer func() {
if removeFromState {
Expand All @@ -165,7 +166,6 @@ func (m *metrics) OnChange(status *api.WorkspaceStatus) {
}

t := status.Metadata.StartedAt.AsTime()
tpe := api.WorkspaceType_name[int32(status.Spec.Type)]
hist, err := m.startupTimeHistVec.GetMetricWithLabelValues(tpe)
if err != nil {
log.WithError(err).WithField("type", tpe).Warn("cannot get startup time histogram metric")
Expand All @@ -185,7 +185,7 @@ func (m *metrics) OnChange(status *api.WorkspaceStatus) {
reason = "regular-stop"
}

counter, err := m.totalStopsCounterVec.GetMetricWithLabelValues(reason)
counter, err := m.totalStopsCounterVec.GetMetricWithLabelValues(reason, tpe)
if err != nil {
log.WithError(err).WithField("reason", reason).Warn("cannot get counter for workspace stops metric")
return
Expand Down

0 comments on commit 019de34

Please sign in to comment.