Skip to content

Commit

Permalink
Only measure until final phase
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Hallisey <[email protected]>
  • Loading branch information
rthallisey committed Sep 9, 2021
1 parent 43784ed commit 45a75b0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
1 change: 1 addition & 0 deletions pkg/monitoring/perfscale/perfscale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var _ = Describe("VMI phase transition time histogram", func() {
table.Entry("Time between running and scheduled using fraction of a second", .5, v1.Running, v1.Scheduled),
table.Entry("Time between scheduled and scheduling", 2.0, v1.Scheduled, v1.Scheduling),
table.Entry("Time between scheduling and pending", 1.0, v1.Scheduling, v1.Pending),
table.Entry("Time between running and failed", 1.0, v1.Running, v1.Failed),
)
})

Expand Down
22 changes: 7 additions & 15 deletions pkg/monitoring/perfscale/vmi-phase-transitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ func getTransitionTimeSeconds(fromCreation bool, fromDeletion bool, oldVMI *v1.V

if fromCreation || oldVMI == nil || (oldVMI.Status.Phase == v1.VmPhaseUnset) {
oldTime = newVMI.CreationTimestamp.DeepCopy()
} else if fromDeletion {
} else if fromDeletion && newVMI.IsMarkedForDeletion() {
oldTime = newVMI.DeletionTimestamp.DeepCopy()
} else if fromDeletion && !newVMI.IsMarkedForDeletion() {
return 0.0, fmt.Errorf("missing deletion timestamp")
}

for _, transitionTimestamp := range newVMI.Status.PhaseTransitionTimestamps {
Expand Down Expand Up @@ -131,10 +133,6 @@ func newVMIPhaseTransitionTimeHistogramVec(informer cache.SharedIndexInformer) *
}

func updateVMIPhaseTransitionTimeFromCreationTimeHistogramVec(histogramVec *prometheus.HistogramVec, oldVMI *v1.VirtualMachineInstance, newVMI *v1.VirtualMachineInstance) {
if newVMI.IsMarkedForDeletion() {
return
}

if oldVMI == nil || oldVMI.Status.Phase == newVMI.Status.Phase {
return
}
Expand Down Expand Up @@ -194,10 +192,7 @@ func newVMIPhaseTransitionTimeFromCreationHistogramVec(informer cache.SharedInde

informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
UpdateFunc: func(oldVMI, newVMI interface{}) {
vmi := newVMI.(*v1.VirtualMachineInstance)
if !vmi.IsMarkedForDeletion() {
updateVMIPhaseTransitionTimeFromCreationTimeHistogramVec(histogramVec, oldVMI.(*v1.VirtualMachineInstance), vmi)
}
updateVMIPhaseTransitionTimeFromCreationTimeHistogramVec(histogramVec, oldVMI.(*v1.VirtualMachineInstance), newVMI.(*v1.VirtualMachineInstance))
},
})
return histogramVec
Expand All @@ -217,12 +212,9 @@ func newVMIPhaseTransitionTimeFromDeletionHistogramVec(informer cache.SharedInde

informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
UpdateFunc: func(oldVMI, newVMI interface{}) {
// User is deleting a VM. Record time to deletion.
// Stop recording when VMI finalizer is removed
vmi := newVMI.(*v1.VirtualMachineInstance)
if vmi.IsMarkedForDeletion() {
updateVMIPhaseTransitionTimeFromDeletionTimeHistogramVec(histogramVec, oldVMI.(*v1.VirtualMachineInstance), vmi)
}
// User is deleting a VM. Record the time from the
// deletionTimestamp to when the VMI enters the final phase
updateVMIPhaseTransitionTimeFromDeletionTimeHistogramVec(histogramVec, oldVMI.(*v1.VirtualMachineInstance), newVMI.(*v1.VirtualMachineInstance))
},
})
return histogramVec
Expand Down

0 comments on commit 45a75b0

Please sign in to comment.