mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
metrics: config validate
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
766272ff8c
commit
ec9ca1c7dc
1 changed files with 18 additions and 0 deletions
|
|
@ -16,6 +16,10 @@
|
||||||
|
|
||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
// Config contains the configuration for the metric collection.
|
// Config contains the configuration for the metric collection.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Enabled bool `toml:",omitempty"`
|
Enabled bool `toml:",omitempty"`
|
||||||
|
|
@ -35,6 +39,20 @@ type Config struct {
|
||||||
InfluxDBOrganization string `toml:",omitempty"`
|
InfluxDBOrganization string `toml:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Config) Validate() error {
|
||||||
|
if c.EnableInfluxDB || c.EnableInfluxDBV2 {
|
||||||
|
v1FlagIsSet := c.InfluxDBUsername != "" || c.InfluxDBPassword != ""
|
||||||
|
v2FlagIsSet := c.InfluxDBToken != "" || c.InfluxDBOrganization != "" || c.InfluxDBBucket != ""
|
||||||
|
|
||||||
|
if c.EnableInfluxDB && v2FlagIsSet {
|
||||||
|
return errors.New("Flags --influxdb.metrics.organization, --influxdb.metrics.token, --influxdb.metrics.bucket are only available for influxdb-v2")
|
||||||
|
} else if c.EnableInfluxDBV2 && v1FlagIsSet {
|
||||||
|
return errors.New("Flags --influxdb.metrics.username, --influxdb.metrics.password are only available for influxdb-v1")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// DefaultConfig is the default config for metrics used in go-ethereum.
|
// DefaultConfig is the default config for metrics used in go-ethereum.
|
||||||
var DefaultConfig = Config{
|
var DefaultConfig = Config{
|
||||||
Enabled: false,
|
Enabled: false,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue