Browse Source

go-kit metrics plus prometheus: one metric

pull/1737/head
Anton Kaliaev 7 years ago
parent
commit
5c7093cc9f
No known key found for this signature in database GPG Key ID: 7B6881D965918214
8 changed files with 93 additions and 8 deletions
  1. +51
    -2
      Gopkg.lock
  2. +4
    -0
      Gopkg.toml
  3. +1
    -1
      consensus/common_test.go
  4. +17
    -0
      consensus/metrics.go
  5. +2
    -2
      consensus/replay_file.go
  6. +6
    -1
      consensus/state.go
  7. +1
    -1
      consensus/wal_generator.go
  8. +11
    -1
      node/node.go

+ 51
- 2
Gopkg.lock View File

@ -1,6 +1,12 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
branch = "master"
name = "github.com/beorn7/perks"
packages = ["quantile"]
revision = "3a771d992973f24aa725d07868b467d1ddfceafb"
[[projects]] [[projects]]
branch = "master" branch = "master"
name = "github.com/btcsuite/btcd" name = "github.com/btcsuite/btcd"
@ -36,7 +42,11 @@
packages = [ packages = [
"log", "log",
"log/level", "log/level",
"log/term"
"log/term",
"metrics",
"metrics/discard",
"metrics/internal/lv",
"metrics/prometheus"
] ]
revision = "4dc7be5d2d12881735283bcab7352178e190fc71" revision = "4dc7be5d2d12881735283bcab7352178e190fc71"
version = "v0.6.0" version = "v0.6.0"
@ -131,6 +141,12 @@
revision = "c2353362d570a7bfa228149c62842019201cfb71" revision = "c2353362d570a7bfa228149c62842019201cfb71"
version = "v1.8.0" version = "v1.8.0"
[[projects]]
name = "github.com/matttproud/golang_protobuf_extensions"
packages = ["pbutil"]
revision = "c12348ce28de40eed0136aa2b644d0ee0650e56c"
version = "v1.0.1"
[[projects]] [[projects]]
branch = "master" branch = "master"
name = "github.com/mitchellh/mapstructure" name = "github.com/mitchellh/mapstructure"
@ -155,6 +171,39 @@
revision = "792786c7400a136282c1664665ae0a8db921c6c2" revision = "792786c7400a136282c1664665ae0a8db921c6c2"
version = "v1.0.0" version = "v1.0.0"
[[projects]]
name = "github.com/prometheus/client_golang"
packages = ["prometheus"]
revision = "c5b7fccd204277076155f10851dad72b76a49317"
version = "v0.8.0"
[[projects]]
branch = "master"
name = "github.com/prometheus/client_model"
packages = ["go"]
revision = "99fa1f4be8e564e8a6b613da7fa6f46c9edafc6c"
[[projects]]
branch = "master"
name = "github.com/prometheus/common"
packages = [
"expfmt",
"internal/bitbucket.org/ww/goautoneg",
"model"
]
revision = "7600349dcfe1abd18d72d3a1770870d9800a7801"
[[projects]]
branch = "master"
name = "github.com/prometheus/procfs"
packages = [
".",
"internal/util",
"nfs",
"xfs"
]
revision = "94663424ae5ae9856b40a9f170762b4197024661"
[[projects]] [[projects]]
branch = "master" branch = "master"
name = "github.com/rcrowley/go-metrics" name = "github.com/rcrowley/go-metrics"
@ -374,6 +423,6 @@
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
inputs-digest = "62d0626fa963b25411234da915fb3b8bfc7aefffd76824d27ac1647ca2b5d489"
inputs-digest = "294ac88a5b44228f5ef841b13602d0a8b8fed5fbe9b9b6df77640d636175be16"
solver-name = "gps-cdcl" solver-name = "gps-cdcl"
solver-version = 1 solver-version = 1

+ 4
- 0
Gopkg.toml View File

@ -97,3 +97,7 @@
[prune] [prune]
go-tests = true go-tests = true
unused-packages = true unused-packages = true
[[constraint]]
name = "github.com/prometheus/client_golang"
version = "0.8.0"

+ 1
- 1
consensus/common_test.go View File

@ -267,7 +267,7 @@ func newConsensusStateWithConfigAndBlockStore(thisConfig *cfg.Config, state sm.S
// Make ConsensusState // Make ConsensusState
stateDB := dbm.NewMemDB() stateDB := dbm.NewMemDB()
blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyAppConnCon, mempool, evpool) blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyAppConnCon, mempool, evpool)
cs := NewConsensusState(thisConfig.Consensus, state, blockExec, blockStore, mempool, evpool)
cs := NewConsensusState(thisConfig.Consensus, state, blockExec, blockStore, mempool, evpool, NopMetrics())
cs.SetLogger(log.TestingLogger().With("module", "consensus")) cs.SetLogger(log.TestingLogger().With("module", "consensus"))
cs.SetPrivValidator(pv) cs.SetPrivValidator(pv)


+ 17
- 0
consensus/metrics.go View File

@ -0,0 +1,17 @@
package consensus
import "github.com/go-kit/kit/metrics"
import "github.com/go-kit/kit/metrics/discard"
// Metrics contains metrics exposed by this package.
type Metrics struct {
// height of the chain
Height metrics.Counter
}
// NopMetrics returns no-op Metrics.
func NopMetrics() *Metrics {
return &Metrics{
Height: discard.NewCounter(),
}
}

+ 2
- 2
consensus/replay_file.go View File

@ -126,7 +126,7 @@ func (pb *playback) replayReset(count int, newStepCh chan interface{}) error {
pb.cs.Wait() pb.cs.Wait()
newCS := NewConsensusState(pb.cs.config, pb.genesisState.Copy(), pb.cs.blockExec, newCS := NewConsensusState(pb.cs.config, pb.genesisState.Copy(), pb.cs.blockExec,
pb.cs.blockStore, pb.cs.mempool, pb.cs.evpool)
pb.cs.blockStore, pb.cs.mempool, pb.cs.evpool, pb.cs.metrics)
newCS.SetEventBus(pb.cs.eventBus) newCS.SetEventBus(pb.cs.eventBus)
newCS.startForReplay() newCS.startForReplay()
@ -314,7 +314,7 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo
blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyApp.Consensus(), mempool, evpool) blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyApp.Consensus(), mempool, evpool)
consensusState := NewConsensusState(csConfig, state.Copy(), blockExec, consensusState := NewConsensusState(csConfig, state.Copy(), blockExec,
blockStore, mempool, evpool)
blockStore, mempool, evpool, NopMetrics())
consensusState.SetEventBus(eventBus) consensusState.SetEventBus(eventBus)
return consensusState return consensusState


+ 6
- 1
consensus/state.go View File

@ -115,10 +115,13 @@ type ConsensusState struct {
// synchronous pubsub between consensus state and reactor. // synchronous pubsub between consensus state and reactor.
// state only emits EventNewRoundStep, EventVote and EventProposalHeartbeat // state only emits EventNewRoundStep, EventVote and EventProposalHeartbeat
evsw tmevents.EventSwitch evsw tmevents.EventSwitch
// for reporting metrics
metrics *Metrics
} }
// NewConsensusState returns a new ConsensusState. // NewConsensusState returns a new ConsensusState.
func NewConsensusState(config *cfg.ConsensusConfig, state sm.State, blockExec *sm.BlockExecutor, blockStore sm.BlockStore, mempool sm.Mempool, evpool sm.EvidencePool) *ConsensusState {
func NewConsensusState(config *cfg.ConsensusConfig, state sm.State, blockExec *sm.BlockExecutor, blockStore sm.BlockStore, mempool sm.Mempool, evpool sm.EvidencePool, metrics *Metrics) *ConsensusState {
cs := &ConsensusState{ cs := &ConsensusState{
config: config, config: config,
blockExec: blockExec, blockExec: blockExec,
@ -132,6 +135,7 @@ func NewConsensusState(config *cfg.ConsensusConfig, state sm.State, blockExec *s
wal: nilWAL{}, wal: nilWAL{},
evpool: evpool, evpool: evpool,
evsw: tmevents.NewEventSwitch(), evsw: tmevents.NewEventSwitch(),
metrics: metrics,
} }
// set function defaults (may be overwritten before calling Start) // set function defaults (may be overwritten before calling Start)
cs.decideProposal = cs.defaultDecideProposal cs.decideProposal = cs.defaultDecideProposal
@ -388,6 +392,7 @@ func (cs *ConsensusState) SetProposalAndBlock(proposal *types.Proposal, block *t
func (cs *ConsensusState) updateHeight(height int64) { func (cs *ConsensusState) updateHeight(height int64) {
cs.Height = height cs.Height = height
cs.metrics.Height.Add(float64(height - cs.Height))
} }
func (cs *ConsensusState) updateRoundStep(round int, step cstypes.RoundStepType) { func (cs *ConsensusState) updateRoundStep(round int, step cstypes.RoundStepType) {


+ 1
- 1
consensus/wal_generator.go View File

@ -68,7 +68,7 @@ func WALWithNBlocks(numBlocks int) (data []byte, err error) {
mempool := sm.MockMempool{} mempool := sm.MockMempool{}
evpool := sm.MockEvidencePool{} evpool := sm.MockEvidencePool{}
blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyApp.Consensus(), mempool, evpool) blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyApp.Consensus(), mempool, evpool)
consensusState := NewConsensusState(config.Consensus, state.Copy(), blockExec, blockStore, mempool, evpool)
consensusState := NewConsensusState(config.Consensus, state.Copy(), blockExec, blockStore, mempool, evpool, NopMetrics())
consensusState.SetLogger(logger) consensusState.SetLogger(logger)
consensusState.SetEventBus(eventBus) consensusState.SetEventBus(eventBus)
if privValidator != nil { if privValidator != nil {


+ 11
- 1
node/node.go View File

@ -7,6 +7,9 @@ import (
"net" "net"
"net/http" "net/http"
prometheus "github.com/go-kit/kit/metrics/prometheus"
stdprometheus "github.com/prometheus/client_golang/prometheus"
abci "github.com/tendermint/abci/types" abci "github.com/tendermint/abci/types"
amino "github.com/tendermint/go-amino" amino "github.com/tendermint/go-amino"
crypto "github.com/tendermint/go-crypto" crypto "github.com/tendermint/go-crypto"
@ -241,8 +244,15 @@ func NewNode(config *cfg.Config,
bcReactor.SetLogger(logger.With("module", "blockchain")) bcReactor.SetLogger(logger.With("module", "blockchain"))
// Make ConsensusReactor // Make ConsensusReactor
// TODO: extract to provider
metrics := &cs.Metrics{
Height: prometheus.NewCounter(stdprometheus.NewCounterVec(stdprometheus.CounterOpts{
Name: "height",
}, []string{})),
}
stdprometheus.MustRegister(metrics.Height)
consensusState := cs.NewConsensusState(config.Consensus, state.Copy(), consensusState := cs.NewConsensusState(config.Consensus, state.Copy(),
blockExec, blockStore, mempool, evidencePool)
blockExec, blockStore, mempool, evidencePool, metrics)
consensusState.SetLogger(consensusLogger) consensusState.SetLogger(consensusLogger)
if privValidator != nil { if privValidator != nil {
consensusState.SetPrivValidator(privValidator) consensusState.SetPrivValidator(privValidator)


Loading…
Cancel
Save