github.com/Blockdaemon/celo-blockchain@v0.0.0-20200129231733-e667f6b08419/cmd/swarm/swarm-smoke/main.go (about) 1 // Copyright 2018 The go-ethereum Authors 2 // This file is part of go-ethereum. 3 // 4 // go-ethereum is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // go-ethereum is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. 16 17 package main 18 19 import ( 20 "fmt" 21 "os" 22 "sort" 23 24 "github.com/ethereum/go-ethereum/cmd/utils" 25 "github.com/ethereum/go-ethereum/log" 26 gethmetrics "github.com/ethereum/go-ethereum/metrics" 27 "github.com/ethereum/go-ethereum/metrics/influxdb" 28 swarmmetrics "github.com/ethereum/go-ethereum/swarm/metrics" 29 "github.com/ethereum/go-ethereum/swarm/tracing" 30 cli "gopkg.in/urfave/cli.v1" 31 ) 32 33 var ( 34 gitCommit string // Git SHA1 commit hash of the release (set via linker flags) 35 ) 36 37 var ( 38 allhosts string 39 hosts []string 40 filesize int 41 syncDelay int 42 httpPort int 43 wsPort int 44 verbosity int 45 timeout int 46 single bool 47 trackTimeout int 48 ) 49 50 func main() { 51 52 app := cli.NewApp() 53 app.Name = "smoke-test" 54 app.Usage = "" 55 56 app.Flags = []cli.Flag{ 57 cli.StringFlag{ 58 Name: "hosts", 59 Value: "", 60 Usage: "comma-separated list of swarm hosts", 61 Destination: &allhosts, 62 }, 63 cli.IntFlag{ 64 Name: "http-port", 65 Value: 80, 66 Usage: "http port", 67 Destination: &httpPort, 68 }, 69 cli.IntFlag{ 70 Name: "ws-port", 71 Value: 8546, 72 Usage: "ws port", 73 Destination: &wsPort, 74 }, 75 cli.IntFlag{ 76 Name: "filesize", 77 Value: 1024, 78 Usage: "file size for generated random file in KB", 79 Destination: &filesize, 80 }, 81 cli.IntFlag{ 82 Name: "sync-delay", 83 Value: 5, 84 Usage: "duration of delay in seconds to wait for content to be synced", 85 Destination: &syncDelay, 86 }, 87 cli.IntFlag{ 88 Name: "verbosity", 89 Value: 1, 90 Usage: "verbosity", 91 Destination: &verbosity, 92 }, 93 cli.IntFlag{ 94 Name: "timeout", 95 Value: 120, 96 Usage: "timeout in seconds after which kill the process", 97 Destination: &timeout, 98 }, 99 cli.BoolFlag{ 100 Name: "single", 101 Usage: "whether to fetch content from a single node or from all nodes", 102 Destination: &single, 103 }, 104 cli.IntFlag{ 105 Name: "track-timeout", 106 Value: 5, 107 Usage: "timeout in seconds to wait for GetAllReferences to return", 108 Destination: &trackTimeout, 109 }, 110 } 111 112 app.Flags = append(app.Flags, []cli.Flag{ 113 utils.MetricsEnabledFlag, 114 swarmmetrics.MetricsInfluxDBEndpointFlag, 115 swarmmetrics.MetricsInfluxDBDatabaseFlag, 116 swarmmetrics.MetricsInfluxDBUsernameFlag, 117 swarmmetrics.MetricsInfluxDBPasswordFlag, 118 swarmmetrics.MetricsInfluxDBTagsFlag, 119 }...) 120 121 app.Flags = append(app.Flags, tracing.Flags...) 122 123 app.Commands = []cli.Command{ 124 { 125 Name: "upload_and_sync", 126 Aliases: []string{"c"}, 127 Usage: "upload and sync", 128 Action: wrapCliCommand("upload-and-sync", uploadAndSyncCmd), 129 }, 130 { 131 Name: "feed_sync", 132 Aliases: []string{"f"}, 133 Usage: "feed update generate, upload and sync", 134 Action: wrapCliCommand("feed-and-sync", feedUploadAndSyncCmd), 135 }, 136 { 137 Name: "upload_speed", 138 Aliases: []string{"u"}, 139 Usage: "measure upload speed", 140 Action: wrapCliCommand("upload-speed", uploadSpeedCmd), 141 }, 142 { 143 Name: "sliding_window", 144 Aliases: []string{"s"}, 145 Usage: "measure network aggregate capacity", 146 Action: wrapCliCommand("sliding-window", slidingWindowCmd), 147 }, 148 } 149 150 sort.Sort(cli.FlagsByName(app.Flags)) 151 sort.Sort(cli.CommandsByName(app.Commands)) 152 153 app.Before = func(ctx *cli.Context) error { 154 tracing.Setup(ctx) 155 return nil 156 } 157 158 app.After = func(ctx *cli.Context) error { 159 return emitMetrics(ctx) 160 } 161 162 err := app.Run(os.Args) 163 if err != nil { 164 log.Error(err.Error()) 165 166 os.Exit(1) 167 } 168 } 169 170 func emitMetrics(ctx *cli.Context) error { 171 if gethmetrics.Enabled { 172 var ( 173 endpoint = ctx.GlobalString(swarmmetrics.MetricsInfluxDBEndpointFlag.Name) 174 database = ctx.GlobalString(swarmmetrics.MetricsInfluxDBDatabaseFlag.Name) 175 username = ctx.GlobalString(swarmmetrics.MetricsInfluxDBUsernameFlag.Name) 176 password = ctx.GlobalString(swarmmetrics.MetricsInfluxDBPasswordFlag.Name) 177 tags = ctx.GlobalString(swarmmetrics.MetricsInfluxDBTagsFlag.Name) 178 ) 179 180 tagsMap := utils.SplitTagsFlag(tags) 181 tagsMap["version"] = gitCommit 182 tagsMap["filesize"] = fmt.Sprintf("%v", filesize) 183 184 return influxdb.InfluxDBWithTagsOnce(gethmetrics.DefaultRegistry, endpoint, database, username, password, "swarm-smoke.", tagsMap) 185 } 186 187 return nil 188 }