From a6a20fb6e075ac4b44b78122e49b8327990d88f6 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Wed, 8 Jul 2020 23:08:37 +0100 Subject: [PATCH] monitoring: Add a config dump handler This patch adds a handler to the monitoring HTTP server which dumps the parsed config, so it can easily be reviewed for troubleshooting. --- monitoring.go | 9 +++++++++ test/t-09-loop/run.sh | 2 ++ 2 files changed, 11 insertions(+) diff --git a/monitoring.go b/monitoring.go index dbb0371..1f6827f 100644 --- a/monitoring.go +++ b/monitoring.go @@ -10,6 +10,7 @@ import ( "blitiri.com.ar/go/chasquid/internal/config" "blitiri.com.ar/go/log" + "google.golang.org/protobuf/encoding/prototext" // To enable live profiling in the monitoring server. _ "net/http/pprof" @@ -45,6 +46,7 @@ func launchMonitoringServer(conf *config.Config) { }) http.HandleFunc("/debug/flags", debugFlagsHandler) + http.HandleFunc("/debug/config", debugConfigHandler(conf)) go http.ListenAndServe(conf.MonitoringAddress, nil) } @@ -94,6 +96,7 @@ os hostname {{.Hostname}}

  • execution
  • pprof @@ -124,6 +127,12 @@ func debugFlagsHandler(w http.ResponseWriter, r *http.Request) { }) } +func debugConfigHandler(conf *config.Config) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + _, _ = w.Write([]byte(prototext.Format(conf))) + } +} + func roundDuration(d time.Duration) time.Duration { return d.Round(time.Second) } diff --git a/test/t-09-loop/run.sh b/test/t-09-loop/run.sh index 5b8a5e1..7b6b1ec 100755 --- a/test/t-09-loop/run.sh +++ b/test/t-09-loop/run.sh @@ -40,6 +40,8 @@ wget -q -o /dev/null -O .data-A/dbg-flags http://localhost:1099/debug/flags \ || fail "failed to fetch /debug/flags" wget -q -o /dev/null -O .data-A/dbg-queue http://localhost:1099/debug/queue \ || fail "failed to fetch /debug/queue" +wget -q -o /dev/null -O .data-A/dbg-config http://localhost:1099/debug/config \ + || fail "failed to fetch /debug/config" wget -q -o /dev/null -O .data-A/dbg-root http://localhost:1099/404 \ && fail "fetch /404 worked, should have failed"