Skip to content

Commit b0bf87e

Browse files
author
Mengqi Yu
committed
⚠️ metrics are now on by default
1 parent da24e0f commit b0bf87e

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

pkg/manager/internal.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,19 @@ func (cm *controllerManager) GetWebhookServer() *webhook.Server {
230230
}
231231

232232
func (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("start to serve metrics", "path", metricsPath)
244246
if err := server.Serve(cm.metricsListener); err != nil && err != http.ErrServerClosed {
245247
cm.errChan <- err
246248
}

pkg/manager/manager.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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.

pkg/metrics/listener.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff 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.
3129
func 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 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 failed to listen. You may want to disable the metrics or use another port if it is due to conflicts")
45+
return nil, er
4546
}
4647
return ln, nil
4748
}

0 commit comments

Comments
 (0)