Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

cmd/swarm/swarm-smoke: timeout flag #1041

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
0e53c59
cmd/swarm/swarm-smoke: timeout flag
nonsense Dec 3, 2018
53905cb
added influxdb flags
acud Dec 4, 2018
ad3aef7
correct metrics flags and add metrics init on smoke run
acud Dec 4, 2018
ea987e4
add metrics to upload and sync test
acud Dec 4, 2018
84a5fcf
add feed smoke metrics
acud Dec 4, 2018
7058760
cmd/swarm/swarm-smoke: fix metrics collection
nonsense Dec 4, 2018
0313009
cmd/swarm: use correct import
nonsense Dec 4, 2018
c05de65
add git commit
nonsense Dec 4, 2018
acb3149
cmd/swarm: fix wait for reporter
nonsense Dec 4, 2018
d6ecdfe
measure upload time
nonsense Dec 4, 2018
99a1c30
emit metrics only once
nonsense Dec 4, 2018
cb72c57
address PR comments
acud Dec 5, 2018
1569d4f
return nil on no error
acud Dec 5, 2018
0edb2bb
fix linter errors
acud Dec 5, 2018
eac3fdb
cmd/swarm/swarm-smoke: timeout flag
nonsense Dec 3, 2018
e176fe5
added influxdb flags
acud Dec 4, 2018
8be02fa
correct metrics flags and add metrics init on smoke run
acud Dec 4, 2018
238195a
add metrics to upload and sync test
acud Dec 4, 2018
5f93226
add feed smoke metrics
acud Dec 4, 2018
f9c231c
cmd/swarm/swarm-smoke: fix metrics collection
nonsense Dec 4, 2018
fe3da49
cmd/swarm: use correct import
nonsense Dec 4, 2018
f7b0db6
add git commit
nonsense Dec 4, 2018
f6cd823
cmd/swarm: fix wait for reporter
nonsense Dec 4, 2018
77cc885
measure upload time
nonsense Dec 4, 2018
891f92b
emit metrics only once
nonsense Dec 4, 2018
24b6b95
address PR comments
acud Dec 5, 2018
a2dfa31
return nil on no error
acud Dec 5, 2018
de8a8af
fix linter errors
acud Dec 5, 2018
972e699
cmd/swarm-smoke: inline metrics
nonsense Dec 5, 2018
72a9953
swarm/storage: measure lazy chunk reader chunk get time
nonsense Dec 5, 2018
159d9af
swarm/api: log and measure the same value for request time
nonsense Dec 5, 2018
4f589df
added loglines to http get requests
acud Dec 6, 2018
008ecab
Merge branch 'swarm-smoke-timeout' of github.com:ethersphere/go-ether…
acud Dec 6, 2018
637444c
fix goimports
acud Dec 6, 2018
36d7c2f
added resetting counters
acud Dec 6, 2018
ac8b6d5
added opentracing span injection and extraction over the wire for htt…
acud Dec 6, 2018
c38d250
cleanup and address PR comments
acud Dec 6, 2018
73fc234
add sync-delay and single configurations to swarm smoke tests
nonsense Dec 6, 2018
964ce76
add missing rand seed
nonsense Dec 6, 2018
4dbb41b
replaced upload from swarm binary by upload from swarm client
acud Dec 7, 2018
b38fd0c
moved http client tracer to api/client. added tracing on uploads
acud Dec 7, 2018
a43801c
cmd/swarm/swarm-smoke: metrics for each run (#1049)
holisticode Dec 7, 2018
aef8672
swarm/api/client: address pr comments
acud Dec 10, 2018
07b1092
swarm/api/client: address pr comments
acud Dec 10, 2018
7336446
swarm/api/http: remove opentracing
nonsense Dec 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions cmd/swarm/swarm-smoke/feed_upload_and_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,29 @@ const (
feedRandomDataLength = 8
)

// TODO: retrieve with manifest + extract repeating code
func cliFeedUploadAndSync(c *cli.Context) error {

feedUploadAndSyncCount.Inc(1)
log.Root().SetHandler(log.CallerFileHandler(log.LvlFilterHandler(log.Lvl(verbosity), log.StreamHandler(colorable.NewColorableStderr(), log.TerminalFormat(true)))))

errc := make(chan error)
go func() {
errc <- feedUploadAndSync(c)
}()

select {
case err := <-errc:
if err != nil {
feedUploadAndSyncFailCount.Inc(1)
}
return err
case <-time.After(time.Duration(timeout) * time.Second):
feedUploadAndSyncTimeout.Inc(1)
return fmt.Errorf("timeout after %v sec", timeout)
}
}

// TODO: retrieve with manifest + extract repeating code
func feedUploadAndSync(c *cli.Context) error {
defer func(now time.Time) { log.Info("total time", "time", time.Since(now), "size (kb)", filesize) }(time.Now())

generateEndpoints(scheme, cluster, appName, from, to)
Expand Down
57 changes: 57 additions & 0 deletions cmd/swarm/swarm-smoke/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,24 @@
package main

import (
"fmt"
"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/log"

cli "gopkg.in/urfave/cli.v1"
)

var (
gitCommit string // Git SHA1 commit hash of the release (set via linker flags)
)

var (
endpoints []string
includeLocalhost bool
Expand All @@ -35,6 +45,12 @@ var (
from int
to int
verbosity int
timeout int
)
var (
feedUploadAndSyncCount = gethmetrics.NewRegisteredCounter("feed-and-sync", nil)
feedUploadAndSyncFailCount = gethmetrics.NewRegisteredCounter("feed-and-sync.fail", nil)
feedUploadAndSyncTimeout = gethmetrics.NewRegisteredCounter("feed-and-sync.timeout", nil)
)

func main() {
Expand Down Expand Up @@ -91,8 +107,23 @@ func main() {
Usage: "verbosity",
Destination: &verbosity,
},
cli.IntFlag{
Name: "timeout",
Value: 120,
Usage: "timeout in seconds after which kill the process",
Destination: &timeout,
},
}

app.Flags = append(app.Flags, []cli.Flag{
utils.MetricsEnabledFlag,
swarmmetrics.MetricsInfluxDBEndpointFlag,
swarmmetrics.MetricsInfluxDBDatabaseFlag,
swarmmetrics.MetricsInfluxDBUsernameFlag,
swarmmetrics.MetricsInfluxDBPasswordFlag,
swarmmetrics.MetricsInfluxDBHostTagFlag,
}...)

app.Commands = []cli.Command{
{
Name: "upload_and_sync",
Expand All @@ -110,10 +141,36 @@ 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
}

err := app.Run(os.Args)
if err != nil {
log.Error(err.Error())

os.Exit(1)
}
}

func emitMetrics(ctx *cli.Context) {
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)
hosttag = ctx.GlobalString(swarmmetrics.MetricsInfluxDBHostTagFlag.Name)
)

influxdb.InfluxDBWithTagsOnce(gethmetrics.DefaultRegistry, endpoint, database, username, password, "swarm-smoke.", map[string]string{
"host": hosttag,
"version": gitCommit,
"filesize": fmt.Sprintf("%v", filesize),
})
}
}
34 changes: 31 additions & 3 deletions cmd/swarm/swarm-smoke/upload_and_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ import (
"time"

"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/pborman/uuid"

cli "gopkg.in/urfave/cli.v1"
)

func generateEndpoints(scheme string, cluster string, app string, from int, to int) {
if cluster == "prod" {
for port := from; port <= to; port++ {
for port := from; port < to; port++ {
endpoints = append(endpoints, fmt.Sprintf("%s://%v.swarm-gateways.net", scheme, port))
}
} else {
for port := from; port <= to; port++ {
for port := from; port < to; port++ {
endpoints = append(endpoints, fmt.Sprintf("%s://%s-%v-%s.stg.swarm-gateways.net", scheme, app, port, cluster))
}
}
Expand All @@ -58,7 +59,32 @@ func cliUploadAndSync(c *cli.Context) error {
log.PrintOrigins(true)
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(verbosity), log.StreamHandler(os.Stdout, log.TerminalFormat(true))))

defer func(now time.Time) { log.Info("total time", "time", time.Since(now), "kb", filesize) }(time.Now())
metrics.GetOrRegisterCounter("upload-and-sync", nil).Inc(1)

errc := make(chan error)
go func() {
errc <- uploadAndSync(c)
}()

select {
case err := <-errc:
if err != nil {
metrics.GetOrRegisterCounter("upload-and-sync.fail", nil).Inc(1)
}
return err
case <-time.After(time.Duration(timeout) * time.Second):
metrics.GetOrRegisterCounter("upload-and-sync.timeout", nil).Inc(1)
return fmt.Errorf("timeout after %v sec", timeout)
}
}

func uploadAndSync(c *cli.Context) error {
defer func(now time.Time) {
totalTime := time.Since(now)

log.Info("total time", "time", totalTime, "kb", filesize)
metrics.GetOrRegisterCounter("upload-and-sync.total-time", nil).Inc(int64(totalTime))
}(time.Now())

generateEndpoints(scheme, cluster, appName, from, to)

Expand All @@ -67,11 +93,13 @@ func cliUploadAndSync(c *cli.Context) error {
f, cleanup := generateRandomFile(filesize * 1000)
defer cleanup()

t1 := time.Now()
hash, err := upload(f, endpoints[0])
if err != nil {
log.Error(err.Error())
return err
}
metrics.GetOrRegisterCounter("upload-and-sync.upload-time", nil).Inc(int64(time.Since(t1)))

fhash, err := digest(f)
if err != nil {
Expand Down
28 changes: 28 additions & 0 deletions metrics/influxdb/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,34 @@ func InfluxDBWithTags(r metrics.Registry, d time.Duration, url, database, userna
rep.run()
}

// 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) {
u, err := uurl.Parse(url)
if err != nil {
log.Warn("Unable to parse InfluxDB", "url", url, "err", err)
return
}

rep := &reporter{
reg: r,
url: *u,
database: database,
username: username,
password: password,
namespace: namespace,
tags: tags,
cache: make(map[string]int64),
}
if err := rep.makeClient(); err != nil {
log.Warn("Unable to make InfluxDB client", "err", err)
return
}

if err := rep.send(); err != nil {
log.Warn("Unable to send to InfluxDB", "err", err)
}
}

func (r *reporter) makeClient() (err error) {
r.client, err = client.NewClient(client.Config{
URL: r.url,
Expand Down
32 changes: 18 additions & 14 deletions swarm/metrics/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@ import (
)

var (
metricsEnableInfluxDBExportFlag = cli.BoolFlag{
MetricsEnableInfluxDBExportFlag = cli.BoolFlag{
Name: "metrics.influxdb.export",
Usage: "Enable metrics export/push to an external InfluxDB database",
}
metricsInfluxDBEndpointFlag = cli.StringFlag{
MetricsInfluxDBEndpointFlag = cli.StringFlag{
Name: "metrics.influxdb.endpoint",
Usage: "Metrics InfluxDB endpoint",
Value: "http://127.0.0.1:8086",
}
metricsInfluxDBDatabaseFlag = cli.StringFlag{
MetricsInfluxDBDatabaseFlag = cli.StringFlag{
Name: "metrics.influxdb.database",
Usage: "Metrics InfluxDB database",
Value: "metrics",
}
metricsInfluxDBUsernameFlag = cli.StringFlag{
MetricsInfluxDBUsernameFlag = cli.StringFlag{
Name: "metrics.influxdb.username",
Usage: "Metrics InfluxDB username",
Value: "",
}
metricsInfluxDBPasswordFlag = cli.StringFlag{
MetricsInfluxDBPasswordFlag = cli.StringFlag{
Name: "metrics.influxdb.password",
Usage: "Metrics InfluxDB password",
Value: "",
Expand All @@ -55,7 +55,7 @@ var (
// It is used so that we can group all nodes and average a measurement across all of them, but also so
// that we can select a specific node and inspect its measurements.
// https://docs.influxdata.com/influxdb/v1.4/concepts/key_concepts/#tag-key
metricsInfluxDBHostTagFlag = cli.StringFlag{
MetricsInfluxDBHostTagFlag = cli.StringFlag{
Name: "metrics.influxdb.host.tag",
Usage: "Metrics InfluxDB `host` tag attached to all measurements",
Value: "localhost",
Expand All @@ -65,20 +65,24 @@ var (
// Flags holds all command-line flags required for metrics collection.
var Flags = []cli.Flag{
utils.MetricsEnabledFlag,
metricsEnableInfluxDBExportFlag,
metricsInfluxDBEndpointFlag, metricsInfluxDBDatabaseFlag, metricsInfluxDBUsernameFlag, metricsInfluxDBPasswordFlag, metricsInfluxDBHostTagFlag,
MetricsEnableInfluxDBExportFlag,
MetricsInfluxDBEndpointFlag,
MetricsInfluxDBDatabaseFlag,
MetricsInfluxDBUsernameFlag,
MetricsInfluxDBPasswordFlag,
MetricsInfluxDBHostTagFlag,
}

func Setup(ctx *cli.Context) {
if gethmetrics.Enabled {
log.Info("Enabling swarm metrics collection")
var (
enableExport = ctx.GlobalBool(metricsEnableInfluxDBExportFlag.Name)
endpoint = ctx.GlobalString(metricsInfluxDBEndpointFlag.Name)
database = ctx.GlobalString(metricsInfluxDBDatabaseFlag.Name)
username = ctx.GlobalString(metricsInfluxDBUsernameFlag.Name)
password = ctx.GlobalString(metricsInfluxDBPasswordFlag.Name)
hosttag = ctx.GlobalString(metricsInfluxDBHostTagFlag.Name)
enableExport = ctx.GlobalBool(MetricsEnableInfluxDBExportFlag.Name)
endpoint = ctx.GlobalString(MetricsInfluxDBEndpointFlag.Name)
database = ctx.GlobalString(MetricsInfluxDBDatabaseFlag.Name)
username = ctx.GlobalString(MetricsInfluxDBUsernameFlag.Name)
password = ctx.GlobalString(MetricsInfluxDBPasswordFlag.Name)
hosttag = ctx.GlobalString(MetricsInfluxDBHostTagFlag.Name)
)

// Start system runtime metrics collection
Expand Down