mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
registry cache_miss logic (#3578)
Signed-off-by: zouyee <zounyee1989@gmail.com>
This commit is contained in:
1
plugin/cache/handler.go
vendored
1
plugin/cache/handler.go
vendored
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user