Browse Source

do not overwrite metrics provider in node#NewNode

also, make running Prometheus server optional.

Closes #2019
pull/2044/head
Anton Kaliaev 7 years ago
parent
commit
75a26ebd6d
No known key found for this signature in database GPG Key ID: 7B6881D965918214
2 changed files with 14 additions and 23 deletions
  1. +13
    -22
      node/node.go
  2. +1
    -1
      rpc/test/helpers.go

+ 13
- 22
node/node.go View File

@ -85,7 +85,7 @@ func DefaultNewNode(config *cfg.Config, logger log.Logger) (*Node, error) {
proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
DefaultGenesisDocProviderFunc(config),
DefaultDBProvider,
DefaultMetricsProvider,
DefaultMetricsProvider(config.Instrumentation),
logger,
)
}
@ -93,15 +93,15 @@ func DefaultNewNode(config *cfg.Config, logger log.Logger) (*Node, error) {
// MetricsProvider returns a consensus, p2p and mempool Metrics.
type MetricsProvider func() (*cs.Metrics, *p2p.Metrics, *mempl.Metrics)
// DefaultMetricsProvider returns consensus, p2p and mempool Metrics build
// using Prometheus client library.
func DefaultMetricsProvider() (*cs.Metrics, *p2p.Metrics, *mempl.Metrics) {
return cs.PrometheusMetrics(), p2p.PrometheusMetrics(), mempl.PrometheusMetrics()
}
// NopMetricsProvider returns consensus, p2p and mempool Metrics as no-op.
func NopMetricsProvider() (*cs.Metrics, *p2p.Metrics, *mempl.Metrics) {
return cs.NopMetrics(), p2p.NopMetrics(), mempl.NopMetrics()
// DefaultMetricsProvider returns Metrics build using Prometheus client library
// if Prometheus is enabled. Otherwise, it returns no-op Metrics.
func DefaultMetricsProvider(config *cfg.InstrumentationConfig) MetricsProvider {
return func() (*cs.Metrics, *p2p.Metrics, *mempl.Metrics) {
if config.Prometheus {
return cs.PrometheusMetrics(), p2p.PrometheusMetrics(), mempl.PrometheusMetrics()
}
return cs.NopMetrics(), p2p.NopMetrics(), mempl.NopMetrics()
}
}
//------------------------------------------------------------------------------
@ -229,17 +229,7 @@ func NewNode(config *cfg.Config,
consensusLogger.Info("This node is not a validator", "addr", privValidator.GetAddress(), "pubKey", privValidator.GetPubKey())
}
// metrics
var (
csMetrics *cs.Metrics
p2pMetrics *p2p.Metrics
memplMetrics *mempl.Metrics
)
if config.Instrumentation.Prometheus {
csMetrics, p2pMetrics, memplMetrics = metricsProvider()
} else {
csMetrics, p2pMetrics, memplMetrics = NopMetricsProvider()
}
csMetrics, p2pMetrics, memplMetrics := metricsProvider()
// Make MempoolReactor
mempoolLogger := logger.With("module", "mempool")
@ -462,7 +452,8 @@ func (n *Node) OnStart() error {
n.rpcListeners = listeners
}
if n.config.Instrumentation.Prometheus {
if n.config.Instrumentation.Prometheus &&
n.config.Instrumentation.PrometheusListenAddr != "" {
n.prometheusSrv = n.startPrometheusServer(n.config.Instrumentation.PrometheusListenAddr)
}


+ 1
- 1
rpc/test/helpers.go View File

@ -123,7 +123,7 @@ func NewTendermint(app abci.Application) *nm.Node {
node, err := nm.NewNode(config, pv, papp,
nm.DefaultGenesisDocProviderFunc(config),
nm.DefaultDBProvider,
nm.DefaultMetricsProvider,
nm.DefaultMetricsProvider(config.Instrumentation),
logger)
if err != nil {
panic(err)


Loading…
Cancel
Save