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 {
230
230
}
231
231
232
232
func (cm * controllerManager ) serveMetrics (stop <- chan struct {}) {
233
+ var metricsPath = "/metrics"
233
234
handler := promhttp .HandlerFor (metrics .Registry , promhttp.HandlerOpts {
234
235
ErrorHandling : promhttp .HTTPErrorOnError ,
235
236
})
236
237
// TODO(JoelSpeed): Use existing Kubernetes machinery for serving metrics
237
238
mux := http .NewServeMux ()
238
- mux .Handle ("/metrics" , handler )
239
+ mux .Handle (metricsPath , handler )
239
240
server := http.Server {
240
241
Handler : mux ,
241
242
}
242
243
// Run the server
243
244
go func () {
245
+ log .Info ("start to serve metrics" , "path" , metricsPath )
244
246
if err := server .Serve (cm .metricsListener ); err != nil && err != http .ErrServerClosed {
245
247
cm .errChan <- err
246
248
}
Original file line number Diff line number Diff line change @@ -135,7 +135,8 @@ type Options struct {
135
135
Namespace string
136
136
137
137
// 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.
139
140
MetricsBindAddress string
140
141
141
142
// 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 (
21
21
"net"
22
22
)
23
23
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"
29
27
30
28
// NewListener creates a new TCP listener bound to the given address.
31
29
func NewListener (addr string ) (net.Listener , error ) {
@@ -39,9 +37,12 @@ func NewListener(addr string) (net.Listener, error) {
39
37
return nil , nil
40
38
}
41
39
40
+ log .Info ("metrics is starting to listen" , "addr" , addr )
42
41
ln , err := net .Listen ("tcp" , addr )
43
42
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 failed to listen. You may want to disable the metrics or use another port if it is due to conflicts" )
45
+ return nil , er
45
46
}
46
47
return ln , nil
47
48
}
You can’t perform that action at this time.
0 commit comments