From 86f5697fcae000f619a33d922bb5a256f6b5cdf8 Mon Sep 17 00:00:00 2001 From: Rafael Matias Date: Mon, 25 Mar 2019 18:54:35 +0100 Subject: [PATCH] cmd/swarm/swarm-smoke-pss: extract pss smoke test to different binary --- cmd/swarm/swarm-smoke-pss/main.go | 150 ++++++++++++++++++ .../{swarm-smoke => swarm-smoke-pss}/pss.go | 5 +- cmd/swarm/swarm-smoke-pss/util.go | 68 ++++++++ cmd/swarm/swarm-smoke/main.go | 35 ++-- swarm/docker/Dockerfile | 17 +- 5 files changed, 241 insertions(+), 34 deletions(-) create mode 100644 cmd/swarm/swarm-smoke-pss/main.go rename cmd/swarm/{swarm-smoke => swarm-smoke-pss}/pss.go (98%) create mode 100644 cmd/swarm/swarm-smoke-pss/util.go diff --git a/cmd/swarm/swarm-smoke-pss/main.go b/cmd/swarm/swarm-smoke-pss/main.go new file mode 100644 index 0000000000..f471bc9bc4 --- /dev/null +++ b/cmd/swarm/swarm-smoke-pss/main.go @@ -0,0 +1,150 @@ +// Copyright 2018 The go-ethereum Authors +// This file is part of go-ethereum. +// +// go-ethereum is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// go-ethereum is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with go-ethereum. If not, see . + +package main + +import ( + "os" + "sort" + + "github.com/ethereum/go-ethereum/cmd/utils" + gethmetrics "github.com/ethereum/go-ethereum/metrics" + "github.com/ethereum/go-ethereum/metrics/influxdb" + swarmmetrics "github.com/ethereum/go-ethereum/swarm/metrics" + "github.com/ethereum/go-ethereum/swarm/tracing" + + "github.com/ethereum/go-ethereum/log" + + cli "gopkg.in/urfave/cli.v1" +) + +var ( + gitCommit string // Git SHA1 commit hash of the release (set via linker flags) +) + +var ( + allhosts string + hosts []string + filesize int + inputSeed int + wsPort int + verbosity int + timeout int + pssMessageCount int +) + +func main() { + + app := cli.NewApp() + app.Name = "smoke-test-pss" + app.Usage = "" + + app.Flags = []cli.Flag{ + cli.StringFlag{ + Name: "hosts", + Value: "", + Usage: "comma-separated list of swarm hosts", + Destination: &allhosts, + }, + cli.IntFlag{ + Name: "ws-port", + Value: 8546, + Usage: "ws port", + Destination: &wsPort, + }, + cli.IntFlag{ + Name: "seed", + Value: 0, + Usage: "input seed in case we need deterministic upload", + Destination: &inputSeed, + }, + cli.IntFlag{ + Name: "verbosity", + Value: 1, + Usage: "verbosity", + Destination: &verbosity, + }, + cli.IntFlag{ + Name: "timeout", + Value: 120, + Usage: "timeout in seconds after which kill the process", + Destination: &timeout, + }, + cli.IntFlag{ + Name: "pss-messages", + Value: 10, + Usage: "number of pss messages that should be send in the pss smoke test", + Destination: &pssMessageCount, + }, + } + + app.Flags = append(app.Flags, []cli.Flag{ + utils.MetricsEnabledFlag, + swarmmetrics.MetricsInfluxDBEndpointFlag, + swarmmetrics.MetricsInfluxDBDatabaseFlag, + swarmmetrics.MetricsInfluxDBUsernameFlag, + swarmmetrics.MetricsInfluxDBPasswordFlag, + swarmmetrics.MetricsInfluxDBTagsFlag, + }...) + + app.Flags = append(app.Flags, tracing.Flags...) + + app.Commands = []cli.Command{ + { + Name: "pss-asym", + Aliases: []string{"pa"}, + Usage: "PSS: send and receive multiple messages across random nodes using asymmetric encryption", + Action: wrapCliCommand("pss-asym", pssAsymCheck), + }, + } + + sort.Sort(cli.FlagsByName(app.Flags)) + sort.Sort(cli.CommandsByName(app.Commands)) + + app.Before = func(ctx *cli.Context) error { + tracing.Setup(ctx) + return nil + } + + app.After = func(ctx *cli.Context) error { + return emitMetrics(ctx) + } + + err := app.Run(os.Args) + if err != nil { + log.Error(err.Error()) + os.Exit(1) + } +} + +func emitMetrics(ctx *cli.Context) error { + if gethmetrics.Enabled { + var ( + endpoint = ctx.GlobalString(swarmmetrics.MetricsInfluxDBEndpointFlag.Name) + database = ctx.GlobalString(swarmmetrics.MetricsInfluxDBDatabaseFlag.Name) + username = ctx.GlobalString(swarmmetrics.MetricsInfluxDBUsernameFlag.Name) + password = ctx.GlobalString(swarmmetrics.MetricsInfluxDBPasswordFlag.Name) + tags = ctx.GlobalString(swarmmetrics.MetricsInfluxDBTagsFlag.Name) + ) + + tagsMap := utils.SplitTagsFlag(tags) + tagsMap["version"] = gitCommit + + return influxdb.InfluxDBWithTagsOnce(gethmetrics.DefaultRegistry, endpoint, database, username, password, "swarm-smoke-pss.", tagsMap) + } + + return nil +} diff --git a/cmd/swarm/swarm-smoke/pss.go b/cmd/swarm/swarm-smoke-pss/pss.go similarity index 98% rename from cmd/swarm/swarm-smoke/pss.go rename to cmd/swarm/swarm-smoke-pss/pss.go index 6f65a96c8b..664ced7ccc 100644 --- a/cmd/swarm/swarm-smoke/pss.go +++ b/cmd/swarm/swarm-smoke-pss/pss.go @@ -123,8 +123,9 @@ func pssSetup() *pssSession { // set up the necessary info for each pss node for i, host := range hosts { - httpHost := fmt.Sprintf("ws://%s:%d", host, 8546) - rpcClient, err := rpc.Dial(httpHost) + wsHost := wsEndpoint(host) + + rpcClient, err := rpc.Dial(wsHost) if err != nil { log.Error("Error dialing host", "err", err) continue diff --git a/cmd/swarm/swarm-smoke-pss/util.go b/cmd/swarm/swarm-smoke-pss/util.go new file mode 100644 index 0000000000..3d54b2027a --- /dev/null +++ b/cmd/swarm/swarm-smoke-pss/util.go @@ -0,0 +1,68 @@ +// Copyright 2018 The go-ethereum Authors +// This file is part of go-ethereum. +// +// go-ethereum is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// go-ethereum is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with go-ethereum. If not, see . + +package main + +import ( + "fmt" + "math/rand" + "os" + "strings" + "time" + + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/metrics" + "github.com/pborman/uuid" + cli "gopkg.in/urfave/cli.v1" +) + +var ( + commandName = "" + seed = int(time.Now().UTC().UnixNano()) +) + +func init() { + rand.Seed(int64(seed)) +} + +func wsEndpoint(host string) string { + return fmt.Sprintf("ws://%s:%d", host, wsPort) +} + +func wrapCliCommand(name string, command func(*cli.Context, string) error) func(*cli.Context) error { + return func(ctx *cli.Context) error { + log.PrintOrigins(true) + log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(verbosity), log.StreamHandler(os.Stdout, log.TerminalFormat(false)))) + + // test uuid + tuid := uuid.New()[:8] + + commandName = name + + hosts = strings.Split(allhosts, ",") + + defer func(now time.Time) { + totalTime := time.Since(now) + log.Info("total time", "tuid", tuid, "time", totalTime) + metrics.GetOrRegisterResettingTimer(name+".total-time", nil).Update(totalTime) + }(time.Now()) + + log.Info("smoke test starting", "tuid", tuid, "task", name, "timeout", timeout) + metrics.GetOrRegisterCounter(name, nil).Inc(1) + + return command(ctx, tuid) + } +} diff --git a/cmd/swarm/swarm-smoke/main.go b/cmd/swarm/swarm-smoke/main.go index 08a0354cd2..860fbcc1dd 100644 --- a/cmd/swarm/swarm-smoke/main.go +++ b/cmd/swarm/swarm-smoke/main.go @@ -37,18 +37,17 @@ var ( ) var ( - allhosts string - hosts []string - filesize int - inputSeed int - syncDelay int - httpPort int - wsPort int - verbosity int - timeout int - single bool - trackTimeout int - pssMessageCount int + allhosts string + hosts []string + filesize int + inputSeed int + syncDelay int + httpPort int + wsPort int + verbosity int + timeout int + single bool + trackTimeout int ) func main() { @@ -117,12 +116,6 @@ func main() { Usage: "timeout in seconds to wait for GetAllReferences to return", Destination: &trackTimeout, }, - cli.IntFlag{ - Name: "pss-messages", - Value: 10, - Usage: "number of pss messages that should be send in the pss smoke test", - Destination: &pssMessageCount, - }, } app.Flags = append(app.Flags, []cli.Flag{ @@ -161,12 +154,6 @@ func main() { Usage: "measure network aggregate capacity", Action: wrapCliCommand("sliding-window", slidingWindowCmd), }, - { - Name: "pss-asym", - Aliases: []string{"pa"}, - Usage: "PSS: send and receive multiple messages across random nodes using asymmetric encryption", - Action: wrapCliCommand("pss-asym", pssAsymCheck), - }, } sort.Sort(cli.FlagsByName(app.Flags)) diff --git a/swarm/docker/Dockerfile b/swarm/docker/Dockerfile index 9450609dd8..6330ee2e17 100644 --- a/swarm/docker/Dockerfile +++ b/swarm/docker/Dockerfile @@ -4,19 +4,20 @@ ARG VERSION RUN apk add --update git gcc g++ linux-headers RUN mkdir -p $GOPATH/src/github.com/ethereum && \ - cd $GOPATH/src/github.com/ethereum && \ - git clone https://github.com/ethersphere/go-ethereum && \ - cd $GOPATH/src/github.com/ethereum/go-ethereum && \ - git checkout ${VERSION} && \ - go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/swarm && \ - go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/swarm/swarm-smoke && \ - go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/swarm/global-store && \ - go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/geth + cd $GOPATH/src/github.com/ethereum && \ + git clone https://github.com/ethersphere/go-ethereum && \ + cd $GOPATH/src/github.com/ethereum/go-ethereum && \ + git checkout ${VERSION} && \ + go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/swarm && \ + go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/swarm/swarm-smoke && \ + go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/swarm/global-store && \ + go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/geth FROM alpine:3.8 as swarm-smoke WORKDIR / COPY --from=builder /go/bin/swarm-smoke / +COPY --from=builder /go/bin/swarm-smoke-pss / ADD run-smoke.sh /run-smoke.sh ENTRYPOINT ["/run-smoke.sh"]