Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/manager/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,19 @@ func (cm *controllerManager) GetWebhookServer() *webhook.Server {
}

func (cm *controllerManager) serveMetrics(stop <-chan struct{}) {
var metricsPath = "/metrics"
handler := promhttp.HandlerFor(metrics.Registry, promhttp.HandlerOpts{
ErrorHandling: promhttp.HTTPErrorOnError,
})
// TODO(JoelSpeed): Use existing Kubernetes machinery for serving metrics
mux := http.NewServeMux()
mux.Handle("/metrics", handler)
mux.Handle(metricsPath, handler)
server := http.Server{
Handler: mux,
}
// Run the server
go func() {
log.Info("starting metrics server", "path", metricsPath)
if err := server.Serve(cm.metricsListener); err != nil && err != http.ErrServerClosed {
cm.errChan <- err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ type Options struct {
Namespace string

// MetricsBindAddress is the TCP address that the controller should bind to
// for serving prometheus metrics
// for serving prometheus metrics.
// It can be set to "0" to disable the metrics serving.
MetricsBindAddress string

// Port is the port that the webhook server serves at.
Expand Down
13 changes: 7 additions & 6 deletions pkg/metrics/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ import (
"net"
)

// DefaultBindAddress sets the default bind address for the metrics
// listener
// The metrics is off by default.
// TODO: Flip the default by changing DefaultBindAddress back to ":8080" in the v0.2.0.
var DefaultBindAddress = "0"
// DefaultBindAddress sets the default bind address for the metrics listener
// The metrics is on by default.
var DefaultBindAddress = ":8080"

// NewListener creates a new TCP listener bound to the given address.
func NewListener(addr string) (net.Listener, error) {
Expand All @@ -39,9 +37,12 @@ func NewListener(addr string) (net.Listener, error) {
return nil, nil
}

log.Info("metrics server is starting to listen", "addr", addr)
ln, err := net.Listen("tcp", addr)
if err != nil {
return nil, fmt.Errorf("error listening on %s: %v", addr, err)
er := fmt.Errorf("error listening on %s: %v", addr, err)
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")
return nil, er
}
return ln, nil
}