add log flags

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-17 23:23:02 -06:00
parent 375e4f2117
commit 0b78c1f2d1
5 changed files with 58 additions and 7 deletions

View File

@ -45,5 +45,5 @@ clean:
git-clone: git-clone:
go-clone --recursive go.wit.com/apps/zookeeper go-clone --recursive go.wit.com/apps/zookeeper
http-list-packages: http-toogle-ZOOD:
curl --silent http://localhost:2521/list?hostname=zookeeper.wit.com curl --silent http://localhost:8080/flag?flag=ZOOD

16
argv.go
View File

@ -7,6 +7,7 @@ package main
import ( import (
"go.wit.com/dev/alexflint/arg" "go.wit.com/dev/alexflint/arg"
"go.wit.com/log"
) )
var argv args var argv args
@ -29,3 +30,18 @@ func (a args) Description() string {
this daemon talks to zookeeper 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")
}

25
http.go
View File

@ -17,10 +17,11 @@ func cleanURL(url string) string {
} }
func okHandler(w http.ResponseWriter, r *http.Request) { 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) route := cleanURL(r.URL.Path)
hostname := r.URL.Query().Get("hostname") hostname := r.URL.Query().Get("hostname")
flag := r.URL.Query().Get("flag")
msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
if err != nil { if err != nil {
@ -40,7 +41,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
log.Info("error =", err) log.Info("error =", err)
return 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) { switch updateMachine(m) {
case "upgrade": case "upgrade":
fmt.Fprintln(w, "upgrade") fmt.Fprintln(w, "upgrade")
@ -69,6 +70,26 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return 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) log.Warn("BAD URL =", route)
} }

View File

@ -13,11 +13,11 @@ func updateMachine(u *zoopb.Machine) string {
} }
m := me.machines.FindByName(u.Hostname) m := me.machines.FindByName(u.Hostname)
if m == nil { if m == nil {
log.Info("did not find", u.Hostname) log.Info("adding new machine", u.Hostname)
me.machines.Append(u) me.machines.Append(u)
return "new" return "new"
} }
log.Info("updating machine", m.Hostname) // log.Info("updating machine", m.Hostname)
// did the # of cpus change? // did the # of cpus change?
if m.Cpus != u.Cpus { if m.Cpus != u.Cpus {

View File

@ -39,7 +39,21 @@ func NewWatchdog() {
fmt.Println("Done!") fmt.Println("Done!")
return return
case t := <-me.dog.C: 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.pollHypervisor()
// h.Scan() // h.Scan()
} }