feat(config): add metrics bind config to policy file with flag hack

Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
Xe Iaso
2026-04-21 14:05:05 -04:00
parent 3a6e368179
commit 8af9845117
35 changed files with 246 additions and 8 deletions
+24
View File
@@ -2,6 +2,7 @@ package config
import (
"errors"
"flag"
"fmt"
"io"
"io/fs"
@@ -334,6 +335,7 @@ type fileConfig struct {
DNSBL bool `json:"dnsbl"`
DNSTTL DnsTTL `json:"dns_ttl"`
Logging *Logging `json:"logging"`
Metrics *Metrics `json:"metrics,omitempty"`
}
func (c *fileConfig) Valid() error {
@@ -375,6 +377,12 @@ func (c *fileConfig) Valid() error {
}
}
if c.Metrics != nil {
if err := c.Metrics.Valid(); err != nil {
errs = append(errs, err)
}
}
if len(errs) != 0 {
return fmt.Errorf("config is not valid:\n%w", errors.Join(errs...))
}
@@ -382,6 +390,16 @@ func (c *fileConfig) Valid() error {
return nil
}
func flagLookup(name string) string {
fl := flag.CommandLine.Lookup(name)
if fl == nil {
return ""
}
return fl.Value.String()
}
func Load(fin io.Reader, fname string) (*Config, error) {
c := &fileConfig{
StatusCodes: StatusCodes{
@@ -396,6 +414,10 @@ func Load(fin io.Reader, fname string) (*Config, error) {
Backend: "memory",
},
Logging: (Logging{}).Default(),
Metrics: &Metrics{
Bind: flagLookup("metrics-bind"),
Network: flagLookup("metrics-bind-network"),
},
}
if err := yaml.NewYAMLToJSONDecoder(fin).Decode(&c); err != nil {
@@ -417,6 +439,7 @@ func Load(fin io.Reader, fname string) (*Config, error) {
StatusCodes: c.StatusCodes,
Store: c.Store,
Logging: c.Logging,
Metrics: c.Metrics,
}
if c.OpenGraph.TimeToLive != "" {
@@ -508,6 +531,7 @@ type Config struct {
Logging *Logging
DNSBL bool
DNSTTL DnsTTL
Metrics *Metrics
}
func (c Config) Valid() error {