diff --git a/components/ws-manager/pkg/manager/metrics.go b/components/ws-manager/pkg/manager/metrics.go index 0d430ef57c11a7..59c2718020e27c 100644 --- a/components/ws-manager/pkg/manager/metrics.go +++ b/components/ws-manager/pkg/manager/metrics.go @@ -37,12 +37,13 @@ const ( type metrics struct { manager *Manager - startupTimeHistVec *prometheus.HistogramVec - initializeTimeHistVec *prometheus.HistogramVec - finalizeTimeHistVec *prometheus.HistogramVec - totalStartsCounterVec *prometheus.CounterVec - totalStopsCounterVec *prometheus.CounterVec - totalOpenPortGauge prometheus.GaugeFunc + startupTimeHistVec *prometheus.HistogramVec + initializeTimeHistVec *prometheus.HistogramVec + finalizeTimeHistVec *prometheus.HistogramVec + volumeSnapshotTimeHistVec *prometheus.HistogramVec + totalStartsCounterVec *prometheus.CounterVec + totalStopsCounterVec *prometheus.CounterVec + totalOpenPortGauge prometheus.GaugeFunc mu sync.Mutex phaseState map[string]api.WorkspacePhase @@ -74,6 +75,13 @@ func newMetrics(m *Manager) *metrics { Help: "time it took to finalize workspace", Buckets: prometheus.ExponentialBuckets(2, 2, 10), }, []string{"type"}), + volumeSnapshotTimeHistVec: prometheus.NewHistogramVec(prometheus.HistogramOpts{ + Namespace: metricsNamespace, + Subsystem: metricsWorkspaceSubsystem, + Name: "volume_snapshot_seconds", + Help: "time it took to snapshot volume", + Buckets: prometheus.ExponentialBuckets(2, 2, 10), + }, []string{"type"}), totalStartsCounterVec: prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: metricsNamespace, Subsystem: metricsWorkspaceSubsystem, @@ -136,6 +144,7 @@ func (m *metrics) Register(reg prometheus.Registerer) error { m.startupTimeHistVec, m.initializeTimeHistVec, m.finalizeTimeHistVec, + m.volumeSnapshotTimeHistVec, newPhaseTotalVec(m.manager), newWorkspaceActivityVec(m.manager), newTimeoutSettingsVec(m.manager), diff --git a/components/ws-manager/pkg/manager/monitor.go b/components/ws-manager/pkg/manager/monitor.go index bbfd27d8305d44..fc45082a4ee336 100644 --- a/components/ws-manager/pkg/manager/monitor.go +++ b/components/ws-manager/pkg/manager/monitor.go @@ -795,8 +795,9 @@ func (m *Monitor) initializeWorkspaceContent(ctx context.Context, pod *corev1.Po hist, errHist := m.manager.metrics.initializeTimeHistVec.GetMetricWithLabelValues(wsType) if errHist != nil { log.WithError(errHist).WithField("type", wsType).Warn("cannot get initialize time histogram metric") + } else { + hist.Observe(time.Since(t).Seconds()) } - hist.Observe(time.Since(t).Seconds()) if err != nil { return xerrors.Errorf("cannot initialize workspace: %w", err) } @@ -880,6 +881,7 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb log.WithError(err).Warn("cannot determine workspace type - assuming this is a regular") tpe = api.WorkspaceType_REGULAR } + wsType := api.WorkspaceType_name[int32(tpe)] var ( createdVolumeSnapshot bool @@ -891,6 +893,8 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb pvcVolumeSnapshotName string = workspaceID pvcVolumeSnapshotContentName string pvcVolumeSnapshotClassName string + + volumeSnapshotTime time.Time ) if wso.Pod != nil { _, pvcFeatureEnabled = wso.Pod.Labels[pvcWorkspaceFeatureAnnotation] @@ -973,6 +977,7 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb return true, nil, err } createdVolumeSnapshot = true + volumeSnapshotTime = time.Now() } if createdVolumeSnapshot { backoff := wait.Backoff{ @@ -1016,6 +1021,12 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb return true, nil, err } readyVolumeSnapshot = true + hist, err := m.manager.metrics.volumeSnapshotTimeHistVec.GetMetricWithLabelValues(wsType) + if err != nil { + log.WithError(err).WithField("type", wsType).Warn("cannot get volume snapshot time histogram metric") + } else { + hist.Observe(time.Since(volumeSnapshotTime).Seconds()) + } } if readyVolumeSnapshot && !markVolumeSnapshotAnnotation { log = log.WithField("VolumeSnapshotContent.Name", pvcVolumeSnapshotContentName) @@ -1154,12 +1165,13 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb } break } - wsType := api.WorkspaceType_name[int32(tpe)] + hist, err := m.manager.metrics.finalizeTimeHistVec.GetMetricWithLabelValues(wsType) if err != nil { log.WithError(err).WithField("type", wsType).Warn("cannot get finalize time histogram metric") + } else { + hist.Observe(time.Since(t).Seconds()) } - hist.Observe(time.Since(t).Seconds()) disposalStatus = &workspaceDisposalStatus{ BackupComplete: true,