@@ -123,22 +123,40 @@ func main() {
123
123
if * tlsCertPath != "" && * tlsKeyPath == "" || * tlsCertPath == "" && * tlsKeyPath != "" {
124
124
logger .Warn ("both --tls-key and --tls-crt must be provided for TLS to be enabled, falling back to non-https" )
125
125
} else if * tlsCertPath == "" && * tlsKeyPath == "" {
126
- logger .Info ("TLS keys not set, using non-https" )
126
+ logger .Info ("TLS keys not set, using non-https for metrics " )
127
127
} else {
128
+ logger .Info ("TLS keys set, using https for metrics" )
128
129
useTLS = true
129
130
}
130
131
131
132
// Serve a health check.
132
- http .HandleFunc ("/healthz" , func (w http.ResponseWriter , r * http.Request ) {
133
+ healthMux := http .NewServeMux ()
134
+ healthMux .HandleFunc ("/healthz" , func (w http.ResponseWriter , r * http.Request ) {
133
135
w .WriteHeader (http .StatusOK )
134
136
})
135
- go http .ListenAndServe (":8080" , nil )
137
+ go func () {
138
+ err := http .ListenAndServe (":8080" , healthMux )
139
+ if err != nil {
140
+ logger .Errorf ("Health serving failed: %v" , err )
141
+ }
142
+ }()
136
143
137
- http .Handle ("/metrics" , promhttp .Handler ())
144
+ metricsMux := http .NewServeMux ()
145
+ metricsMux .Handle ("/metrics" , promhttp .Handler ())
138
146
if useTLS {
139
- go http .ListenAndServeTLS (":8081" , * tlsCertPath , * tlsKeyPath , nil )
147
+ go func () {
148
+ err := http .ListenAndServeTLS (":8081" , * tlsCertPath , * tlsKeyPath , metricsMux )
149
+ if err != nil {
150
+ logger .Errorf ("Metrics (https) serving failed: %v" , err )
151
+ }
152
+ }()
140
153
} else {
141
- go http .ListenAndServe (":8081" , nil )
154
+ go func () {
155
+ err := http .ListenAndServe (":8081" , metricsMux )
156
+ if err != nil {
157
+ logger .Errorf ("Metrics (http) serving failed: %v" , err )
158
+ }
159
+ }()
142
160
}
143
161
144
162
ready , done , sync := operator .Run (stopCh )
0 commit comments