Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions go/consensus/cometbft/cometbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func New(
genesis genesisAPI.Provider,
doc *genesisAPI.Document,
p2p p2pAPI.Service,
metricsEnabled bool,
) (consensusAPI.Service, error) {
genesisDoc, err := api.GetCometBFTGenesisDocument(doc)
if err != nil {
Expand All @@ -39,7 +40,7 @@ func New(

switch config.GlobalConfig.Mode {
case config.ModeArchive:
node, err := createArchiveNode(ctx, dataDir, identity, genesis, doc, genesisDoc)
node, err := createArchiveNode(ctx, dataDir, identity, genesis, doc, genesisDoc, metricsEnabled)
if err != nil {
return nil, fmt.Errorf("failed to create archive node: %w", err)
}
Expand All @@ -51,7 +52,7 @@ func New(
}
return node, nil
default:
node, err := createFullNode(ctx, dataDir, identity, genesis, doc, genesisDoc, upgrader, p2p)
node, err := createFullNode(ctx, dataDir, identity, genesis, doc, genesisDoc, upgrader, p2p, metricsEnabled)
if err != nil {
return nil, fmt.Errorf("failed to create full node: %w", err)
}
Expand All @@ -66,9 +67,10 @@ func createArchiveNode(
genesis genesisAPI.Provider,
doc *genesisAPI.Document,
genesisDoc *cmttypes.GenesisDoc,
metricsEnabled bool,
) (consensusAPI.Service, error) {
cfg := full.ArchiveConfig{
CommonConfig: createCommonConfig(dataDir, identity, genesis, doc, genesisDoc),
CommonConfig: createCommonConfig(dataDir, identity, genesis, doc, genesisDoc, metricsEnabled),
}

return full.NewArchive(ctx, cfg)
Expand All @@ -83,9 +85,10 @@ func createFullNode(
genesisDoc *cmttypes.GenesisDoc,
upgrader upgradeAPI.Backend,
p2p p2pAPI.Service,
metricsEnabled bool,
) (consensusAPI.Service, error) {
cfg := full.Config{
CommonConfig: createCommonConfig(dataDir, identity, genesis, doc, genesisDoc),
CommonConfig: createCommonConfig(dataDir, identity, genesis, doc, genesisDoc, metricsEnabled),
TimeoutCommit: doc.Consensus.Parameters.TimeoutCommit,
EmptyBlockInterval: doc.Consensus.Parameters.EmptyBlockInterval,
SkipTimeoutCommit: doc.Consensus.Parameters.SkipTimeoutCommit,
Expand Down Expand Up @@ -193,6 +196,7 @@ func createCommonConfig(
genesis genesisAPI.Provider,
doc *genesisAPI.Document,
genesisDoc *cmttypes.GenesisDoc,
metricsEnabled bool,
) full.CommonConfig {
return full.CommonConfig{
DataDir: dataDir,
Expand All @@ -205,6 +209,7 @@ func createCommonConfig(
BaseEpoch: doc.Beacon.Base,
BaseHeight: doc.Height,
PublicKeyBlacklist: doc.Consensus.Parameters.PublicKeyBlacklist,
MetricsEnabled: metricsEnabled,
}
}

Expand Down
8 changes: 6 additions & 2 deletions go/consensus/cometbft/full/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import (
governanceAPI "github.com/oasisprotocol/oasis-core/go/governance/api"
keymanagerAPI "github.com/oasisprotocol/oasis-core/go/keymanager/api"
cmbackground "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/background"
cmmetrics "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/metrics"
"github.com/oasisprotocol/oasis-core/go/registry"
registryAPI "github.com/oasisprotocol/oasis-core/go/registry/api"
roothashAPI "github.com/oasisprotocol/oasis-core/go/roothash/api"
Expand Down Expand Up @@ -101,6 +100,8 @@ type CommonConfig struct {
BaseHeight int64
// PublicKeyBlacklist is the network-wide public key blacklist.
PublicKeyBlacklist []signature.PublicKey
// MetricsEnabled is true if prometheus metrics are enabled.
MetricsEnabled bool
}

// commonNode implements the common CometBFT node functionality shared between
Expand Down Expand Up @@ -149,6 +150,8 @@ type commonNode struct {
startedCh chan struct{}

parentNode consensusAPI.Backend

metricsEnabled bool
}

func (n *commonNode) initialized() bool {
Expand Down Expand Up @@ -304,7 +307,7 @@ func (n *commonNode) initialize() error {
}

// Start metrics.
if cmmetrics.Enabled() {
if n.metricsEnabled {
rmu := registry.NewMetricsUpdater(n.ctx, n.registry)
n.svcMgr.RegisterCleanupOnly(rmu, "registry metrics updater")
}
Expand Down Expand Up @@ -909,6 +912,7 @@ func newCommonNode(ctx context.Context, cfg CommonConfig) *commonNode {
svcMgr: cmbackground.NewServiceManager(logging.GetLogger("cometbft/servicemanager")),
dbCloser: db.NewCloser(),
startedCh: make(chan struct{}),
metricsEnabled: cfg.MetricsEnabled,
}
}

Expand Down
3 changes: 1 addition & 2 deletions go/consensus/cometbft/full/full.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import (
"github.com/oasisprotocol/oasis-core/go/consensus/metrics"
"github.com/oasisprotocol/oasis-core/go/consensus/pricediscovery"
cmflags "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags"
cmmetrics "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/metrics"
p2pAPI "github.com/oasisprotocol/oasis-core/go/p2p/api"
registryAPI "github.com/oasisprotocol/oasis-core/go/registry/api"
stakingAPI "github.com/oasisprotocol/oasis-core/go/staking/api"
Expand Down Expand Up @@ -173,7 +172,7 @@ func (t *fullService) Start() error {
// Start block notifier.
go t.blockNotifierWorker()
// Optionally start metrics updater.
if cmmetrics.Enabled() {
if t.commonNode.metricsEnabled {
go t.metrics()
}
case false:
Expand Down
2 changes: 1 addition & 1 deletion go/oasis-node/cmd/common/metrics/config/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package config implements global metrics configuration options.
// Package config implements metrics configuration options.
package config

import (
Expand Down
35 changes: 18 additions & 17 deletions go/oasis-node/cmd/common/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (

"github.com/oasisprotocol/oasis-core/go/common/service"
"github.com/oasisprotocol/oasis-core/go/common/version"
"github.com/oasisprotocol/oasis-core/go/config"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/metrics/config"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/env"
)

Expand Down Expand Up @@ -107,8 +107,8 @@ func (s *pullService) Cleanup() {
}
}

func newPullService() (service.BackgroundService, error) {
addr := config.GlobalConfig.Metrics.Address
func newPullService(cfg *config.Config) (service.BackgroundService, error) {
addr := cfg.Address

svc := *service.NewBaseBackgroundService("metrics")

Expand All @@ -127,7 +127,7 @@ func newPullService() (service.BackgroundService, error) {
ln: ln,
s: &http.Server{Handler: promhttp.Handler(), ReadTimeout: 5 * time.Second},
errCh: make(chan error),
rsvc: newResourceService(config.GlobalConfig.Metrics.Interval),
rsvc: newResourceService(cfg.Interval),
}, nil
}

Expand Down Expand Up @@ -222,14 +222,14 @@ func (s *pushService) initPusher(isReinit bool) {
s.pusher = pusher
}

func newPushService() (service.BackgroundService, error) {
func newPushService(cfg *config.Config) (service.BackgroundService, error) {
svc := &pushService{
BaseBackgroundService: *service.NewBaseBackgroundService("metrics"),
addr: config.GlobalConfig.Metrics.Address,
jobName: config.GlobalConfig.Metrics.JobName,
labels: config.GlobalConfig.Metrics.Labels,
interval: config.GlobalConfig.Metrics.Interval,
rsvc: newResourceService(config.GlobalConfig.Metrics.Interval),
addr: cfg.Address,
jobName: cfg.JobName,
labels: cfg.Labels,
interval: cfg.Interval,
rsvc: newResourceService(cfg.Interval),
stopCh: make(chan struct{}),
quitCh: make(chan struct{}),
}
Expand All @@ -247,24 +247,25 @@ func newPushService() (service.BackgroundService, error) {
}

// New constructs a new metrics service.
func New() (service.BackgroundService, error) {
mode := strings.ToLower(config.GlobalConfig.Metrics.Mode)
func New(cfg *config.Config) (service.BackgroundService, error) {
mode := strings.ToLower(cfg.Mode)
switch mode {
case MetricsModeNone:
return newStubService()
case MetricsModePull:
return newPullService()
return newPullService(cfg)
default:
if mode == MetricsModePush && flags.DebugDontBlameOasis() {
return newPushService()
return newPushService(cfg)
}
return nil, fmt.Errorf("metrics: unsupported mode: '%v'", mode)
}
}

// Enabled returns if metrics are enabled.
func Enabled() bool {
return config.GlobalConfig.Metrics.Mode != MetricsModeNone
func Enabled(mode string) bool {
mode = strings.ToLower(mode)
return mode != MetricsModeNone
}

// EscapeLabelCharacters replaces invalid prometheus label name characters with "_".
Expand All @@ -289,7 +290,7 @@ func GetDefaultPushLabels(ti *env.ScenarioInstanceInfo) map[string]string {
labels[EscapeLabelCharacters(f.Name)] = f.Value.String()
})
// Override any labels passed to oasis-test-runner via CLI.
for k, v := range config.GlobalConfig.Metrics.Labels {
for k, v := range config.DefaultConfig().Labels { // TODO explain in the commit why this is safe.
labels[k] = v
}

Expand Down
5 changes: 4 additions & 1 deletion go/oasis-node/cmd/debug/byzantine/beacon_vrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
"github.com/oasisprotocol/oasis-core/go/common/logging"
"github.com/oasisprotocol/oasis-core/go/common/node"
"github.com/oasisprotocol/oasis-core/go/config"
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
"github.com/oasisprotocol/oasis-core/go/consensus/api/transaction"
scheduler "github.com/oasisprotocol/oasis-core/go/scheduler/api"
Expand Down Expand Up @@ -81,7 +82,9 @@ func doVRFBeaconScenario(*cobra.Command, []string) {
}

round := uint64(3)
b, err := initializeAndRegisterByzantineNode(runtimeID, node.RoleValidator, scheduler.RoleInvalid, false, true, round)
// For every command where applicable you will have to parse yaml config??
cfg := &config.GlobalConfig
b, err := initializeAndRegisterByzantineNode(cfg, runtimeID, node.RoleValidator, scheduler.RoleInvalid, false, true, round)
if err != nil {
panic(fmt.Sprintf("error initializing node: %+v", err))
}
Expand Down
4 changes: 4 additions & 0 deletions go/oasis-node/cmd/debug/byzantine/byzantine.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/oasisprotocol/oasis-core/go/common/node"
"github.com/oasisprotocol/oasis-core/go/common/sgx/ias"
"github.com/oasisprotocol/oasis-core/go/common/sgx/pcs"
"github.com/oasisprotocol/oasis-core/go/config"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/grpc"
"github.com/oasisprotocol/oasis-core/go/roothash/api/block"
Expand Down Expand Up @@ -147,7 +148,10 @@ func doExecutorScenario(*cobra.Command, []string) { //nolint: gocyclo

round := uint64(3)
isTxScheduler := viper.GetBool(CfgPrimarySchedulerExpected)
// For every command where applicable you will have to parse yaml config??
cfg := &config.GlobalConfig
b, err := initializeAndRegisterByzantineNode(
cfg,
runtimeID,
node.RoleComputeWorker,
scheduler.RoleWorker,
Expand Down
4 changes: 2 additions & 2 deletions go/oasis-node/cmd/debug/byzantine/cometbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ func newHonestCometBFT(genesis genesis.Provider, genesisDoc *genesis.Document) *
}
}

func (ht *honestCometBFT) start(id *identity.Identity, dataDir string) error {
func (ht *honestCometBFT) start(id *identity.Identity, dataDir string, metricsEnabled bool) error {
if ht.service != nil {
return fmt.Errorf("honest CometBFT service already started")
}

var err error
ht.service, err = cometbft.New(context.Background(), dataDir, id, upgrade.NewDummyUpgradeManager(), ht.genesis, ht.genesisDoc, p2p.NewNop())
ht.service, err = cometbft.New(context.Background(), dataDir, id, upgrade.NewDummyUpgradeManager(), ht.genesis, ht.genesisDoc, p2p.NewNop(), metricsEnabled)
if err != nil {
return fmt.Errorf("cometbft New: %w", err)
}
Expand Down
8 changes: 6 additions & 2 deletions go/oasis-node/cmd/debug/byzantine/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import (
"github.com/oasisprotocol/oasis-core/go/common/identity"
"github.com/oasisprotocol/oasis-core/go/common/logging"
"github.com/oasisprotocol/oasis-core/go/common/node"
"github.com/oasisprotocol/oasis-core/go/config"
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
genesis "github.com/oasisprotocol/oasis-core/go/genesis/file"
cmdCommon "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common"
cmdFlags "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/metrics"
"github.com/oasisprotocol/oasis-core/go/roothash/api/block"
"github.com/oasisprotocol/oasis-core/go/roothash/api/commitment"
scheduler "github.com/oasisprotocol/oasis-core/go/scheduler/api"
Expand Down Expand Up @@ -96,6 +98,7 @@ func (b *byzantine) receiveAndScheduleTransactions(ctx context.Context, cbc *com
}

func initializeAndRegisterByzantineNode(
cfg *config.Config,
runtimeID common.Namespace,
nodeRoles node.RolesMask,
expectedExecutorRole scheduler.Role,
Expand Down Expand Up @@ -139,13 +142,14 @@ func initializeAndRegisterByzantineNode(

// Setup CometBFT.
b.cometbft = newHonestCometBFT(genesis, genesisDoc)
if err = b.cometbft.start(b.identity, cmdCommon.DataDir()); err != nil {
metricsEnabled := metrics.Enabled(cfg.Metrics.Mode)
if err = b.cometbft.start(b.identity, cmdCommon.DataDir(), metricsEnabled); err != nil {
return nil, fmt.Errorf("node cometbft start failed: %w", err)
}

// Setup P2P.
b.p2p = newP2PHandle()
if err = b.p2p.start(b.cometbft, b.identity, b.chainContext, b.runtimeID); err != nil {
if err = b.p2p.start(cfg, b.cometbft, b.identity, b.chainContext, b.runtimeID); err != nil {
return nil, fmt.Errorf("P2P start failed: %w", err)
}

Expand Down
9 changes: 7 additions & 2 deletions go/oasis-node/cmd/debug/byzantine/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/oasisprotocol/oasis-core/go/common/cbor"
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
"github.com/oasisprotocol/oasis-core/go/common/identity"
"github.com/oasisprotocol/oasis-core/go/config"
"github.com/oasisprotocol/oasis-core/go/p2p"
p2pAPI "github.com/oasisprotocol/oasis-core/go/p2p/api"
"github.com/oasisprotocol/oasis-core/go/p2p/protocol"
Expand Down Expand Up @@ -91,13 +92,17 @@ func (h *committeeMsgHandler) HandleMessage(_ context.Context, peerID signature.
return <-responseCh
}

func (ph *p2pHandle) start(ht *honestCometBFT, id *identity.Identity, chainContext string, runtimeID common.Namespace) error {
func (ph *p2pHandle) start(yamlCfg *config.Config, ht *honestCometBFT, id *identity.Identity, chainContext string, runtimeID common.Namespace) error {
if ph.service != nil {
return fmt.Errorf("P2P service already started")
}

var cfg p2p.Config
if err := cfg.Load(&yamlCfg.P2P); err != nil {
return fmt.Errorf("failed to parse p2p config %w", err)
}
var err error
ph.service, err = p2p.New(id, chainContext, nil)
ph.service, err = p2p.New(&cfg, id, chainContext, nil)
if err != nil {
return fmt.Errorf("P2P service New: %w", err)
}
Expand Down
5 changes: 4 additions & 1 deletion go/oasis-node/cmd/ias/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/oasisprotocol/oasis-core/go/common/grpc"
"github.com/oasisprotocol/oasis-core/go/common/logging"
cmnIAS "github.com/oasisprotocol/oasis-core/go/common/sgx/ias"
"github.com/oasisprotocol/oasis-core/go/config"
ias "github.com/oasisprotocol/oasis-core/go/ias/api"
iasHTTP "github.com/oasisprotocol/oasis-core/go/ias/http"
iasProxy "github.com/oasisprotocol/oasis-core/go/ias/proxy"
Expand Down Expand Up @@ -152,8 +153,10 @@ func doProxy(cmd *cobra.Command, _ []string) {
}
env.svcMgr.Register(env.grpcSrv)

// For every command where applicable you will have to parse yaml config??
cfg := &config.GlobalConfig
// Initialize the metrics server.
metrics, err := metrics.New()
metrics, err := metrics.New(&cfg.Metrics)
if err != nil {
logger.Error("failed to initialize metrics server",
"err", err,
Expand Down
6 changes: 4 additions & 2 deletions go/oasis-node/cmd/node/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
cmdCommon "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/background"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/metrics"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/metrics/config"

"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/pprof"
cmdSigner "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/signer"
)
Expand Down Expand Up @@ -81,9 +83,9 @@ func loadOrGenerateIdentity(dataDir string, logger *logging.Logger) (*identity.I
}

// startMetricServer initializes and starts the metrics reporting server.
func startMetricServer(svcMgr *background.ServiceManager, logger *logging.Logger) (service.BackgroundService, error) {
func startMetricServer(svcMgr *background.ServiceManager, logger *logging.Logger, cfg *config.Config) (service.BackgroundService, error) {
// Initialize the metrics server.
metrics, err := metrics.New()
metrics, err := metrics.New(cfg)
if err != nil {
logger.Error("failed to initialize metrics server",
"err", err,
Expand Down
Loading
Loading