Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 188bdab

Browse files
yedamaothaJeztah
andcommitted
DaemonCli: Move check into startMetricsServer
Fix TODO: move into startMetricsServer() Fix errors.Wrap return nil when passed err is nil Co-Authored-By: Sebastiaan van Stijn <thaJeztah@users.noreply.github.com> Signed-off-by: HuanHuan Ye <logindaveye@gmail.com> (cherry picked from commit 88c554f950d4667595cc2174bfab67d2cc072e62) Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: 68e1150357c4dc56a5f9df3227af9c1b3f457252 Component: engine
1 parent 72f7e5a commit 188bdab

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

components/engine/cmd/dockerd/daemon.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,10 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
208208
return errors.Wrap(err, "failed to validate authorization plugin")
209209
}
210210

211-
// TODO: move into startMetricsServer()
212-
if cli.Config.MetricsAddress != "" {
213-
if !d.HasExperimental() {
214-
return errors.Wrap(err, "metrics-addr is only supported when experimental is enabled")
215-
}
216-
if err := startMetricsServer(cli.Config.MetricsAddress); err != nil {
217-
return err
218-
}
211+
cli.d = d
212+
213+
if err := cli.startMetricsServer(cli.Config.MetricsAddress); err != nil {
214+
return err
219215
}
220216

221217
c, err := createAndStartCluster(cli, d)
@@ -230,8 +226,6 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
230226

231227
logrus.Info("Daemon has completed initialization")
232228

233-
cli.d = d
234-
235229
routerOptions, err := newRouterOptions(cli.Config, d)
236230
if err != nil {
237231
return err

components/engine/cmd/dockerd/metrics.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@ import (
55
"net/http"
66

77
"github.com/docker/go-metrics"
8+
"github.com/pkg/errors"
89
"github.com/sirupsen/logrus"
910
)
1011

11-
func startMetricsServer(addr string) error {
12+
func (cli *DaemonCli) startMetricsServer(addr string) error {
13+
if addr == "" {
14+
return nil
15+
}
16+
17+
if !cli.d.HasExperimental() {
18+
return errors.New("metrics-addr is only supported when experimental is enabled")
19+
}
20+
1221
if err := allocateDaemonPort(addr); err != nil {
1322
return err
1423
}

0 commit comments

Comments
 (0)