Skip to content

[ws-manager] Make sure volume restore time is accurate #10640

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
Jun 14, 2022
Merged
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
19 changes: 12 additions & 7 deletions components/ws-manager/pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ func (m *Manager) StartWorkspace(ctx context.Context, req *api.StartWorkspaceReq
span.LogKV("event", "pod description created")

var (
createPVC bool
pvc *corev1.PersistentVolumeClaim
volumeRestoreTime time.Time
createPVC bool
pvc *corev1.PersistentVolumeClaim
startTime, endTime time.Time // the start time and end time of PVC restoring from VolumeSnapshot
)
for _, feature := range startContext.Request.Spec.FeatureFlags {
if feature == api.WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM {
Expand All @@ -235,7 +235,10 @@ func (m *Manager) StartWorkspace(ctx context.Context, req *api.StartWorkspaceReq
if err != nil && !k8serr.IsAlreadyExists(err) {
return nil, xerrors.Errorf("cannot create pvc object for workspace pod: %w", err)
}
volumeRestoreTime = time.Now()
// we only calculate the time that PVC restoring from VolumeSnapshot
if startContext.VolumeSnapshot != nil && startContext.VolumeSnapshot.VolumeSnapshotName != "" {
startTime = time.Now()
}
}

// create the Pod in the cluster and wait until is scheduled
Expand Down Expand Up @@ -266,7 +269,8 @@ func (m *Manager) StartWorkspace(ctx context.Context, req *api.StartWorkspaceReq
return false, err
}

if createPVC {
// we only calculate the time that PVC restoring from VolumeSnapshot
if createPVC && startContext.VolumeSnapshot != nil && startContext.VolumeSnapshot.VolumeSnapshotName != "" {
err = wait.PollWithContext(ctx, 100*time.Millisecond, time.Minute, pvcRunning(m.Clientset, pvc.Name, pvc.Namespace))
if err != nil {
return false, nil
Expand All @@ -276,8 +280,9 @@ func (m *Manager) StartWorkspace(ctx context.Context, req *api.StartWorkspaceReq
hist, err := m.metrics.volumeRestoreTimeHistVec.GetMetricWithLabelValues(wsType, req.Spec.Class)
if err != nil {
log.WithError(err).WithField("type", wsType).Warn("cannot get volume restore time histogram metric")
} else {
hist.Observe(time.Since(volumeRestoreTime).Seconds())
} else if endTime.IsZero() {
endTime = time.Now()
hist.Observe(endTime.Sub(startTime).Seconds())
}
}

Expand Down