Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load log level in processor app, add config in stats #2241

Merged
merged 2 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion cmd/vega/node_pre.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (l *NodeCommand) persistentPre(_ *cobra.Command, args []string) (err error)
logging.Uint64("nofile", l.conf.UlimitNOFile))
}

l.stats = stats.New(l.Log, l.cli.version, l.cli.versionHash)
l.stats = stats.New(l.Log, l.conf.Stats, l.cli.version, l.cli.versionHash)

// set up storage, this should be persistent
if err := l.setupStorages(); err != nil {
Expand Down Expand Up @@ -272,6 +272,7 @@ func (l *NodeCommand) setupStorages() (err error) {
func(cfg config.Config) { l.riskStore.ReloadConf(cfg.Storage) },
func(cfg config.Config) { l.marketDataStore.ReloadConf(cfg.Storage) },
func(cfg config.Config) { l.marketStore.ReloadConf(cfg.Storage) },
func(cfg config.Config) { l.stats.ReloadConf(cfg.Stats) },
)

return
Expand Down Expand Up @@ -552,6 +553,7 @@ func (l *NodeCommand) preRun(_ *cobra.Command, _ []string) (err error) {
func(cfg config.Config) { l.banking.ReloadConf(cfg.Banking) },
func(cfg config.Config) { l.governance.ReloadConf(cfg.Governance) },
func(cfg config.Config) { l.nodeWallet.ReloadConf(cfg.NodeWallet) },
func(cfg config.Config) { app.ReloadConf(cfg.Processor) },

// services
func(cfg config.Config) { l.candleService.ReloadConf(cfg.Candles) },
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"code.vegaprotocol.io/vega/processor"
"code.vegaprotocol.io/vega/risk"
"code.vegaprotocol.io/vega/settlement"
"code.vegaprotocol.io/vega/stats"
"code.vegaprotocol.io/vega/storage"
"code.vegaprotocol.io/vega/subscribers"
"code.vegaprotocol.io/vega/trades"
Expand Down Expand Up @@ -73,6 +74,7 @@ type Config struct {
Genesis genesis.Config
Validators validators.Config
Banking banking.Config
Stats stats.Config

Pprof pprof.Config
GatewayEnabled bool
Expand Down Expand Up @@ -115,6 +117,7 @@ func NewDefaultConfig(defaultStoreDirPath string) Config {
Genesis: genesis.NewDefaultConfig(),
Validators: validators.NewDefaultConfig(),
Banking: banking.NewDefaultConfig(),
Stats: stats.NewDefaultConfig(),
Subscribers: subscribers.NewDefaultConfig(),
GatewayEnabled: true,
StoresEnabled: true,
Expand Down
25 changes: 21 additions & 4 deletions processor/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type App struct {
hasRegistered bool
size uint64

Config
cfg Config
log *logging.Logger
cancelFn func()
idGen *IDgenerator
Expand Down Expand Up @@ -71,6 +71,9 @@ func NewApp(
top ValidatorTopology,
wallet Wallet,
) (*App, error) {
log = log.Named(namedLogger)
log.SetLevel(config.Level.Get())

vegaWallet, ok := wallet.Get(nodewallet.Vega)
if !ok {
return nil, ErrVegaWalletRequired
Expand All @@ -80,7 +83,7 @@ func NewApp(
abci: abci.New(&codec{}),

log: log,
Config: config,
cfg: config,
cancelFn: cancelFn,
idGen: NewIDGen(),

Expand Down Expand Up @@ -127,6 +130,20 @@ func NewApp(
return app, nil
}

// ReloadConf updates the internal configuration
func (a *App) ReloadConf(cfg Config) {
a.log.Info("reloading configuration")
if a.log.GetLevel() != cfg.Level.Get() {
a.log.Info("updating log level",
logging.String("old", a.log.GetLevel().String()),
logging.String("new", cfg.Level.String()),
)
a.log.SetLevel(cfg.Level.Get())
}

a.cfg = cfg
}

func (app *App) Abci() *abci.App {
return app.abci
}
Expand Down Expand Up @@ -319,7 +336,7 @@ func (app *App) DeliverCancelOrder(ctx context.Context, tx abci.Tx) error {
app.log.Error("error on cancelling order", logging.String("order-id", order.OrderID), logging.Error(err))
return err
}
if app.LogOrderCancelDebug {
if app.cfg.LogOrderCancelDebug {
for _, v := range msg {
app.log.Debug("Order cancelled", logging.Order(*v.Order))
}
Expand All @@ -343,7 +360,7 @@ func (app *App) DeliverAmendOrder(ctx context.Context, tx abci.Tx) error {
app.log.Error("error on amending order", logging.String("order-id", order.OrderID), logging.Error(err))
return err
}
if app.LogOrderAmendDebug {
if app.cfg.LogOrderAmendDebug {
app.log.Debug("Order amended", logging.Order(*msg.Order))
}

Expand Down
23 changes: 23 additions & 0 deletions stats/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package stats

import (
"code.vegaprotocol.io/vega/config/encoding"
"code.vegaprotocol.io/vega/logging"
)

const (
namedLogger = "stats"
)

// Config represent the configuration
type Config struct {
Level encoding.LogLevel
}

// NewDefaultConfig creates an instance of the package specific configuration, given a
// pointer to a logger instance to be used for logging within the package.
func NewDefaultConfig() Config {
return Config{
Level: encoding.LogLevel{Level: logging.InfoLevel},
}
}
22 changes: 20 additions & 2 deletions stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
// Stats ties together all other package level application stats types.
type Stats struct {
log *logging.Logger
cfg Config
Blockchain *Blockchain
version string
versionHash string
Expand All @@ -17,16 +18,33 @@ type Stats struct {
}

// New instantiates a new Stats
func New(logger *logging.Logger, version string, versionHash string) *Stats {
func New(log *logging.Logger, cfg Config, version string, versionHash string) *Stats {
log = log.Named(namedLogger)
log.SetLevel(cfg.Level.Get())
return &Stats{
log: logger,
log: log,
cfg: cfg,
Blockchain: &Blockchain{},
version: version,
versionHash: versionHash,
uptime: time.Now(),
}
}

// ReloadConf updates the internal configuration
func (s *Stats) ReloadConf(cfg Config) {
s.log.Info("reloading configuration")
if s.log.GetLevel() != cfg.Level.Get() {
s.log.Info("updating log level",
logging.String("old", s.log.GetLevel().String()),
logging.String("new", cfg.Level.String()),
)
s.log.SetLevel(cfg.Level.Get())
}

s.cfg = cfg
}

// SetChainVersion sets the version of the chain in use by vega
func (s *Stats) SetChainVersion(v string) {
s.chainVersion = v
Expand Down