Browse code

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>

HuanHuan Ye authored on 2019/09/11 20:40:11
Showing 2 changed files
... ...
@@ -208,14 +208,10 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
208 208
 		return errors.Wrap(err, "failed to validate authorization plugin")
209 209
 	}
210 210
 
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
219 215
 	}
220 216
 
221 217
 	c, err := createAndStartCluster(cli, d)
... ...
@@ -230,8 +226,6 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
230 230
 
231 231
 	logrus.Info("Daemon has completed initialization")
232 232
 
233
-	cli.d = d
234
-
235 233
 	routerOptions, err := newRouterOptions(cli.Config, d)
236 234
 	if err != nil {
237 235
 		return err
... ...
@@ -5,10 +5,19 @@ import (
5 5
 	"net/http"
6 6
 
7 7
 	"github.com/docker/go-metrics"
8
+	"github.com/pkg/errors"
8 9
 	"github.com/sirupsen/logrus"
9 10
 )
10 11
 
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
+
12 21
 	if err := allocateDaemonPort(addr); err != nil {
13 22
 		return err
14 23
 	}