diff --git a/plugin/cache/handler.go b/plugin/cache/handler.go index 905a98ef4..2a64f11e4 100644 --- a/plugin/cache/handler.go +++ b/plugin/cache/handler.go @@ -114,6 +114,7 @@ func (c *Cache) getIgnoreTTL(now time.Time, state request.Request, server string } return i.(*item) } + cacheMisses.WithLabelValues(server).Inc() return nil } diff --git a/test/metrics_test.go b/test/metrics_test.go index b84e906ce..cad1a0a87 100644 --- a/test/metrics_test.go +++ b/test/metrics_test.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" "testing" "time" @@ -223,3 +224,39 @@ example.com:0 { t.Errorf("Expected value %s for %s, but got %s", "", metricName, got) } } + +func TestMetricsAvailable(t *testing.T) { + procMetric := "coredns_build_info" + procCache := "coredns_cache_size" + procCacheMiss := "coredns_cache_misses_total" + procForward := "coredns_dns_request_duration_seconds" + corefileWithMetrics := ` + .:0 { + prometheus localhost:0 + cache + forward . 8.8.8.8 { + force_tcp + } + }` + inst, _, tcp, err := CoreDNSServerAndPorts(corefileWithMetrics) + defer inst.Stop() + if err != nil { + if strings.Contains(err.Error(), inUse) { + return + } + t.Errorf("Could not get service instance: %s", err) + } + // send a query and check we can scrap corresponding metrics + cl := dns.Client{Net: "tcp"} + m := new(dns.Msg) + m.SetQuestion("www.example.org.", dns.TypeA) + + if _, _, err := cl.Exchange(m, tcp); err != nil { + t.Fatalf("Could not send message: %s", err) + } + + // we should have metrics from forward, cache, and metrics itself + if err := collectMetricsInfo(metrics.ListenAddr, procMetric, procCache, procCacheMiss, procForward); err != nil { + t.Errorf("Could not scrap one of expected stats : %s", err) + } +}