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.

125 lines
3.9 KiB

blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
  1. package v2
  2. import (
  3. "github.com/go-kit/kit/metrics"
  4. "github.com/go-kit/kit/metrics/discard"
  5. "github.com/go-kit/kit/metrics/prometheus"
  6. stdprometheus "github.com/prometheus/client_golang/prometheus"
  7. )
  8. const (
  9. // MetricsSubsystem is a subsystem shared by all metrics exposed by this
  10. // package.
  11. MetricsSubsystem = "blockchain"
  12. )
  13. // Metrics contains metrics exposed by this package.
  14. type Metrics struct {
  15. // events_in
  16. EventsIn metrics.Counter
  17. // events_in
  18. EventsHandled metrics.Counter
  19. // events_out
  20. EventsOut metrics.Counter
  21. // errors_in
  22. ErrorsIn metrics.Counter
  23. // errors_handled
  24. ErrorsHandled metrics.Counter
  25. // errors_out
  26. ErrorsOut metrics.Counter
  27. // events_shed
  28. EventsShed metrics.Counter
  29. // events_sent
  30. EventsSent metrics.Counter
  31. // errors_sent
  32. ErrorsSent metrics.Counter
  33. // errors_shed
  34. ErrorsShed metrics.Counter
  35. }
  36. // PrometheusMetrics returns metrics for in and out events, errors, etc. handled by routines.
  37. // Can we burn in the routine name here?
  38. func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
  39. labels := []string{}
  40. for i := 0; i < len(labelsAndValues); i += 2 {
  41. labels = append(labels, labelsAndValues[i])
  42. }
  43. return &Metrics{
  44. EventsIn: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  45. Namespace: namespace,
  46. Subsystem: MetricsSubsystem,
  47. Name: "events_in",
  48. Help: "Events read from the channel.",
  49. }, labels).With(labelsAndValues...),
  50. EventsHandled: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  51. Namespace: namespace,
  52. Subsystem: MetricsSubsystem,
  53. Name: "events_handled",
  54. Help: "Events handled",
  55. }, labels).With(labelsAndValues...),
  56. EventsOut: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  57. Namespace: namespace,
  58. Subsystem: MetricsSubsystem,
  59. Name: "events_out",
  60. Help: "Events output from routine.",
  61. }, labels).With(labelsAndValues...),
  62. ErrorsIn: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  63. Namespace: namespace,
  64. Subsystem: MetricsSubsystem,
  65. Name: "errors_in",
  66. Help: "Errors read from the channel.",
  67. }, labels).With(labelsAndValues...),
  68. ErrorsHandled: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  69. Namespace: namespace,
  70. Subsystem: MetricsSubsystem,
  71. Name: "errors_handled",
  72. Help: "Errors handled.",
  73. }, labels).With(labelsAndValues...),
  74. ErrorsOut: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  75. Namespace: namespace,
  76. Subsystem: MetricsSubsystem,
  77. Name: "errors_out",
  78. Help: "Errors output from routine.",
  79. }, labels).With(labelsAndValues...),
  80. ErrorsSent: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  81. Namespace: namespace,
  82. Subsystem: MetricsSubsystem,
  83. Name: "errors_sent",
  84. Help: "Errors sent to routine.",
  85. }, labels).With(labelsAndValues...),
  86. ErrorsShed: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  87. Namespace: namespace,
  88. Subsystem: MetricsSubsystem,
  89. Name: "errors_shed",
  90. Help: "Errors dropped from sending.",
  91. }, labels).With(labelsAndValues...),
  92. EventsSent: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  93. Namespace: namespace,
  94. Subsystem: MetricsSubsystem,
  95. Name: "events_sent",
  96. Help: "Events sent to routine.",
  97. }, labels).With(labelsAndValues...),
  98. EventsShed: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  99. Namespace: namespace,
  100. Subsystem: MetricsSubsystem,
  101. Name: "events_shed",
  102. Help: "Events dropped from sending.",
  103. }, labels).With(labelsAndValues...),
  104. }
  105. }
  106. // NopMetrics returns no-op Metrics.
  107. func NopMetrics() *Metrics {
  108. return &Metrics{
  109. EventsIn: discard.NewCounter(),
  110. EventsHandled: discard.NewCounter(),
  111. EventsOut: discard.NewCounter(),
  112. ErrorsIn: discard.NewCounter(),
  113. ErrorsHandled: discard.NewCounter(),
  114. ErrorsOut: discard.NewCounter(),
  115. EventsShed: discard.NewCounter(),
  116. EventsSent: discard.NewCounter(),
  117. ErrorsSent: discard.NewCounter(),
  118. ErrorsShed: discard.NewCounter(),
  119. }
  120. }