From c3a69690eee158e676d7ce7a5aa3088a1dc7fc7a Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 17 Oct 2024 15:29:47 -0500 Subject: [PATCH] clean up logging of initial scan of droplets Signed-off-by: Jeff Carr --- README | 1 + event.go | 3 +++ http.go | 2 +- poll.go | 49 ++++++++++++++++++++++++++++++++----------------- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/README b/README index d56d2af..ed285cf 100644 --- a/README +++ b/README @@ -16,6 +16,7 @@ Notes & Goals: * Be super easy to use. * Automatically map access to serial and graphical consoles +* Only temporarily generate libvirt XML files for virsh create * This is intended for managing Virtual Machines, not for containers * This often uses the DO nomenclature 'droplets' instead of 'virtual machines' or 'domU' * Every droplet is considered hostile diff --git a/event.go b/event.go index 8920bdc..5c26b5d 100644 --- a/event.go +++ b/event.go @@ -23,6 +23,9 @@ func (h *HyperT) RestartDaemon() { dur := time.Since(h.lastpoll) // Calculate the elapsed time log.Info("KILLED DAEMON", h.Hostname, shell.FormatDuration(dur), "curl", url) me.killcount += 1 + + // mark the cluster as unstable so droplet starts can be throttled + me.unstable = time.Now() } var stableTimeout time.Duration = 43 * time.Second diff --git a/http.go b/http.go index 510d7a9..f0af65a 100644 --- a/http.go +++ b/http.go @@ -28,7 +28,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) { } dur := time.Since(d.lastpoll) // Calculate the elapsed time if d.CurrentState != "ON" { - fmt.Fprintln(w, "BAD STATE ", d.Hostname, "State =", d.State, "CurrentState =", d.CurrentState, shell.FormatDuration(dur)) + fmt.Fprintln(w, "BAD STATE ", d.Hostname, d.hname, "(", d.State, "vs", d.CurrentState, ")", shell.FormatDuration(dur)) } else { dur := time.Since(d.lastpoll) // Calculate the elapsed time fmt.Fprintln(w, "GOOD STATE ON", d.Hostname, d.hname, shell.FormatDuration(dur)) diff --git a/poll.go b/poll.go index bc3ea49..f3bd4ce 100644 --- a/poll.go +++ b/poll.go @@ -32,29 +32,44 @@ func (h *HyperT) pollHypervisor() { if state == "ON" { log.Log(POLL, h.Hostname, "STATE:", state, "HOST:", name, "rest:", fields[2:]) d := findDroplet(name) - if d != nil { - log.Log(INFO, "ALREADY RECORDED", d.Hostname) + if d == nil { + // this is a new unknown droplet (not in the config file) + d = new(DropletT) + d.Hostname = name + d.hname = h.Hostname d.lastpoll = time.Now() d.CurrentState = "ON" - // log.Info("ALREADY RECORDED", d.Hostname, d.lastpoll) - if d.hname == "" { - log.Log(EVENT, "DROPLET", d.Hostname, "PROBABLY WAS NEVER POLLED YET") - } - if d.hname != h.Hostname { - log.Log(EVENT, "DROPLET", d.Hostname, "MOVED FROM", d.hname, "TO", h.Hostname) - d.hname = h.Hostname - } + me.droplets = append(me.droplets, d) + log.Log(EVENT, name, "IS NEW. ADDED ON", h.Hostname) + } + log.Log(INFO, "ALREADY RECORDED", d.Hostname) + + // update the status to ON and the last polled value + d.CurrentState = "ON" + d.lastpoll = time.Now() + + // this means the droplet is still where it was before + if d.hname == h.Hostname { continue } - // this is a new unknown droplet (not in the config file) - d = new(DropletT) - d.Hostname = name + + if d.hname == "" { + // this means the droplet was in the config file + // but this is the first time it's shown up as running + + // this should mean a droplet is running where the config file says it probably should be running + if d.hyperPreferred == h.Hostname { + log.Log(EVENT, "new droplet", d.Hostname, "(matches config hypervisor", h.Hostname + ")") + d.hname = h.Hostname + continue + } + + log.Log(EVENT, "new droplet", d.Hostname, "was not in the config file") + log.Log(EVENT, "new droplet", d.Hostname, "moved", d.hname, h.Hostname, "config file hypervisor =", d.hname) + } d.hname = h.Hostname - d.lastpoll = time.Now() - d.CurrentState = "ON" - me.droplets = append(me.droplets, d) - log.Log(EVENT, name, "IS NEW. ADDED ON", h.Hostname) } + continue } h.lastpoll = time.Now() h.killcount = 0 // poll worked. reset killcount