Metrics: Add direct listen (#4409)

This commit is contained in:
风扇滑翔翼 2025-02-18 19:32:48 +08:00 committed by GitHub
parent c5de08bea6
commit 4b01eb4398
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 49 additions and 13 deletions

View file

@ -6,15 +6,21 @@ import (
)
type MetricsConfig struct {
Tag string `json:"tag"`
Tag string `json:"tag"`
Listen string `json:"listen"`
}
func (c *MetricsConfig) Build() (*metrics.Config, error) {
if c.Listen == "" && c.Tag == "" {
return nil, errors.New("Metrics must have a tag or listen address.")
}
// If the tag is empty but have "listen" set a default "Metrics" for compatibility.
if c.Tag == "" {
return nil, errors.New("metrics tag can't be empty.")
c.Tag = "Metrics"
}
return &metrics.Config{
Tag: c.Tag,
Tag: c.Tag,
Listen: c.Listen,
}, nil
}