Do not require "experimental" for metrics API

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2020-01-29 17:51:01 +01:00
parent 71626b7bdf
commit f337a8d21d
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
3 changed files with 12 additions and 12 deletions

View File

@ -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)

View File

@ -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

View File

@ -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