diff --git a/Gopkg.lock b/Gopkg.lock index 8019acb52..9d1031e98 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1,6 +1,12 @@ # 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]] branch = "master" name = "github.com/btcsuite/btcd" @@ -36,7 +42,11 @@ packages = [ "log", "log/level", - "log/term" + "log/term", + "metrics", + "metrics/discard", + "metrics/internal/lv", + "metrics/prometheus" ] revision = "4dc7be5d2d12881735283bcab7352178e190fc71" version = "v0.6.0" @@ -131,6 +141,12 @@ revision = "c2353362d570a7bfa228149c62842019201cfb71" version = "v1.8.0" +[[projects]] + name = "github.com/matttproud/golang_protobuf_extensions" + packages = ["pbutil"] + revision = "c12348ce28de40eed0136aa2b644d0ee0650e56c" + version = "v1.0.1" + [[projects]] branch = "master" name = "github.com/mitchellh/mapstructure" @@ -155,6 +171,39 @@ revision = "792786c7400a136282c1664665ae0a8db921c6c2" 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]] branch = "master" name = "github.com/rcrowley/go-metrics" @@ -374,6 +423,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "62d0626fa963b25411234da915fb3b8bfc7aefffd76824d27ac1647ca2b5d489" + inputs-digest = "294ac88a5b44228f5ef841b13602d0a8b8fed5fbe9b9b6df77640d636175be16" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index b7393a475..13339e550 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -97,3 +97,7 @@ [prune] go-tests = true unused-packages = true + +[[constraint]] + name = "github.com/prometheus/client_golang" + version = "0.8.0" diff --git a/consensus/common_test.go b/consensus/common_test.go index f50e57699..ea1415924 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -267,7 +267,7 @@ func newConsensusStateWithConfigAndBlockStore(thisConfig *cfg.Config, state sm.S // Make ConsensusState stateDB := dbm.NewMemDB() 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.SetPrivValidator(pv) diff --git a/consensus/metrics.go b/consensus/metrics.go new file mode 100644 index 000000000..06df7e35c --- /dev/null +++ b/consensus/metrics.go @@ -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(), + } +} diff --git a/consensus/replay_file.go b/consensus/replay_file.go index 57204b01a..113c69c86 100644 --- a/consensus/replay_file.go +++ b/consensus/replay_file.go @@ -126,7 +126,7 @@ func (pb *playback) replayReset(count int, newStepCh chan interface{}) error { pb.cs.Wait() 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.startForReplay() @@ -314,7 +314,7 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyApp.Consensus(), mempool, evpool) consensusState := NewConsensusState(csConfig, state.Copy(), blockExec, - blockStore, mempool, evpool) + blockStore, mempool, evpool, NopMetrics()) consensusState.SetEventBus(eventBus) return consensusState diff --git a/consensus/state.go b/consensus/state.go index d46ec5830..3b6c029f7 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -115,10 +115,13 @@ type ConsensusState struct { // synchronous pubsub between consensus state and reactor. // state only emits EventNewRoundStep, EventVote and EventProposalHeartbeat evsw tmevents.EventSwitch + + // for reporting metrics + metrics *Metrics } // 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{ config: config, blockExec: blockExec, @@ -132,6 +135,7 @@ func NewConsensusState(config *cfg.ConsensusConfig, state sm.State, blockExec *s wal: nilWAL{}, evpool: evpool, evsw: tmevents.NewEventSwitch(), + metrics: metrics, } // set function defaults (may be overwritten before calling Start) cs.decideProposal = cs.defaultDecideProposal @@ -388,6 +392,7 @@ func (cs *ConsensusState) SetProposalAndBlock(proposal *types.Proposal, block *t func (cs *ConsensusState) updateHeight(height int64) { cs.Height = height + cs.metrics.Height.Add(float64(height - cs.Height)) } func (cs *ConsensusState) updateRoundStep(round int, step cstypes.RoundStepType) { diff --git a/consensus/wal_generator.go b/consensus/wal_generator.go index f61af15f5..dab93c343 100644 --- a/consensus/wal_generator.go +++ b/consensus/wal_generator.go @@ -68,7 +68,7 @@ func WALWithNBlocks(numBlocks int) (data []byte, err error) { mempool := sm.MockMempool{} evpool := sm.MockEvidencePool{} 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.SetEventBus(eventBus) if privValidator != nil { diff --git a/node/node.go b/node/node.go index efeb17ee0..538055a8e 100644 --- a/node/node.go +++ b/node/node.go @@ -7,6 +7,9 @@ import ( "net" "net/http" + prometheus "github.com/go-kit/kit/metrics/prometheus" + stdprometheus "github.com/prometheus/client_golang/prometheus" + abci "github.com/tendermint/abci/types" amino "github.com/tendermint/go-amino" crypto "github.com/tendermint/go-crypto" @@ -241,8 +244,15 @@ func NewNode(config *cfg.Config, bcReactor.SetLogger(logger.With("module", "blockchain")) // 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(), - blockExec, blockStore, mempool, evidencePool) + blockExec, blockStore, mempool, evidencePool, metrics) consensusState.SetLogger(consensusLogger) if privValidator != nil { consensusState.SetPrivValidator(privValidator)