Skip to content

[ws-manager] add a metric to track volume snapshot time #10290

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 3 commits into from
May 30, 2022
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
21 changes: 15 additions & 6 deletions components/ws-manager/pkg/manager/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
18 changes: 15 additions & 3 deletions components/ws-manager/pkg/manager/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down