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