Skip to content

Commit

Permalink
log probes
Browse files Browse the repository at this point in the history
  • Loading branch information
dprotaso committed Mar 19, 2023
1 parent 8fa534b commit 296ce46
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ import (

// InitHandlers initializes all handlers.
func InitHandlers(mux *http.ServeMux) {
mux.HandleFunc("/", withHeaders(withRequestLog(runtimeHandler)))
mux.HandleFunc("/", withHeaders(runtimeHandler))

h := probe.NewHandler(withRequestLog(withKubeletProbeHeaderCheck))
h := probe.NewHandler(http.HandlerFunc(withKubeletProbeHeaderCheck))
mux.HandleFunc(nethttp.HealthCheckPath, h.ServeHTTP)
}

// withRequestLog logs each request before handling it.
func withRequestLog(next http.HandlerFunc) http.HandlerFunc {
func WithRequestLog(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
reqDump, err := httputil.DumpRequest(r, true)
if err != nil {
Expand Down Expand Up @@ -73,6 +73,6 @@ func withHeaders(next http.HandlerFunc) http.HandlerFunc {
func writeJSON(w http.ResponseWriter, o interface{}) {
w.WriteHeader(http.StatusOK)
e := json.NewEncoder(w)
e.SetIndent("", "\t")
// e.SetIndent("", "\t")
e.Encode(o)
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ func main() {
mux := http.NewServeMux()
handlers.InitHandlers(mux)

handler := handlers.WithRequestLog(mux.ServeHTTP)

if cert, key := os.Getenv("CERT"), os.Getenv("KEY"); cert != "" && key != "" {
log.Print("Server starting on port with TLS ", port)
test.ListenAndServeTLSGracefullyWithHandler(cert, key, ":"+port, mux)
test.ListenAndServeTLSGracefullyWithHandler(cert, key, ":"+port, handler)
} else {
log.Print("Server starting on port ", port)
test.ListenAndServeGracefullyWithHandler(":"+port, mux)
test.ListenAndServeGracefullyWithHandler(":"+port, handler)
}
}

0 comments on commit 296ce46

Please sign in to comment.