File tree Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -230,17 +230,19 @@ func (cm *controllerManager) GetWebhookServer() *webhook.Server {
230230}
231231
232232func (cm * controllerManager ) serveMetrics (stop <- chan struct {}) {
233+ var metricsPath = "/metrics"
233234 handler := promhttp .HandlerFor (metrics .Registry , promhttp.HandlerOpts {
234235 ErrorHandling : promhttp .HTTPErrorOnError ,
235236 })
236237 // TODO(JoelSpeed): Use existing Kubernetes machinery for serving metrics
237238 mux := http .NewServeMux ()
238- mux .Handle ("/metrics" , handler )
239+ mux .Handle (metricsPath , handler )
239240 server := http.Server {
240241 Handler : mux ,
241242 }
242243 // Run the server
243244 go func () {
245+ log .Info ("starting metrics server" , "path" , metricsPath )
244246 if err := server .Serve (cm .metricsListener ); err != nil && err != http .ErrServerClosed {
245247 cm .errChan <- err
246248 }
Original file line number Diff line number Diff line change @@ -135,7 +135,8 @@ type Options struct {
135135 Namespace string
136136
137137 // MetricsBindAddress is the TCP address that the controller should bind to
138- // for serving prometheus metrics
138+ // for serving prometheus metrics.
139+ // It can be set to "0" to disable the metrics serving.
139140 MetricsBindAddress string
140141
141142 // Port is the port that the webhook server serves at.
Original file line number Diff line number Diff line change @@ -21,11 +21,9 @@ import (
2121 "net"
2222)
2323
24- // DefaultBindAddress sets the default bind address for the metrics
25- // listener
26- // The metrics is off by default.
27- // TODO: Flip the default by changing DefaultBindAddress back to ":8080" in the v0.2.0.
28- var DefaultBindAddress = "0"
24+ // DefaultBindAddress sets the default bind address for the metrics listener
25+ // The metrics is on by default.
26+ var DefaultBindAddress = ":8080"
2927
3028// NewListener creates a new TCP listener bound to the given address.
3129func NewListener (addr string ) (net.Listener , error ) {
@@ -39,9 +37,12 @@ func NewListener(addr string) (net.Listener, error) {
3937 return nil , nil
4038 }
4139
40+ log .Info ("metrics server is starting to listen" , "addr" , addr )
4241 ln , err := net .Listen ("tcp" , addr )
4342 if err != nil {
44- return nil , fmt .Errorf ("error listening on %s: %v" , addr , err )
43+ er := fmt .Errorf ("error listening on %s: %v" , addr , err )
44+ log .Error (er , "metrics server failed to listen. You may want to disable the metrics server or use another port if it is due to conflicts" )
45+ return nil , er
4546 }
4647 return ln , nil
4748}
You can’t perform that action at this time.
0 commit comments