Skip to content

Commit b60a6d7

Browse files
jentingroboquat
authored andcommitted
[ws-manager] fix the possibility the volume restore time is incorrect
We might fall into the exponential backoff function, meaning that the volume restore time would be calculated again even if we had already calculated the volume restore time. Signed-off-by: JenTing Hsiao <[email protected]>
1 parent 311d13c commit b60a6d7

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ func (m *Manager) StartWorkspace(ctx context.Context, req *api.StartWorkspaceReq
215215
span.LogKV("event", "pod description created")
216216

217217
var (
218-
createPVC bool
219-
pvc *corev1.PersistentVolumeClaim
220-
volumeRestoreTime time.Time
218+
createPVC bool
219+
pvc *corev1.PersistentVolumeClaim
220+
startTime, endTime time.Time
221221
)
222222
for _, feature := range startContext.Request.Spec.FeatureFlags {
223223
if feature == api.WorkspaceFeatureFlag_PERSISTENT_VOLUME_CLAIM {
@@ -235,7 +235,7 @@ func (m *Manager) StartWorkspace(ctx context.Context, req *api.StartWorkspaceReq
235235
if err != nil && !k8serr.IsAlreadyExists(err) {
236236
return nil, xerrors.Errorf("cannot create pvc object for workspace pod: %w", err)
237237
}
238-
volumeRestoreTime = time.Now()
238+
startTime = time.Now()
239239
}
240240

241241
// create the Pod in the cluster and wait until is scheduled
@@ -276,8 +276,9 @@ func (m *Manager) StartWorkspace(ctx context.Context, req *api.StartWorkspaceReq
276276
hist, err := m.metrics.volumeRestoreTimeHistVec.GetMetricWithLabelValues(wsType, req.Spec.Class)
277277
if err != nil {
278278
log.WithError(err).WithField("type", wsType).Warn("cannot get volume restore time histogram metric")
279-
} else {
280-
hist.Observe(time.Since(volumeRestoreTime).Seconds())
279+
} else if endTime.IsZero() {
280+
endTime = time.Now()
281+
hist.Observe(endTime.Sub(startTime).Seconds())
281282
}
282283
}
283284

0 commit comments

Comments
 (0)