diff --git a/config.example.toml b/config.example.toml index 09d4f6c..1990ad9 100644 --- a/config.example.toml +++ b/config.example.toml @@ -3,21 +3,26 @@ # Verbosity level. Set to `debug` or even `trace` to make it more verbose. Defaults to `info`. level = "debug" # Whether to print logs in JSON format. Useful if you are using centralised logs solutions like ELK. -# Defaults to false +# Defaults to false. json = false # Tendermint configuration [tendermint] -# Tendermint RPC address. Omitting it will result in disabling Tendermint node metrics +# If set to false, the metrics related to Tendermint node would be disabled. Defaults to true. +enabled = true +# Tendermint RPC address. Defaults to "http://localhost:26657". address = "http://localhost:26657" # gRPC configuration [grpc] +# If set to false, the metrics related to upgrades would be disabled. Defaults to true. +enabled = true # Tendermint RPC address. Omitting it will result in disabling upgrades metrics. address = "localhost:9090" -# Cosmovisor configuration. Omitting any parameter will result in disabling Cosmovisor metrics. [cosmovisor] +# If set to false, the metrics related to Cosmovisor would be disabled. Defaults to true. +enabled = true # Path to folder storing fullnode data and configs (like ~/.gaia for cosmoshub). chain-folder = "/home/validator/.gaia" # Binary name (like gaiad for cosmoshub) diff --git a/go.mod b/go.mod index 8f10351..7e395a5 100644 --- a/go.mod +++ b/go.mod @@ -6,13 +6,13 @@ require ( github.com/BurntSushi/toml v1.2.1 github.com/Masterminds/semver v1.5.0 github.com/cosmos/cosmos-sdk v0.46.6 + github.com/creasty/defaults v1.7.0 github.com/google/uuid v1.3.0 - github.com/mcuadros/go-defaults v1.2.0 github.com/prometheus/client_golang v1.14.0 github.com/rs/zerolog v1.28.0 github.com/spf13/cobra v1.6.1 - github.com/tendermint/tendermint v0.34.24 google.golang.org/grpc v1.50.1 + gopkg.in/guregu/null.v4 v4.0.0 ) require ( @@ -95,6 +95,7 @@ require ( github.com/tendermint/btcd v0.1.1 // indirect github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 // indirect github.com/tendermint/go-amino v0.16.0 // indirect + github.com/tendermint/tendermint v0.34.24 // indirect github.com/tendermint/tm-db v0.6.7 // indirect github.com/zondax/hid v0.9.0 // indirect go.etcd.io/bbolt v1.3.6 // indirect diff --git a/go.sum b/go.sum index 12bf964..ec4f4bb 100644 --- a/go.sum +++ b/go.sum @@ -141,6 +141,8 @@ github.com/cosmos/ledger-go v0.9.2/go.mod h1:oZJ2hHAZROdlHiwTg4t7kP+GKIIkBT+o6c9 github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creachadair/taskgroup v0.3.2 h1:zlfutDS+5XG40AOxcHDSThxKzns8Tnr9jnr6VqkYlkM= +github.com/creasty/defaults v1.7.0 h1:eNdqZvc5B509z18lD8yc212CAqJNvfT1Jq6L8WowdBA= +github.com/creasty/defaults v1.7.0/go.mod h1:iGzKe6pbEHnpMPtfDXZEr0NVxWnPTjb1bbDy08fPzYM= github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0= github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -364,8 +366,6 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI= github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= -github.com/mcuadros/go-defaults v1.2.0 h1:FODb8WSf0uGaY8elWJAkoLL0Ri6AlZ1bFlenk56oZtc= -github.com/mcuadros/go-defaults v1.2.0/go.mod h1:WEZtHEVIGYVDqkKSWBdWKUVdRyKlMfulPaGDWIVeCWY= github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643/go.mod h1:43+3pMjjKimDBf5Kr4ZFNGbLql1zKkbImw+fZbw3geM= github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 h1:QRUSJEgZn2Snx0EmT/QLXibWjSUDjKWvXIT19NBVp94= github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0/go.mod h1:43+3pMjjKimDBf5Kr4ZFNGbLql1zKkbImw+fZbw3geM= @@ -888,11 +888,12 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U= gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/guregu/null.v4 v4.0.0 h1:1Wm3S1WEA2I26Kq+6vcW+w0gcDo44YKYD7YIEJNHDjg= +gopkg.in/guregu/null.v4 v4.0.0/go.mod h1:YoQhUrADuG3i9WqesrCmpNRwm1ypAgSHYqoOcTu/JrI= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= diff --git a/pkg/app.go b/pkg/app.go index e4fc0c9..baab71a 100644 --- a/pkg/app.go +++ b/pkg/app.go @@ -39,15 +39,15 @@ func NewApp( var grpc *grpcPkg.Grpc var github *githubPkg.Github - if config.TendermintConfig.Address != "" { + if config.TendermintConfig.Enabled.Bool { tendermintRPC = tendermint.NewRPC(config, logger) } - if config.GrpcConfig.Address != "" { + if config.GrpcConfig.Enabled.Bool { grpc = grpcPkg.NewGrpc(config, logger) } - if config.CosmovisorConfig.IsEnabled() { + if config.CosmovisorConfig.Enabled.Bool { cosmovisor = cosmovisorPkg.NewCosmovisor(config, logger) } diff --git a/pkg/config/config.go b/pkg/config/config.go index 5271dd9..a55a24a 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -6,20 +6,23 @@ import ( "os" "github.com/BurntSushi/toml" - "github.com/mcuadros/go-defaults" + "github.com/creasty/defaults" + "gopkg.in/guregu/null.v4" ) type LogConfig struct { - LogLevel string `toml:"level" default:"info"` - JSONOutput bool `toml:"json" default:"false"` + LogLevel string `toml:"level" default:"info"` + JSONOutput null.Bool `toml:"json" default:"false"` } type TendermintConfig struct { - Address string `toml:"address" default:""` + Enabled null.Bool `toml:"enabled" default:"true"` + Address string `toml:"address" default:"http://localhost:26657"` } type GrpcConfig struct { - Address string `toml:"address" default:""` + Enabled null.Bool `toml:"enabled" default:"true"` + Address string `toml:"address" default:"localhost:9090"` } type GithubConfig struct { @@ -28,13 +31,10 @@ type GithubConfig struct { } type CosmovisorConfig struct { - ChainBinaryName string `toml:"chain-binary-name"` - ChainFolder string `toml:"chain-folder"` - CosmovisorPath string `toml:"cosmovisor-path"` -} - -func (c *CosmovisorConfig) IsEnabled() bool { - return c.ChainBinaryName != "" && c.ChainFolder != "" && c.CosmovisorPath != "" + Enabled null.Bool `toml:"enabled" default:"true"` + ChainBinaryName string `toml:"chain-binary-name"` + ChainFolder string `toml:"chain-folder"` + CosmovisorPath string `toml:"cosmovisor-path"` } type Config struct { @@ -79,6 +79,8 @@ func GetConfig(path string) (*Config, error) { return nil, err } - defaults.SetDefaults(&configStruct) + if err := defaults.Set(&configStruct); err != nil { + return nil, err + } return &configStruct, nil } diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index 3a4dfcc..cca7476 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -16,7 +16,7 @@ func GetDefaultLogger() *zerolog.Logger { func GetLogger(config config.LogConfig) *zerolog.Logger { log := zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout}).With().Timestamp().Logger() - if config.JSONOutput { + if config.JSONOutput.Bool { log = zerolog.New(os.Stdout).With().Timestamp().Logger() }