Metrics collection should not break on missing leases file (#14)
This commit is contained in:
parent
7245dc2121
commit
8f3a65778f
@ -209,6 +209,11 @@ func (s *server) metrics(w http.ResponseWriter, r *http.Request) {
|
||||
eg.Go(func() error {
|
||||
f, err := os.Open(s.leasesPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
// ignore
|
||||
leases.Set(0)
|
||||
return nil
|
||||
}
|
||||
log.Warnln("could not open leases file:", err)
|
||||
return err
|
||||
}
|
||||
|
@ -120,6 +120,24 @@ func TestDnsmasqExporter(t *testing.T) {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
s.leasesPath = "testdata/dnsmasq.leases.does.not.exists"
|
||||
|
||||
t.Run("without leases file", func(t *testing.T) {
|
||||
metrics := fetchMetrics(t, s)
|
||||
want := map[string]string{
|
||||
"dnsmasq_leases": "0",
|
||||
"dnsmasq_cachesize": "666",
|
||||
"dnsmasq_hits": "4",
|
||||
"dnsmasq_misses": "1",
|
||||
}
|
||||
for key, val := range want {
|
||||
if got, want := metrics[key], val; got != want {
|
||||
t.Errorf("metric %q: got %q, want %q", key, got, want)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func fetchMetrics(t *testing.T, s *server) map[string]string {
|
||||
|
Loading…
x
Reference in New Issue
Block a user