github.com/letterj/go-ethereum@v1.8.22-0.20190204142846-520024dfd689/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 gethmetrics "github.com/ethereum/go-ethereum/metrics" 26 "github.com/ethereum/go-ethereum/metrics/influxdb" 27 swarmmetrics "github.com/ethereum/go-ethereum/swarm/metrics" 28 "github.com/ethereum/go-ethereum/swarm/tracing" 29 30 "github.com/ethereum/go-ethereum/log" 31 32 cli "gopkg.in/urfave/cli.v1" 33 ) 34 35 var ( 36 gitCommit string // Git SHA1 commit hash of the release (set via linker flags) 37 ) 38 39 var ( 40 endpoints []string 41 includeLocalhost bool 42 cluster string 43 appName string 44 scheme string 45 filesize int 46 syncDelay int 47 from int 48 to int 49 verbosity int 50 timeout int 51 single bool 52 ) 53 54 func main() { 55 56 app := cli.NewApp() 57 app.Name = "smoke-test" 58 app.Usage = "" 59 60 app.Flags = []cli.Flag{ 61 cli.StringFlag{ 62 Name: "cluster-endpoint", 63 Value: "prod", 64 Usage: "cluster to point to (prod or a given namespace)", 65 Destination: &cluster, 66 }, 67 cli.StringFlag{ 68 Name: "app", 69 Value: "swarm", 70 Usage: "application to point to (swarm or swarm-private)", 71 Destination: &appName, 72 }, 73 cli.IntFlag{ 74 Name: "cluster-from", 75 Value: 8501, 76 Usage: "swarm node (from)", 77 Destination: &from, 78 }, 79 cli.IntFlag{ 80 Name: "cluster-to", 81 Value: 8512, 82 Usage: "swarm node (to)", 83 Destination: &to, 84 }, 85 cli.StringFlag{ 86 Name: "cluster-scheme", 87 Value: "http", 88 Usage: "http or https", 89 Destination: &scheme, 90 }, 91 cli.BoolFlag{ 92 Name: "include-localhost", 93 Usage: "whether to include localhost:8500 as an endpoint", 94 Destination: &includeLocalhost, 95 }, 96 cli.IntFlag{ 97 Name: "filesize", 98 Value: 1024, 99 Usage: "file size for generated random file in KB", 100 Destination: &filesize, 101 }, 102 cli.IntFlag{ 103 Name: "sync-delay", 104 Value: 5, 105 Usage: "duration of delay in seconds to wait for content to be synced", 106 Destination: &syncDelay, 107 }, 108 cli.IntFlag{ 109 Name: "verbosity", 110 Value: 1, 111 Usage: "verbosity", 112 Destination: &verbosity, 113 }, 114 cli.IntFlag{ 115 Name: "timeout", 116 Value: 120, 117 Usage: "timeout in seconds after which kill the process", 118 Destination: &timeout, 119 }, 120 cli.BoolFlag{ 121 Name: "single", 122 Usage: "whether to fetch content from a single node or from all nodes", 123 Destination: &single, 124 }, 125 } 126 127 app.Flags = append(app.Flags, []cli.Flag{ 128 utils.MetricsEnabledFlag, 129 swarmmetrics.MetricsInfluxDBEndpointFlag, 130 swarmmetrics.MetricsInfluxDBDatabaseFlag, 131 swarmmetrics.MetricsInfluxDBUsernameFlag, 132 swarmmetrics.MetricsInfluxDBPasswordFlag, 133 swarmmetrics.MetricsInfluxDBTagsFlag, 134 }...) 135 136 app.Flags = append(app.Flags, tracing.Flags...) 137 138 app.Commands = []cli.Command{ 139 { 140 Name: "upload_and_sync", 141 Aliases: []string{"c"}, 142 Usage: "upload and sync", 143 Action: wrapCliCommand("upload-and-sync", true, uploadAndSync), 144 }, 145 { 146 Name: "feed_sync", 147 Aliases: []string{"f"}, 148 Usage: "feed update generate, upload and sync", 149 Action: wrapCliCommand("feed-and-sync", true, feedUploadAndSync), 150 }, 151 { 152 Name: "upload_speed", 153 Aliases: []string{"u"}, 154 Usage: "measure upload speed", 155 Action: wrapCliCommand("upload-speed", true, uploadSpeed), 156 }, 157 { 158 Name: "sliding_window", 159 Aliases: []string{"s"}, 160 Usage: "measure network aggregate capacity", 161 Action: wrapCliCommand("sliding-window", false, slidingWindow), 162 }, 163 } 164 165 sort.Sort(cli.FlagsByName(app.Flags)) 166 sort.Sort(cli.CommandsByName(app.Commands)) 167 168 app.Before = func(ctx *cli.Context) error { 169 tracing.Setup(ctx) 170 return nil 171 } 172 173 app.After = func(ctx *cli.Context) error { 174 return emitMetrics(ctx) 175 } 176 177 err := app.Run(os.Args) 178 if err != nil { 179 log.Error(err.Error()) 180 181 os.Exit(1) 182 } 183 } 184 185 func emitMetrics(ctx *cli.Context) error { 186 if gethmetrics.Enabled { 187 var ( 188 endpoint = ctx.GlobalString(swarmmetrics.MetricsInfluxDBEndpointFlag.Name) 189 database = ctx.GlobalString(swarmmetrics.MetricsInfluxDBDatabaseFlag.Name) 190 username = ctx.GlobalString(swarmmetrics.MetricsInfluxDBUsernameFlag.Name) 191 password = ctx.GlobalString(swarmmetrics.MetricsInfluxDBPasswordFlag.Name) 192 tags = ctx.GlobalString(swarmmetrics.MetricsInfluxDBTagsFlag.Name) 193 ) 194 195 tagsMap := utils.SplitTagsFlag(tags) 196 tagsMap["version"] = gitCommit 197 tagsMap["filesize"] = fmt.Sprintf("%v", filesize) 198 199 return influxdb.InfluxDBWithTagsOnce(gethmetrics.DefaultRegistry, endpoint, database, username, password, "swarm-smoke.", tagsMap) 200 } 201 202 return nil 203 }