Skip to content

Commit

Permalink
chore: add metrics provider as a paramater upon node creation (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Mar 5, 2024
1 parent da7f62c commit da9a85b
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ proto/pb
.idea
.go-version
build

vendor/
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
golang 1.20
8 changes: 8 additions & 0 deletions block/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ var rollappHubHeightGauge = promauto.NewGauge(prometheus.GaugeOpts{
Name: "rollapp_hub_height",
Help: "The latest height of the Rollapp that has been synced to the hub.",
})
var rollappBlockSizeBytesGauge = promauto.NewGauge(prometheus.GaugeOpts{
Name: "rollapp_block_size_bytes",
Help: "Rollapp ",
})
var rollappBlockSizeTxsGauge = promauto.NewGauge(prometheus.GaugeOpts{
Name: "rollapp_block_size_txs",
Help: "Rollapp ",
})
2 changes: 2 additions & 0 deletions block/produce.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ func (m *Manager) produceBlock(ctx context.Context, allowEmpty bool) error {
}

m.logger.Info("block created", "height", newHeight, "num_tx", len(block.Data.Txs))
rollappBlockSizeBytesGauge.Set(float64(len(block.Data.Txs)))
rollappBlockSizeTxsGauge.Set(float64(len(block.Data.Txs)))
rollappHeightGauge.Set(float64(newHeight))
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/dymint/commands/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

cfg "github.com/dymensionxyz/dymint/config"
"github.com/dymensionxyz/dymint/conv"
"github.com/dymensionxyz/dymint/mempool"
"github.com/dymensionxyz/dymint/node"
"github.com/dymensionxyz/dymint/rpc"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -95,6 +96,7 @@ func startInProcess(config *cfg.NodeConfig, tmConfig *tmcfg.Config, logger log.L
proxy.DefaultClientCreator(tmConfig.ProxyApp, tmConfig.ABCI, tmConfig.DBDir()),
genesis,
logger,
mempool.PrometheusMetrics("dymint"),
)
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion node/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"time"

"github.com/dymensionxyz/dymint/mempool"
"github.com/dymensionxyz/dymint/p2p"
"github.com/dymensionxyz/dymint/settlement"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -66,7 +67,7 @@ func TestAggregatorMode(t *testing.T) {
SettlementLayer: "mock",
SettlementConfig: settlement.Config{ProposerPubKey: proposerKey},
}
node, err := NewNode(context.Background(), nodeConfig, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
node, err := NewNode(context.Background(), nodeConfig, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger(), mempool.NopMetrics())
require.NoError(err)
require.NotNil(node)

Expand Down
2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ type Node struct {
}

// NewNode creates new Dymint node.
func NewNode(ctx context.Context, conf config.NodeConfig, p2pKey crypto.PrivKey, signingKey crypto.PrivKey, clientCreator proxy.ClientCreator, genesis *tmtypes.GenesisDoc, logger log.Logger) (*Node, error) {
func NewNode(ctx context.Context, conf config.NodeConfig, p2pKey crypto.PrivKey, signingKey crypto.PrivKey, clientCreator proxy.ClientCreator, genesis *tmtypes.GenesisDoc, logger log.Logger, metrics *mempool.Metrics) (*Node, error) {
proxyApp := proxy.NewAppConns(clientCreator)
proxyApp.SetLogger(logger.With("module", "proxy"))
if err := proxyApp.Start(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestMempoolDirectly(t *testing.T) {
SettlementLayer: "mock",
SettlementConfig: settlement.Config{},
}
node, err := NewNode(context.Background(), nodeConfig, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
node, err := NewNode(context.Background(), nodeConfig, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger(), mempool.NopMetrics())
require.NoError(err)
require.NotNil(node)

Expand Down
3 changes: 2 additions & 1 deletion node/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/dymensionxyz/dymint/config"
"github.com/dymensionxyz/dymint/mempool"
"github.com/dymensionxyz/dymint/settlement"
"github.com/dymensionxyz/dymint/testutil"
"github.com/libp2p/go-libp2p/core/crypto"
Expand Down Expand Up @@ -39,7 +40,7 @@ func CreateNode(isAggregator bool, blockManagerConfig *config.BlockManagerConfig
// SL config
nodeConfig.SettlementConfig = settlement.Config{ProposerPubKey: hex.EncodeToString(pubkeyBytes)}

node, err := NewNode(context.Background(), nodeConfig, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
node, err := NewNode(context.Background(), nodeConfig, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger(), mempool.NopMetrics())
if err != nil {
return nil, err
}
Expand Down
13 changes: 7 additions & 6 deletions rpc/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/dymensionxyz/dymint/config"
abciconv "github.com/dymensionxyz/dymint/conv/abci"
"github.com/dymensionxyz/dymint/mempool"
"github.com/dymensionxyz/dymint/mocks"
"github.com/dymensionxyz/dymint/node"
"github.com/dymensionxyz/dymint/settlement"
Expand Down Expand Up @@ -112,7 +113,7 @@ func TestGenesisChunked(t *testing.T) {
SettlementLayer: "mock",
SettlementConfig: settlement.Config{},
}
n, _ := node.NewNode(context.Background(), config, privKey, signingKey, proxy.NewLocalClientCreator(mockApp), genDoc, log.TestingLogger())
n, _ := node.NewNode(context.Background(), config, privKey, signingKey, proxy.NewLocalClientCreator(mockApp), genDoc, log.TestingLogger(), mempool.NopMetrics())

rpc := NewClient(n)

Expand Down Expand Up @@ -447,7 +448,7 @@ func TestTx(t *testing.T) {
},
key, signingKey, proxy.NewLocalClientCreator(mockApp),
&tmtypes.GenesisDoc{ChainID: "test"},
log.TestingLogger())
log.TestingLogger(), mempool.NopMetrics())
require.NoError(err)
require.NotNil(node)

Expand Down Expand Up @@ -715,7 +716,7 @@ func TestValidatorSetHandling(t *testing.T) {
SettlementConfig: settlement.Config{ProposerPubKey: hex.EncodeToString(proposerPubKeyBytes)},
}

node, err := node.NewNode(context.Background(), nodeConfig, key, signingKey, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators}, log.TestingLogger())
node, err := node.NewNode(context.Background(), nodeConfig, key, signingKey, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators}, log.TestingLogger(), mempool.NopMetrics())
require.NoError(err)
require.NotNil(node)

Expand Down Expand Up @@ -837,7 +838,7 @@ func getRPC(t *testing.T) (*mocks.Application, *Client) {
SettlementLayer: "mock",
SettlementConfig: settlement.Config{ProposerPubKey: proposerKey},
}
node, err := node.NewNode(context.Background(), config, key, signingKey, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
node, err := node.NewNode(context.Background(), config, key, signingKey, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger(), mempool.NopMetrics())
require.NoError(err)
require.NotNil(node)

Expand Down Expand Up @@ -923,7 +924,7 @@ func TestMempool2Nodes(t *testing.T) {
P2P: config.P2PConfig{
ListenAddress: "/ip4/127.0.0.1/tcp/9001",
},
}, key1, signingKey1, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
}, key1, signingKey1, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger(), mempool.NopMetrics())
require.NoError(err)
require.NotNil(node1)

Expand All @@ -943,7 +944,7 @@ func TestMempool2Nodes(t *testing.T) {
ListenAddress: "/ip4/127.0.0.1/tcp/9002",
Seeds: "/ip4/127.0.0.1/tcp/9001/p2p/" + id1.String(),
},
}, key2, signingKey2, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
}, key2, signingKey2, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger(), mempool.NopMetrics())
require.NoError(err)
require.NotNil(node1)

Expand Down
3 changes: 2 additions & 1 deletion rpc/json/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/tendermint/tendermint/types"

"github.com/dymensionxyz/dymint/config"
"github.com/dymensionxyz/dymint/mempool"
"github.com/dymensionxyz/dymint/mocks"
"github.com/dymensionxyz/dymint/node"
"github.com/dymensionxyz/dymint/rpc/client"
Expand Down Expand Up @@ -307,7 +308,7 @@ func getRPC(t *testing.T) (*mocks.Application, *client.Client) {
SettlementConfig: settlement.Config{
ProposerPubKey: hex.EncodeToString(proposerPubKeyBytes)},
}
node, err := node.NewNode(context.Background(), config, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
node, err := node.NewNode(context.Background(), config, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger(), mempool.NopMetrics())
require.NoError(err)
require.NotNil(node)

Expand Down

0 comments on commit da9a85b

Please sign in to comment.