Skip to content

Commit c5d6e15

Browse files
author
Jeff Peeler
committed
fix(metrics): add logging and separate muxer in catalog
1 parent 4fc6319 commit c5d6e15

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

cmd/catalog/main.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,35 @@ func main() {
9999
if *tlsCertPath != "" && *tlsKeyPath == "" || *tlsCertPath == "" && *tlsKeyPath != "" {
100100
logger.Warn("both --tls-key and --tls-crt must be provided for TLS to be enabled, falling back to non-https")
101101
} else if *tlsCertPath == "" && *tlsKeyPath == "" {
102-
logger.Info("TLS keys not set, using non-https")
102+
logger.Info("TLS keys not set, using non-https for metrics")
103103
} else {
104+
logger.Info("TLS keys set, using https for metrics")
104105
useTLS = true
105106
}
106107

107108
// Serve a health check.
108-
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
109+
healthMux := http.NewServeMux()
110+
healthMux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
109111
w.WriteHeader(http.StatusOK)
110112
})
111-
go http.ListenAndServe(":8080", nil)
113+
go http.ListenAndServe(":8080", healthMux)
112114

113-
http.Handle("/metrics", promhttp.Handler())
115+
metricsMux := http.NewServeMux()
116+
metricsMux.Handle("/metrics", promhttp.Handler())
114117
if useTLS {
115-
go http.ListenAndServeTLS(":8081", *tlsCertPath, *tlsKeyPath, nil)
118+
go func() {
119+
err := http.ListenAndServeTLS(":8081", *tlsCertPath, *tlsKeyPath, metricsMux)
120+
if err != nil {
121+
logger.Errorf("Metrics (https) serving failed: %v", err)
122+
}
123+
}()
116124
} else {
117-
go http.ListenAndServe(":8081", nil)
125+
go func() {
126+
err := http.ListenAndServe(":8081", metricsMux)
127+
if err != nil {
128+
logger.Errorf("Metrics (http) serving failed: %v", err)
129+
}
130+
}()
118131
}
119132

120133
// create a config client for operator status

0 commit comments

Comments
 (0)