main.go 5.0 KB

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