diff --git a/CHANGELOG.md b/CHANGELOG.md index 771cf35..c70dab3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.9.7: Better validation + +This release adds better validation for the metrics server. + ## 0.9.6: Fixed listen default This release fixes a regression where the default `listen` value would be `0.0.0.0:8080` instead of `0.0.0.0:9100`. diff --git a/server_config.go b/server_config.go index 7091872..8fe8a5a 100644 --- a/server_config.go +++ b/server_config.go @@ -1,6 +1,8 @@ package metrics import ( + "fmt" + "github.com/containerssh/http" ) @@ -10,3 +12,14 @@ type Config struct { Enable bool `yaml:"enable" json:"enable" comment:"Enable metrics server." default:"false"` Path string `yaml:"path" json:"path" comment:"Path to run the Metrics endpoint on." default:"/metrics"` } + +// Validate validates the configuration. +func (c Config) Validate() error { + if !c.Enable { + return nil + } + if c.Path == "" { + return fmt.Errorf("metrics path cannot be empty") + } + return c.ServerConfiguration.Validate() +}