cmd/swarm/swarm-smoke-pss: extract pss smoke test to different binary

This commit is contained in:
Rafael Matias 2019-03-25 18:54:35 +01:00
parent 85721d6e7d
commit 86f5697fca
No known key found for this signature in database
GPG key ID: 1BC39532FB4A2DBD
5 changed files with 241 additions and 34 deletions

View file

@ -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 <http://www.gnu.org/licenses/>.
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
}

View file

@ -123,8 +123,9 @@ func pssSetup() *pssSession {
// set up the necessary info for each pss node // set up the necessary info for each pss node
for i, host := range hosts { for i, host := range hosts {
httpHost := fmt.Sprintf("ws://%s:%d", host, 8546) wsHost := wsEndpoint(host)
rpcClient, err := rpc.Dial(httpHost)
rpcClient, err := rpc.Dial(wsHost)
if err != nil { if err != nil {
log.Error("Error dialing host", "err", err) log.Error("Error dialing host", "err", err)
continue continue

View file

@ -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 <http://www.gnu.org/licenses/>.
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)
}
}

View file

@ -37,18 +37,17 @@ var (
) )
var ( var (
allhosts string allhosts string
hosts []string hosts []string
filesize int filesize int
inputSeed int inputSeed int
syncDelay int syncDelay int
httpPort int httpPort int
wsPort int wsPort int
verbosity int verbosity int
timeout int timeout int
single bool single bool
trackTimeout int trackTimeout int
pssMessageCount int
) )
func main() { func main() {
@ -117,12 +116,6 @@ func main() {
Usage: "timeout in seconds to wait for GetAllReferences to return", Usage: "timeout in seconds to wait for GetAllReferences to return",
Destination: &trackTimeout, 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{ app.Flags = append(app.Flags, []cli.Flag{
@ -161,12 +154,6 @@ func main() {
Usage: "measure network aggregate capacity", Usage: "measure network aggregate capacity",
Action: wrapCliCommand("sliding-window", slidingWindowCmd), 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)) sort.Sort(cli.FlagsByName(app.Flags))

View file

@ -4,19 +4,20 @@ ARG VERSION
RUN apk add --update git gcc g++ linux-headers RUN apk add --update git gcc g++ linux-headers
RUN mkdir -p $GOPATH/src/github.com/ethereum && \ RUN mkdir -p $GOPATH/src/github.com/ethereum && \
cd $GOPATH/src/github.com/ethereum && \ cd $GOPATH/src/github.com/ethereum && \
git clone https://github.com/ethersphere/go-ethereum && \ git clone https://github.com/ethersphere/go-ethereum && \
cd $GOPATH/src/github.com/ethereum/go-ethereum && \ cd $GOPATH/src/github.com/ethereum/go-ethereum && \
git checkout ${VERSION} && \ git checkout ${VERSION} && \
go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/swarm && \ 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/swarm-smoke && \
go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/swarm/global-store && \ go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/swarm/global-store && \
go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/geth go install -ldflags "-X main.gitCommit=${VERSION}" ./cmd/geth
FROM alpine:3.8 as swarm-smoke FROM alpine:3.8 as swarm-smoke
WORKDIR / WORKDIR /
COPY --from=builder /go/bin/swarm-smoke / COPY --from=builder /go/bin/swarm-smoke /
COPY --from=builder /go/bin/swarm-smoke-pss /
ADD run-smoke.sh /run-smoke.sh ADD run-smoke.sh /run-smoke.sh
ENTRYPOINT ["/run-smoke.sh"] ENTRYPOINT ["/run-smoke.sh"]