From c335c4dc292e6cb355236cd033b6dee195f44827 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 9 Nov 2021 14:14:31 +0100 Subject: [PATCH] config dump endpoint for proxy --- ocis-pkg/service/debug/option.go | 8 ++++++++ ocis-pkg/service/debug/service.go | 4 ++++ proxy/pkg/server/debug/server.go | 16 ++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/ocis-pkg/service/debug/option.go b/ocis-pkg/service/debug/option.go index ef39d9ce4..d33420ca4 100644 --- a/ocis-pkg/service/debug/option.go +++ b/ocis-pkg/service/debug/option.go @@ -20,6 +20,7 @@ type Options struct { Zpages bool Health func(http.ResponseWriter, *http.Request) Ready func(http.ResponseWriter, *http.Request) + ConfigDump func(http.ResponseWriter, *http.Request) CorsAllowedOrigins []string CorsAllowedMethods []string CorsAllowedHeaders []string @@ -100,6 +101,13 @@ func Ready(r func(http.ResponseWriter, *http.Request)) Option { } } +// ConfigDump to be documented. +func ConfigDump(r func(http.ResponseWriter, *http.Request)) Option { + return func(o *Options) { + o.ConfigDump = r + } +} + // CorsAllowedOrigins provides a function to set the CorsAllowedOrigin option. func CorsAllowedOrigins(origins []string) Option { return func(o *Options) { diff --git a/ocis-pkg/service/debug/service.go b/ocis-pkg/service/debug/service.go index e0fc93853..8112618a5 100644 --- a/ocis-pkg/service/debug/service.go +++ b/ocis-pkg/service/debug/service.go @@ -28,6 +28,10 @@ func NewService(opts ...Option) *http.Server { mux.HandleFunc("/healthz", dopts.Health) mux.HandleFunc("/readyz", dopts.Ready) + if dopts.ConfigDump != nil { + mux.HandleFunc("/config", dopts.ConfigDump) + } + if dopts.Pprof { mux.HandleFunc("/debug/pprof/", pprof.Index) mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) diff --git a/proxy/pkg/server/debug/server.go b/proxy/pkg/server/debug/server.go index 2d8bfb738..b4106f2a8 100644 --- a/proxy/pkg/server/debug/server.go +++ b/proxy/pkg/server/debug/server.go @@ -1,6 +1,7 @@ package debug import ( + "encoding/json" "io" "net/http" @@ -22,6 +23,7 @@ func Server(opts ...Option) (*http.Server, error) { debug.Zpages(options.Config.Debug.Zpages), debug.Health(health(options.Config)), debug.Ready(ready(options.Config)), + debug.ConfigDump(configDump(options.Config)), ), nil } @@ -52,3 +54,17 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { } } } + +// configDump implements the config dump +func configDump(cfg *config.Config) func(http.ResponseWriter, *http.Request) { + return func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + + b, err := json.Marshal(cfg) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + } + + _, _ = w.Write(b) + } +}