mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-09-30 12:01:15 +02:00
Controller: emit lifecycle events when the VM gets restarted or deleted (#208)
* Controller: emit lifecycle events when the VM gets restarted or deleted
* vm_{scheduling,run}_time → vm_{scheduling,run}_duration for clarity
* Update VM endpoint: only update VM started time when zero
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package lifecycle
|
||||
|
||||
import (
|
||||
v1 "github.com/cirruslabs/orchard/pkg/resource/v1"
|
||||
"go.uber.org/zap"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Report(vm *v1.VM, message string, logger *zap.SugaredLogger) {
|
||||
args := []interface{}{
|
||||
"component", "lifecycle",
|
||||
"vm_uid", vm.UID,
|
||||
"vm_name", vm.Name,
|
||||
"vm_restart_count", vm.RestartCount,
|
||||
"vm_image", vm.Image,
|
||||
"vm_status", vm.Status,
|
||||
}
|
||||
|
||||
if vm.ScheduledAt.IsZero() {
|
||||
// VM was never scheduled
|
||||
args = append(args, "vm_scheduling_duration", time.Since(vm.CreatedAt))
|
||||
} else {
|
||||
args = append(args, "vm_scheduling_duration", vm.ScheduledAt.Sub(vm.CreatedAt))
|
||||
}
|
||||
|
||||
if vm.StartedAt.IsZero() {
|
||||
// VM was never started
|
||||
args = append(args, "vm_run_duration", time.Duration(0))
|
||||
} else {
|
||||
args = append(args, "vm_run_duration", time.Since(vm.StartedAt))
|
||||
}
|
||||
|
||||
logger.With(args...).Info(message)
|
||||
}
|
||||
Reference in New Issue
Block a user