mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-04-23 00:26:42 +00:00
d5ccf9c670
* feat(config): add metrics bind config to policy file with flag hack Signed-off-by: Xe Iaso <me@xeiaso.net> * feat(internal): move SetupListener from main Signed-off-by: Xe Iaso <me@xeiaso.net> * fix(main): use internal.SetupListener Signed-off-by: Xe Iaso <me@xeiaso.net> * fix(config): add metrics socket mode Signed-off-by: Xe Iaso <me@xeiaso.net> * feat: move metrics server to a dedicated package Signed-off-by: Xe Iaso <me@xeiaso.net> * doc: add metrics server configuration docs Signed-off-by: Xe Iaso <me@xeiaso.net> * doc(default-config): add vague references to metrics server Signed-off-by: Xe Iaso <me@xeiaso.net> * chore: spelling Signed-off-by: Xe Iaso <me@xeiaso.net> --------- Signed-off-by: Xe Iaso <me@xeiaso.net>
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package config
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strconv"
|
|
)
|
|
|
|
var (
|
|
ErrInvalidMetricsConfig = errors.New("config: invalid metrics configuration")
|
|
ErrNoMetricsBind = errors.New("config.Metrics: must define bind")
|
|
ErrNoMetricsNetwork = errors.New("config.Metrics: must define network")
|
|
ErrNoMetricsSocketMode = errors.New("config.Metrics: must define socket mode when using unix sockets")
|
|
ErrInvalidMetricsSocketMode = errors.New("config.Metrics: invalid unix socket mode")
|
|
ErrInvalidMetricsNetwork = errors.New("config.Metrics: invalid metrics network")
|
|
)
|
|
|
|
type Metrics struct {
|
|
Bind string `json:"bind" yaml:"bind"`
|
|
Network string `json:"network" yaml:"network"`
|
|
SocketMode string `json:"socketMode" yaml:"socketMode"`
|
|
}
|
|
|
|
func (m *Metrics) Valid() error {
|
|
var errs []error
|
|
|
|
if m.Bind == "" {
|
|
errs = append(errs, ErrNoMetricsBind)
|
|
}
|
|
|
|
if m.Network == "" {
|
|
errs = append(errs, ErrNoMetricsNetwork)
|
|
}
|
|
|
|
switch m.Network {
|
|
case "tcp", "tcp4", "tcp6": // https://pkg.go.dev/net#Listen
|
|
case "unix":
|
|
if m.SocketMode == "" {
|
|
errs = append(errs, ErrNoMetricsSocketMode)
|
|
}
|
|
|
|
if _, err := strconv.ParseUint(m.SocketMode, 8, 0); err != nil {
|
|
errs = append(errs, fmt.Errorf("%w: %w", ErrInvalidMetricsSocketMode, err))
|
|
}
|
|
default:
|
|
errs = append(errs, ErrInvalidMetricsNetwork)
|
|
}
|
|
|
|
if len(errs) != 0 {
|
|
return errors.Join(ErrInvalidMetricsConfig, errors.Join(errs...))
|
|
}
|
|
|
|
return nil
|
|
}
|