Skip to content

Commit b6dac56

Browse files
committed
[ws-manager] Add workspace class to metrics
1 parent 23c7726 commit b6dac56

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

components/ws-manager/pkg/manager/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ func (m *Manager) StartWorkspace(ctx context.Context, req *api.StartWorkspaceReq
341341
OwnerToken: startContext.OwnerToken,
342342
}
343343

344-
m.metrics.OnWorkspaceStarted(req.Type)
344+
m.metrics.OnWorkspaceStarted(req.Type, req.Spec.Class)
345345

346346
return okResponse, nil
347347
}

components/ws-manager/pkg/manager/metrics.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,21 @@ func newMetrics(m *Manager) *metrics {
6060
Help: "time it took for workspace pods to reach the running phase",
6161
// same as components/ws-manager-bridge/src/prometheus-metrics-exporter.ts#L15
6262
Buckets: prometheus.ExponentialBuckets(2, 2, 10),
63-
}, []string{"type"}),
63+
}, []string{"type", "class"}),
6464
initializeTimeHistVec: prometheus.NewHistogramVec(prometheus.HistogramOpts{
6565
Namespace: metricsNamespace,
6666
Subsystem: metricsWorkspaceSubsystem,
6767
Name: "workspace_initialize_seconds",
6868
Help: "time it took to initialize workspace",
6969
Buckets: prometheus.ExponentialBuckets(2, 2, 10),
70-
}, []string{"type"}),
70+
}, []string{"type", "class"}),
7171
finalizeTimeHistVec: prometheus.NewHistogramVec(prometheus.HistogramOpts{
7272
Namespace: metricsNamespace,
7373
Subsystem: metricsWorkspaceSubsystem,
7474
Name: "workspace_finalize_seconds",
7575
Help: "time it took to finalize workspace",
7676
Buckets: prometheus.ExponentialBuckets(2, 2, 10),
77-
}, []string{"type"}),
77+
}, []string{"type", "class"}),
7878
volumeSnapshotTimeHistVec: prometheus.NewHistogramVec(prometheus.HistogramOpts{
7979
Namespace: metricsNamespace,
8080
Subsystem: metricsWorkspaceSubsystem,
@@ -87,13 +87,13 @@ func newMetrics(m *Manager) *metrics {
8787
Subsystem: metricsWorkspaceSubsystem,
8888
Name: "workspace_starts_total",
8989
Help: "total number of workspaces started",
90-
}, []string{"type"}),
90+
}, []string{"type", "class"}),
9191
totalStopsCounterVec: prometheus.NewCounterVec(prometheus.CounterOpts{
9292
Namespace: metricsNamespace,
9393
Subsystem: metricsWorkspaceSubsystem,
9494
Name: "workspace_stops_total",
9595
Help: "total number of workspaces stopped",
96-
}, []string{"reason", "type"}),
96+
}, []string{"reason", "type", "class"}),
9797
totalOpenPortGauge: prometheus.NewGaugeFunc(prometheus.GaugeOpts{
9898
Namespace: metricsNamespace,
9999
Subsystem: metricsWorkspaceSubsystem,
@@ -163,9 +163,9 @@ func (m *metrics) Register(reg prometheus.Registerer) error {
163163
return nil
164164
}
165165

166-
func (m *metrics) OnWorkspaceStarted(tpe api.WorkspaceType) {
166+
func (m *metrics) OnWorkspaceStarted(tpe api.WorkspaceType, class string) {
167167
nme := api.WorkspaceType_name[int32(tpe)]
168-
counter, err := m.totalStartsCounterVec.GetMetricWithLabelValues(nme)
168+
counter, err := m.totalStartsCounterVec.GetMetricWithLabelValues(nme, class)
169169
if err != nil {
170170
log.WithError(err).WithField("type", tpe).Warn("cannot get counter for workspace start metric")
171171
return
@@ -198,7 +198,7 @@ func (m *metrics) OnChange(status *api.WorkspaceStatus) {
198198
}
199199

200200
t := status.Metadata.StartedAt.AsTime()
201-
hist, err := m.startupTimeHistVec.GetMetricWithLabelValues(tpe)
201+
hist, err := m.startupTimeHistVec.GetMetricWithLabelValues(tpe, status.Spec.Class)
202202
if err != nil {
203203
log.WithError(err).WithField("type", tpe).Warn("cannot get startup time histogram metric")
204204
return
@@ -217,7 +217,7 @@ func (m *metrics) OnChange(status *api.WorkspaceStatus) {
217217
reason = "regular-stop"
218218
}
219219

220-
counter, err := m.totalStopsCounterVec.GetMetricWithLabelValues(reason, tpe)
220+
counter, err := m.totalStopsCounterVec.GetMetricWithLabelValues(reason, tpe, status.Spec.Class)
221221
if err != nil {
222222
log.WithError(err).WithField("reason", reason).Warn("cannot get counter for workspace stops metric")
223223
return

components/ws-manager/pkg/manager/monitor.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,8 @@ func (m *Monitor) initializeWorkspaceContent(ctx context.Context, pod *corev1.Po
792792
err = handleGRPCError(ctx, err)
793793
}
794794
wsType := pod.Labels[wsk8s.TypeLabel]
795-
hist, errHist := m.manager.metrics.initializeTimeHistVec.GetMetricWithLabelValues(wsType)
795+
wsClass := pod.Labels[workspaceClassLabel]
796+
hist, errHist := m.manager.metrics.initializeTimeHistVec.GetMetricWithLabelValues(wsType, wsClass)
796797
if errHist != nil {
797798
log.WithError(errHist).WithField("type", wsType).Warn("cannot get initialize time histogram metric")
798799
} else {
@@ -1166,7 +1167,7 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb
11661167
break
11671168
}
11681169

1169-
hist, err := m.manager.metrics.finalizeTimeHistVec.GetMetricWithLabelValues(wsType)
1170+
hist, err := m.manager.metrics.finalizeTimeHistVec.GetMetricWithLabelValues(wsType, wso.Pod.Labels[workspaceClassLabel])
11701171
if err != nil {
11711172
log.WithError(err).WithField("type", wsType).Warn("cannot get finalize time histogram metric")
11721173
} else {

0 commit comments

Comments
 (0)