You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

241 lines
6.1 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
internal/proxy: add initial set of abci metrics (#7115) This PR adds an initial set of metrics for use ABCI. The initial metrics enable the calculation of timing histograms and call counts for each of the ABCI methods. The metrics are also labeled as either 'sync' or 'async' to determine if the method call was performed using ABCI's `*Async` methods. An example of these metrics is included here for reference: ``` tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0001"} 0 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0004"} 5 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.002"} 12 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.009"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.02"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.1"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.65"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="2"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="6"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="25"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="+Inf"} 13 tendermint_abci_connection_method_timing_sum{chain_id="ci",method="commit",type="sync"} 0.007802058000000001 tendermint_abci_connection_method_timing_count{chain_id="ci",method="commit",type="sync"} 13 ``` These metrics can easily be graphed using prometheus's `histogram_quantile(...)` method to pick out a particular quantile to graph or examine. I chose buckets that were somewhat of an estimate of expected range of times for ABCI operations. They start at .0001 seconds and range to 25 seconds. The hope is that this range captures enough possible times to be useful for us and operators.
3 years ago
internal/proxy: add initial set of abci metrics (#7115) This PR adds an initial set of metrics for use ABCI. The initial metrics enable the calculation of timing histograms and call counts for each of the ABCI methods. The metrics are also labeled as either 'sync' or 'async' to determine if the method call was performed using ABCI's `*Async` methods. An example of these metrics is included here for reference: ``` tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0001"} 0 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0004"} 5 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.002"} 12 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.009"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.02"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.1"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.65"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="2"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="6"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="25"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="+Inf"} 13 tendermint_abci_connection_method_timing_sum{chain_id="ci",method="commit",type="sync"} 0.007802058000000001 tendermint_abci_connection_method_timing_count{chain_id="ci",method="commit",type="sync"} 13 ``` These metrics can easily be graphed using prometheus's `histogram_quantile(...)` method to pick out a particular quantile to graph or examine. I chose buckets that were somewhat of an estimate of expected range of times for ABCI operations. They start at .0001 seconds and range to 25 seconds. The hope is that this range captures enough possible times to be useful for us and operators.
3 years ago
8 years ago
8 years ago
8 years ago
internal/proxy: add initial set of abci metrics (#7115) This PR adds an initial set of metrics for use ABCI. The initial metrics enable the calculation of timing histograms and call counts for each of the ABCI methods. The metrics are also labeled as either 'sync' or 'async' to determine if the method call was performed using ABCI's `*Async` methods. An example of these metrics is included here for reference: ``` tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0001"} 0 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0004"} 5 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.002"} 12 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.009"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.02"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.1"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.65"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="2"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="6"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="25"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="+Inf"} 13 tendermint_abci_connection_method_timing_sum{chain_id="ci",method="commit",type="sync"} 0.007802058000000001 tendermint_abci_connection_method_timing_count{chain_id="ci",method="commit",type="sync"} 13 ``` These metrics can easily be graphed using prometheus's `histogram_quantile(...)` method to pick out a particular quantile to graph or examine. I chose buckets that were somewhat of an estimate of expected range of times for ABCI operations. They start at .0001 seconds and range to 25 seconds. The hope is that this range captures enough possible times to be useful for us and operators.
3 years ago
8 years ago
internal/proxy: add initial set of abci metrics (#7115) This PR adds an initial set of metrics for use ABCI. The initial metrics enable the calculation of timing histograms and call counts for each of the ABCI methods. The metrics are also labeled as either 'sync' or 'async' to determine if the method call was performed using ABCI's `*Async` methods. An example of these metrics is included here for reference: ``` tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0001"} 0 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0004"} 5 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.002"} 12 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.009"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.02"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.1"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.65"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="2"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="6"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="25"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="+Inf"} 13 tendermint_abci_connection_method_timing_sum{chain_id="ci",method="commit",type="sync"} 0.007802058000000001 tendermint_abci_connection_method_timing_count{chain_id="ci",method="commit",type="sync"} 13 ``` These metrics can easily be graphed using prometheus's `histogram_quantile(...)` method to pick out a particular quantile to graph or examine. I chose buckets that were somewhat of an estimate of expected range of times for ABCI operations. They start at .0001 seconds and range to 25 seconds. The hope is that this range captures enough possible times to be useful for us and operators.
3 years ago
internal/proxy: add initial set of abci metrics (#7115) This PR adds an initial set of metrics for use ABCI. The initial metrics enable the calculation of timing histograms and call counts for each of the ABCI methods. The metrics are also labeled as either 'sync' or 'async' to determine if the method call was performed using ABCI's `*Async` methods. An example of these metrics is included here for reference: ``` tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0001"} 0 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0004"} 5 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.002"} 12 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.009"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.02"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.1"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.65"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="2"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="6"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="25"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="+Inf"} 13 tendermint_abci_connection_method_timing_sum{chain_id="ci",method="commit",type="sync"} 0.007802058000000001 tendermint_abci_connection_method_timing_count{chain_id="ci",method="commit",type="sync"} 13 ``` These metrics can easily be graphed using prometheus's `histogram_quantile(...)` method to pick out a particular quantile to graph or examine. I chose buckets that were somewhat of an estimate of expected range of times for ABCI operations. They start at .0001 seconds and range to 25 seconds. The hope is that this range captures enough possible times to be useful for us and operators.
3 years ago
internal/proxy: add initial set of abci metrics (#7115) This PR adds an initial set of metrics for use ABCI. The initial metrics enable the calculation of timing histograms and call counts for each of the ABCI methods. The metrics are also labeled as either 'sync' or 'async' to determine if the method call was performed using ABCI's `*Async` methods. An example of these metrics is included here for reference: ``` tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0001"} 0 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0004"} 5 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.002"} 12 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.009"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.02"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.1"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.65"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="2"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="6"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="25"} 13 tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="+Inf"} 13 tendermint_abci_connection_method_timing_sum{chain_id="ci",method="commit",type="sync"} 0.007802058000000001 tendermint_abci_connection_method_timing_count{chain_id="ci",method="commit",type="sync"} 13 ``` These metrics can easily be graphed using prometheus's `histogram_quantile(...)` method to pick out a particular quantile to graph or examine. I chose buckets that were somewhat of an estimate of expected range of times for ABCI operations. They start at .0001 seconds and range to 25 seconds. The hope is that this range captures enough possible times to be useful for us and operators.
3 years ago
  1. package proxy
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "os"
  7. "syscall"
  8. abciclient "github.com/tendermint/tendermint/abci/client"
  9. "github.com/tendermint/tendermint/libs/log"
  10. "github.com/tendermint/tendermint/libs/service"
  11. )
  12. const (
  13. connConsensus = "consensus"
  14. connMempool = "mempool"
  15. connQuery = "query"
  16. connSnapshot = "snapshot"
  17. )
  18. // AppConns is the Tendermint's interface to the application that consists of
  19. // multiple connections.
  20. type AppConns interface {
  21. service.Service
  22. // Mempool connection
  23. Mempool() AppConnMempool
  24. // Consensus connection
  25. Consensus() AppConnConsensus
  26. // Query connection
  27. Query() AppConnQuery
  28. // Snapshot connection
  29. Snapshot() AppConnSnapshot
  30. }
  31. // NewAppConns calls NewMultiAppConn.
  32. func NewAppConns(clientCreator abciclient.Creator, logger log.Logger, metrics *Metrics) AppConns {
  33. return NewMultiAppConn(clientCreator, logger, metrics)
  34. }
  35. // multiAppConn implements AppConns.
  36. //
  37. // A multiAppConn is made of a few appConns and manages their underlying abci
  38. // clients.
  39. // TODO: on app restart, clients must reboot together
  40. type multiAppConn struct {
  41. service.BaseService
  42. metrics *Metrics
  43. consensusConn AppConnConsensus
  44. mempoolConn AppConnMempool
  45. queryConn AppConnQuery
  46. snapshotConn AppConnSnapshot
  47. consensusConnClient stoppableClient
  48. mempoolConnClient stoppableClient
  49. queryConnClient stoppableClient
  50. snapshotConnClient stoppableClient
  51. clientCreator abciclient.Creator
  52. }
  53. // TODO: this is a totally internal and quasi permanent shim for
  54. // clients. eventually we can have a single client and have some kind
  55. // of reasonable lifecycle witout needing an explicit stop method.
  56. type stoppableClient interface {
  57. abciclient.Client
  58. Stop() error
  59. }
  60. // NewMultiAppConn makes all necessary abci connections to the application.
  61. func NewMultiAppConn(clientCreator abciclient.Creator, logger log.Logger, metrics *Metrics) AppConns {
  62. multiAppConn := &multiAppConn{
  63. metrics: metrics,
  64. clientCreator: clientCreator,
  65. }
  66. multiAppConn.BaseService = *service.NewBaseService(logger, "multiAppConn", multiAppConn)
  67. return multiAppConn
  68. }
  69. func (app *multiAppConn) Mempool() AppConnMempool {
  70. return app.mempoolConn
  71. }
  72. func (app *multiAppConn) Consensus() AppConnConsensus {
  73. return app.consensusConn
  74. }
  75. func (app *multiAppConn) Query() AppConnQuery {
  76. return app.queryConn
  77. }
  78. func (app *multiAppConn) Snapshot() AppConnSnapshot {
  79. return app.snapshotConn
  80. }
  81. func (app *multiAppConn) OnStart(ctx context.Context) error {
  82. c, err := app.abciClientFor(ctx, connQuery)
  83. if err != nil {
  84. return err
  85. }
  86. app.queryConnClient = c.(stoppableClient)
  87. app.queryConn = NewAppConnQuery(c, app.metrics)
  88. c, err = app.abciClientFor(ctx, connSnapshot)
  89. if err != nil {
  90. app.stopAllClients()
  91. return err
  92. }
  93. app.snapshotConnClient = c.(stoppableClient)
  94. app.snapshotConn = NewAppConnSnapshot(c, app.metrics)
  95. c, err = app.abciClientFor(ctx, connMempool)
  96. if err != nil {
  97. app.stopAllClients()
  98. return err
  99. }
  100. app.mempoolConnClient = c.(stoppableClient)
  101. app.mempoolConn = NewAppConnMempool(c, app.metrics)
  102. c, err = app.abciClientFor(ctx, connConsensus)
  103. if err != nil {
  104. app.stopAllClients()
  105. return err
  106. }
  107. app.consensusConnClient = c.(stoppableClient)
  108. app.consensusConn = NewAppConnConsensus(c, app.metrics)
  109. // Kill Tendermint if the ABCI application crashes.
  110. app.startWatchersForClientErrorToKillTendermint(ctx)
  111. return nil
  112. }
  113. func (app *multiAppConn) OnStop() {
  114. app.stopAllClients()
  115. }
  116. func (app *multiAppConn) startWatchersForClientErrorToKillTendermint(ctx context.Context) {
  117. // this function starts a number of threads (per abci client)
  118. // that will SIGTERM's our own PID if any of the ABCI clients
  119. // exit/return early. If the context is canceled then these
  120. // functions will not kill tendermint.
  121. killFn := func(conn string, err error, logger log.Logger) {
  122. logger.Error(
  123. fmt.Sprintf("%s connection terminated. Did the application crash? Please restart tendermint", conn),
  124. "err", err)
  125. if killErr := kill(); killErr != nil {
  126. logger.Error("Failed to kill this process - please do so manually", "err", killErr)
  127. }
  128. }
  129. type op struct {
  130. connClient stoppableClient
  131. name string
  132. }
  133. for _, client := range []op{
  134. {
  135. connClient: app.consensusConnClient,
  136. name: connConsensus,
  137. },
  138. {
  139. connClient: app.mempoolConnClient,
  140. name: connMempool,
  141. },
  142. {
  143. connClient: app.queryConnClient,
  144. name: connQuery,
  145. },
  146. {
  147. connClient: app.snapshotConnClient,
  148. name: connSnapshot,
  149. },
  150. } {
  151. go func(name string, client stoppableClient) {
  152. client.Wait()
  153. if ctx.Err() != nil {
  154. return
  155. }
  156. if err := client.Error(); err != nil {
  157. killFn(name, err, app.Logger)
  158. }
  159. }(client.name, client.connClient)
  160. }
  161. }
  162. func (app *multiAppConn) stopAllClients() {
  163. if app.consensusConnClient != nil {
  164. if err := app.consensusConnClient.Stop(); err != nil {
  165. if !errors.Is(err, service.ErrAlreadyStopped) {
  166. app.Logger.Error("error while stopping consensus client", "error", err)
  167. }
  168. }
  169. }
  170. if app.mempoolConnClient != nil {
  171. if err := app.mempoolConnClient.Stop(); err != nil {
  172. if !errors.Is(err, service.ErrAlreadyStopped) {
  173. app.Logger.Error("error while stopping mempool client", "error", err)
  174. }
  175. }
  176. }
  177. if app.queryConnClient != nil {
  178. if err := app.queryConnClient.Stop(); err != nil {
  179. if !errors.Is(err, service.ErrAlreadyStopped) {
  180. app.Logger.Error("error while stopping query client", "error", err)
  181. }
  182. }
  183. }
  184. if app.snapshotConnClient != nil {
  185. if err := app.snapshotConnClient.Stop(); err != nil {
  186. if !errors.Is(err, service.ErrAlreadyStopped) {
  187. app.Logger.Error("error while stopping snapshot client", "error", err)
  188. }
  189. }
  190. }
  191. }
  192. func (app *multiAppConn) abciClientFor(ctx context.Context, conn string) (abciclient.Client, error) {
  193. c, err := app.clientCreator(app.Logger.With(
  194. "module", "abci-client",
  195. "connection", conn))
  196. if err != nil {
  197. return nil, fmt.Errorf("error creating ABCI client (%s connection): %w", conn, err)
  198. }
  199. if err := c.Start(ctx); err != nil {
  200. return nil, fmt.Errorf("error starting ABCI client (%s connection): %w", conn, err)
  201. }
  202. return c, nil
  203. }
  204. func kill() error {
  205. p, err := os.FindProcess(os.Getpid())
  206. if err != nil {
  207. return err
  208. }
  209. return p.Signal(syscall.SIGTERM)
  210. }