diff --git a/cmd/swarm/swarm-smoke/main.go b/cmd/swarm/swarm-smoke/main.go index f1e50372ec..ea419e9fac 100644 --- a/cmd/swarm/swarm-smoke/main.go +++ b/cmd/swarm/swarm-smoke/main.go @@ -141,12 +141,8 @@ func main() { sort.Sort(cli.FlagsByName(app.Flags)) sort.Sort(cli.CommandsByName(app.Commands)) - app.Before = func(ctx *cli.Context) error { - return nil - } app.After = func(ctx *cli.Context) error { - emitMetrics(ctx) - return nil + return emitMetrics(ctx) } err := app.Run(os.Args) @@ -157,7 +153,7 @@ func main() { } } -func emitMetrics(ctx *cli.Context) { +func emitMetrics(ctx *cli.Context) error { if gethmetrics.Enabled { var ( endpoint = ctx.GlobalString(swarmmetrics.MetricsInfluxDBEndpointFlag.Name) @@ -166,8 +162,7 @@ func emitMetrics(ctx *cli.Context) { password = ctx.GlobalString(swarmmetrics.MetricsInfluxDBPasswordFlag.Name) hosttag = ctx.GlobalString(swarmmetrics.MetricsInfluxDBHostTagFlag.Name) ) - - influxdb.InfluxDBWithTagsOnce(gethmetrics.DefaultRegistry, endpoint, database, username, password, "swarm-smoke.", map[string]string{ + return influxdb.InfluxDBWithTagsOnce(gethmetrics.DefaultRegistry, endpoint, database, username, password, "swarm-smoke.", map[string]string{ "host": hosttag, "version": gitCommit, "filesize": fmt.Sprintf("%v", filesize), diff --git a/metrics/influxdb/influxdb.go b/metrics/influxdb/influxdb.go index 5f99bb0146..1c2b04bf82 100644 --- a/metrics/influxdb/influxdb.go +++ b/metrics/influxdb/influxdb.go @@ -1,6 +1,7 @@ package influxdb import ( + "errors" "fmt" uurl "net/url" "time" @@ -59,11 +60,10 @@ func InfluxDBWithTags(r metrics.Registry, d time.Duration, url, database, userna } // InfluxDBWithTagsOnce runs once an InfluxDB reporter and post the given metrics.Registry with the specified tags -func InfluxDBWithTagsOnce(r metrics.Registry, url, database, username, password, namespace string, tags map[string]string) { +func InfluxDBWithTagsOnce(r metrics.Registry, url, database, username, password, namespace string, tags map[string]string) error { u, err := uurl.Parse(url) if err != nil { - log.Warn("Unable to parse InfluxDB", "url", url, "err", err) - return + return errors.New(fmt.Sprintf("Unable to parse InfluxDB. url: %s, err: %v", url, err)) } rep := &reporter{ @@ -77,13 +77,14 @@ func InfluxDBWithTagsOnce(r metrics.Registry, url, database, username, password, cache: make(map[string]int64), } if err := rep.makeClient(); err != nil { - log.Warn("Unable to make InfluxDB client", "err", err) - return + return errors.New(fmt.Sprintf("Unable to make InfluxDB client. err: %v", err)) } if err := rep.send(); err != nil { - log.Warn("Unable to send to InfluxDB", "err", err) + return errors.New(fmt.Sprintf("Unable to send to InfluxDB. err: %v", err)) } + + return nil } func (r *reporter) makeClient() (err error) {