From f337a8d21d9902772a766f57475a5512405c86c5 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 29 Jan 2020 17:51:01 +0100 Subject: [PATCH] Do not require "experimental" for metrics API Signed-off-by: Sebastiaan van Stijn --- cmd/dockerd/daemon.go | 4 ++-- cmd/dockerd/metrics.go | 14 +++++--------- daemon/metrics_unix.go | 6 +++++- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/dockerd/daemon.go b/cmd/dockerd/daemon.go index 700098601c..929cb9e144 100644 --- a/cmd/dockerd/daemon.go +++ b/cmd/dockerd/daemon.go @@ -204,8 +204,8 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) { cli.d = d - if err := cli.startMetricsServer(cli.Config.MetricsAddress); err != nil { - return err + if err := startMetricsServer(cli.Config.MetricsAddress); err != nil { + return errors.Wrap(err, "failed to start metrics server") } c, err := createAndStartCluster(cli, d) diff --git a/cmd/dockerd/metrics.go b/cmd/dockerd/metrics.go index 2b3c90578e..4ea8321b5d 100644 --- a/cmd/dockerd/metrics.go +++ b/cmd/dockerd/metrics.go @@ -3,21 +3,16 @@ package main import ( "net" "net/http" + "strings" metrics "github.com/docker/go-metrics" - "github.com/pkg/errors" "github.com/sirupsen/logrus" ) -func (cli *DaemonCli) startMetricsServer(addr string) error { +func startMetricsServer(addr string) error { if addr == "" { return nil } - - if !cli.d.HasExperimental() { - return errors.New("metrics-addr is only supported when experimental is enabled") - } - if err := allocateDaemonPort(addr); err != nil { return err } @@ -28,8 +23,9 @@ func (cli *DaemonCli) startMetricsServer(addr string) error { mux := http.NewServeMux() mux.Handle("/metrics", metrics.Handler()) go func() { - if err := http.Serve(l, mux); err != nil { - logrus.Errorf("serve metrics api: %s", err) + logrus.Infof("metrics API listening on %s", l.Addr()) + if err := http.Serve(l, mux); err != nil && !strings.Contains(err.Error(), "use of closed network connection") { + logrus.WithError(err).Error("error serving metrics API") } }() return nil diff --git a/daemon/metrics_unix.go b/daemon/metrics_unix.go index b131ebc3e1..e8bcd88b15 100644 --- a/daemon/metrics_unix.go +++ b/daemon/metrics_unix.go @@ -6,6 +6,7 @@ import ( "net" "net/http" "path/filepath" + "strings" "github.com/docker/docker/pkg/plugingetter" "github.com/docker/docker/pkg/plugins" @@ -28,7 +29,10 @@ func (daemon *Daemon) listenMetricsSock() (string, error) { mux := http.NewServeMux() mux.Handle("/metrics", metrics.Handler()) go func() { - http.Serve(l, mux) + logrus.Debugf("metrics API listening on %s", l.Addr()) + if err := http.Serve(l, mux); err != nil && !strings.Contains(err.Error(), "use of closed network connection") { + logrus.WithError(err).Error("error serving metrics API") + } }() daemon.metricsPluginListener = l return path, nil