1414 DNS DNSConfig `toml:"dns"`
1515 // Individual transports used by the DNS server.
1616 Transport TransportConfig `toml:"transport"`
17+ // Prometheus metric configuration.
18+ Metrics * MetricsConfig `toml:"metrics"`
1719 }
1820
1921 // The DNSConfig type contains fields for configuring specific DNS behavior.
@@ -85,6 +87,12 @@ type (
8587 // The path to the key file.
8688 Key string `toml:"key"`
8789 }
90+
91+ // The MetricsConfig type contains fields for configuring the Prometheus metrics endpoint.
92+ MetricsConfig struct {
93+ // The bind address of the metrics HTTP listener.
94+ Bind string `toml:"bind"`
95+ }
8896)
8997
9098// DefaultConfig returns a Config type containing default working values for the DNS server. By default, it will
@@ -106,6 +114,9 @@ func DefaultConfig() Config {
106114 Bind : "0.0.0.0:53" ,
107115 },
108116 },
117+ Metrics : & MetricsConfig {
118+ Bind : "0.0.0.0:9100" ,
119+ },
109120 }
110121}
111122
@@ -124,10 +135,15 @@ func (c *Config) Validate() error {
124135 return errors .Join (
125136 c .DNS .validate (),
126137 c .Transport .validate (),
138+ c .Metrics .validate (),
127139 )
128140}
129141
130142func (c * DNSConfig ) validate () error {
143+ if c == nil {
144+ return errors .New ("no DNS configuration specified" )
145+ }
146+
131147 if len (c .Upstreams ) == 0 {
132148 return errors .New ("no dns upstreams specified" )
133149 }
@@ -144,6 +160,10 @@ func (c *DNSConfig) validate() error {
144160}
145161
146162func (t * TransportConfig ) validate () error {
163+ if t == nil {
164+ return errors .New ("no transport configuration specified" )
165+ }
166+
147167 // We never want a server that does nothing at all.
148168 if t .UDP == nil && t .TCP == nil && t .DOT == nil && t .DOH == nil {
149169 return errors .New ("at least one transport must be specified" )
@@ -183,3 +203,15 @@ func (t *TransportConfig) validate() error {
183203
184204 return nil
185205}
206+
207+ func (c * MetricsConfig ) validate () error {
208+ if c == nil {
209+ return nil
210+ }
211+
212+ if c .Bind == "" {
213+ return errors .New ("metrics bind address must be specified" )
214+ }
215+
216+ return nil
217+ }
0 commit comments