From 0b78c1f2d15608a9f6ddfaa977ef0f44dab77073 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 17 Nov 2024 23:23:02 -0600 Subject: [PATCH] add log flags Signed-off-by: Jeff Carr --- Makefile | 4 ++-- argv.go | 16 ++++++++++++++++ http.go | 25 +++++++++++++++++++++++-- machine.go | 4 ++-- watchdog.go | 16 +++++++++++++++- 5 files changed, 58 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 61bbc87..190098d 100644 --- a/Makefile +++ b/Makefile @@ -45,5 +45,5 @@ clean: git-clone: go-clone --recursive go.wit.com/apps/zookeeper -http-list-packages: - curl --silent http://localhost:2521/list?hostname=zookeeper.wit.com +http-toogle-ZOOD: + curl --silent http://localhost:8080/flag?flag=ZOOD diff --git a/argv.go b/argv.go index 85dcf75..80635c5 100644 --- a/argv.go +++ b/argv.go @@ -7,6 +7,7 @@ package main import ( "go.wit.com/dev/alexflint/arg" + "go.wit.com/log" ) var argv args @@ -29,3 +30,18 @@ func (a args) Description() string { this daemon talks to zookeeper ` } + +var NOW *log.LogFlag +var INFO *log.LogFlag +var ZOOD *log.LogFlag +var WARN *log.LogFlag + +func init() { + full := "go.wit.com/apps/zookeeper" + short := "zookeeper" + + NOW = log.NewFlag("NOW", true, full, short, "useful while doing debugging") + INFO = log.NewFlag("INFO", false, full, short, "general zookeeper") + ZOOD = log.NewFlag("ZOOD", false, full, short, "show reporting from zood") + WARN = log.NewFlag("WARN", true, full, short, "bad things") +} diff --git a/http.go b/http.go index 7c19a3a..0460896 100644 --- a/http.go +++ b/http.go @@ -17,10 +17,11 @@ func cleanURL(url string) string { } func okHandler(w http.ResponseWriter, r *http.Request) { - log.Info("Got URL Path: ", r.URL.Path) + // log.Info("Got URL Path: ", r.URL.Path) route := cleanURL(r.URL.Path) hostname := r.URL.Query().Get("hostname") + flag := r.URL.Query().Get("flag") msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte if err != nil { @@ -40,7 +41,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) { log.Info("error =", err) return } - log.Info("proto.Unmarshal() worked on wire message len", len(msg), "from", m.Hostname) + log.Log(ZOOD, "proto.Unmarshal() worked on wire message len", len(msg), "from", m.Hostname) switch updateMachine(m) { case "upgrade": fmt.Fprintln(w, "upgrade") @@ -69,6 +70,26 @@ func okHandler(w http.ResponseWriter, r *http.Request) { return } + // toggle logging flags + if route == "/flag" { + log.HttpMode(w) + defer log.HttpMode(nil) + log.Info("going to toggle flag:", flag) + switch flag { + case "ZOOD": + if ZOOD.Bool() { + log.Log(NOW, "toogle ZOOD false") + ZOOD.SetBool(false) + } else { + log.Log(NOW, "toogle ZOOD true") + ZOOD.SetBool(true) + } + default: + log.Info("unknown looging flag:", flag) + } + return + } + log.Warn("BAD URL =", route) } diff --git a/machine.go b/machine.go index 907b51d..3f4d23e 100644 --- a/machine.go +++ b/machine.go @@ -13,11 +13,11 @@ func updateMachine(u *zoopb.Machine) string { } m := me.machines.FindByName(u.Hostname) if m == nil { - log.Info("did not find", u.Hostname) + log.Info("adding new machine", u.Hostname) me.machines.Append(u) return "new" } - log.Info("updating machine", m.Hostname) + // log.Info("updating machine", m.Hostname) // did the # of cpus change? if m.Cpus != u.Cpus { diff --git a/watchdog.go b/watchdog.go index 6c90492..0609bb3 100644 --- a/watchdog.go +++ b/watchdog.go @@ -39,7 +39,21 @@ func NewWatchdog() { fmt.Println("Done!") return case t := <-me.dog.C: - log.Info("zookeeper Watchdog() ticked", me.hostname, "Current time: ", t) + // log.Info("zookeeper Watchdog() ticked", me.hostname, "Current time: ", t) + var counter int + loop := me.machines.SortByName() + for loop.Scan() { + m := loop.Machine() + counter += 1 + zood := m.FindPackageByName("zood") + if zood == nil { + log.Info("machine", m.Hostname, "does not have zood installed") + } else { + // log.Info("know about machine", m.Hostname, "zood version", zood.Version) + } + } + log.Info("zookeeper has", counter, "machines. Current time:", t) + // h.pollHypervisor() // h.Scan() }