Skip to content

Commit

Permalink
monitor config: make threshold optional in the configuration
Browse files Browse the repository at this point in the history
takes default when not set.
  • Loading branch information
hsanjuan committed May 16, 2019
1 parent 2f6a839 commit 6caf78a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions monitor/pubsubmon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type Config struct {
}

type jsonConfig struct {
CheckInterval string `json:"check_interval"`
FailureThreshold float64 `json:"failure_threshold"`
CheckInterval string `json:"check_interval"`
FailureThreshold *float64 `json:"failure_threshold"`
}

// ConfigKey provides a human-friendly identifier for this type of Config.
Expand Down Expand Up @@ -91,7 +91,9 @@ func (cfg *Config) LoadJSON(raw []byte) error {
func (cfg *Config) applyJSONConfig(jcfg *jsonConfig) error {
interval, _ := time.ParseDuration(jcfg.CheckInterval)
cfg.CheckInterval = interval
cfg.FailureThreshold = jcfg.FailureThreshold
if jcfg.FailureThreshold != nil {
cfg.FailureThreshold = *jcfg.FailureThreshold
}

return cfg.Validate()
}
Expand All @@ -106,6 +108,6 @@ func (cfg *Config) ToJSON() ([]byte, error) {
func (cfg *Config) toJSONConfig() *jsonConfig {
return &jsonConfig{
CheckInterval: cfg.CheckInterval.String(),
FailureThreshold: cfg.FailureThreshold,
FailureThreshold: &cfg.FailureThreshold,
}
}

0 comments on commit 6caf78a

Please sign in to comment.