git » chasquid » commit a6a20fb

monitoring: Add a config dump handler

author Alberto Bertogli
2020-07-08 22:08:37 UTC
committer Alberto Bertogli
2020-07-28 01:12:29 UTC
parent 33446fd565ef16eba935bbac9167220282a6d020

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 -0
test/t-09-loop/run.sh +2 -0

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 <i>{{.Hostname}}</i><p>
   <li>execution
     <ul>
       <li><a href="/debug/flags">flags</a>
+      <li><a href="/debug/config">config</a>
       <li><a href="/debug/pprof/cmdline">command line</a>
     </ul>
   <li><a href="/debug/pprof">pprof</a>
@@ -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"