main.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. package main
  17. import (
  18. "fmt"
  19. "os"
  20. "sort"
  21. "github.com/ethereum/go-ethereum/cmd/utils"
  22. gethmetrics "github.com/ethereum/go-ethereum/metrics"
  23. "github.com/ethereum/go-ethereum/metrics/influxdb"
  24. swarmmetrics "github.com/ethereum/go-ethereum/swarm/metrics"
  25. "github.com/ethereum/go-ethereum/swarm/tracing"
  26. "github.com/ethereum/go-ethereum/log"
  27. cli "gopkg.in/urfave/cli.v1"
  28. )
  29. var (
  30. gitCommit string // Git SHA1 commit hash of the release (set via linker flags)
  31. )
  32. var (
  33. allhosts string
  34. hosts []string
  35. filesize int
  36. syncDelay bool
  37. inputSeed int
  38. httpPort int
  39. wsPort int
  40. verbosity int
  41. timeout int
  42. single bool
  43. onlyUpload bool
  44. )
  45. func main() {
  46. app := cli.NewApp()
  47. app.Name = "smoke-test"
  48. app.Usage = ""
  49. app.Flags = []cli.Flag{
  50. cli.StringFlag{
  51. Name: "hosts",
  52. Value: "",
  53. Usage: "comma-separated list of swarm hosts",
  54. Destination: &allhosts,
  55. },
  56. cli.IntFlag{
  57. Name: "http-port",
  58. Value: 80,
  59. Usage: "http port",
  60. Destination: &httpPort,
  61. },
  62. cli.IntFlag{
  63. Name: "ws-port",
  64. Value: 8546,
  65. Usage: "ws port",
  66. Destination: &wsPort,
  67. },
  68. cli.IntFlag{
  69. Name: "seed",
  70. Value: 0,
  71. Usage: "input seed in case we need deterministic upload",
  72. Destination: &inputSeed,
  73. },
  74. cli.IntFlag{
  75. Name: "filesize",
  76. Value: 1024,
  77. Usage: "file size for generated random file in KB",
  78. Destination: &filesize,
  79. },
  80. cli.BoolFlag{
  81. Name: "sync-delay",
  82. Usage: "wait for content to be synced",
  83. Destination: &syncDelay,
  84. },
  85. cli.IntFlag{
  86. Name: "verbosity",
  87. Value: 1,
  88. Usage: "verbosity",
  89. Destination: &verbosity,
  90. },
  91. cli.IntFlag{
  92. Name: "timeout",
  93. Value: 180,
  94. Usage: "timeout in seconds after which kill the process",
  95. Destination: &timeout,
  96. },
  97. cli.BoolFlag{
  98. Name: "single",
  99. Usage: "whether to fetch content from a single node or from all nodes",
  100. Destination: &single,
  101. },
  102. cli.BoolFlag{
  103. Name: "only-upload",
  104. Usage: "whether to only upload content to a single node without fetching",
  105. Destination: &onlyUpload,
  106. },
  107. }
  108. app.Flags = append(app.Flags, []cli.Flag{
  109. utils.MetricsEnabledFlag,
  110. swarmmetrics.MetricsInfluxDBEndpointFlag,
  111. swarmmetrics.MetricsInfluxDBDatabaseFlag,
  112. swarmmetrics.MetricsInfluxDBUsernameFlag,
  113. swarmmetrics.MetricsInfluxDBPasswordFlag,
  114. swarmmetrics.MetricsInfluxDBTagsFlag,
  115. }...)
  116. app.Flags = append(app.Flags, tracing.Flags...)
  117. app.Commands = []cli.Command{
  118. {
  119. Name: "upload_and_sync",
  120. Aliases: []string{"c"},
  121. Usage: "upload and sync",
  122. Action: wrapCliCommand("upload-and-sync", uploadAndSyncCmd),
  123. },
  124. {
  125. Name: "feed_sync",
  126. Aliases: []string{"f"},
  127. Usage: "feed update generate, upload and sync",
  128. Action: wrapCliCommand("feed-and-sync", feedUploadAndSyncCmd),
  129. },
  130. {
  131. Name: "upload_speed",
  132. Aliases: []string{"u"},
  133. Usage: "measure upload speed",
  134. Action: wrapCliCommand("upload-speed", uploadSpeedCmd),
  135. },
  136. {
  137. Name: "sliding_window",
  138. Aliases: []string{"s"},
  139. Usage: "measure network aggregate capacity",
  140. Action: wrapCliCommand("sliding-window", slidingWindowCmd),
  141. },
  142. }
  143. sort.Sort(cli.FlagsByName(app.Flags))
  144. sort.Sort(cli.CommandsByName(app.Commands))
  145. app.Before = func(ctx *cli.Context) error {
  146. tracing.Setup(ctx)
  147. return nil
  148. }
  149. app.After = func(ctx *cli.Context) error {
  150. return emitMetrics(ctx)
  151. }
  152. err := app.Run(os.Args)
  153. if err != nil {
  154. log.Error(err.Error())
  155. os.Exit(1)
  156. }
  157. }
  158. func emitMetrics(ctx *cli.Context) error {
  159. if gethmetrics.Enabled {
  160. var (
  161. endpoint = ctx.GlobalString(swarmmetrics.MetricsInfluxDBEndpointFlag.Name)
  162. database = ctx.GlobalString(swarmmetrics.MetricsInfluxDBDatabaseFlag.Name)
  163. username = ctx.GlobalString(swarmmetrics.MetricsInfluxDBUsernameFlag.Name)
  164. password = ctx.GlobalString(swarmmetrics.MetricsInfluxDBPasswordFlag.Name)
  165. tags = ctx.GlobalString(swarmmetrics.MetricsInfluxDBTagsFlag.Name)
  166. )
  167. tagsMap := utils.SplitTagsFlag(tags)
  168. tagsMap["version"] = gitCommit
  169. tagsMap["filesize"] = fmt.Sprintf("%v", filesize)
  170. return influxdb.InfluxDBWithTagsOnce(gethmetrics.DefaultRegistry, endpoint, database, username, password, "swarm-smoke.", tagsMap)
  171. }
  172. return nil
  173. }