aboutsummaryrefslogtreecommitdiff
path: root/test/metrics_test.go
diff options
context:
space:
mode:
authorGravatar Ben Kochie <superq@gmail.com> 2016-10-31 19:50:50 +0100
committerGravatar Miek Gieben <miek@miek.nl> 2016-10-31 18:50:50 +0000
commit775d26c5e2c09e969dbf4141d82cd7ab6565e6aa (patch)
treea6afe14dbcf27da28d9c43d6817055c6db3b49f5 /test/metrics_test.go
parent27d893cf33b81e1a419ec58d0512bd2ecb01b8a2 (diff)
downloadcoredns-775d26c5e2c09e969dbf4141d82cd7ab6565e6aa.tar.gz
coredns-775d26c5e2c09e969dbf4141d82cd7ab6565e6aa.tar.zst
coredns-775d26c5e2c09e969dbf4141d82cd7ab6565e6aa.zip
Add metrics for cache hits/misses (#375)
* Add metrics for cache hits/misses Add counters for cache middleware hits and misses. * Add test for cache middleware hit/miss counters. * Fix cache hit metric incrementing. * Add cache hit/miss metrics to dnssec middleware. * Update README metric documentation.
Diffstat (limited to 'test/metrics_test.go')
-rw-r--r--test/metrics_test.go22
1 files changed, 18 insertions, 4 deletions
diff --git a/test/metrics_test.go b/test/metrics_test.go
index ee905e155..67e3a5d13 100644
--- a/test/metrics_test.go
+++ b/test/metrics_test.go
@@ -73,7 +73,8 @@ func TestMetricsRefused(t *testing.T) {
}
func TestMetricsCache(t *testing.T) {
- metricName := "coredns_cache_size"
+ cacheSizeMetricName := "coredns_cache_size"
+ cacheHitMetricName := "coredns_cache_hits_total"
corefile := `example.net:0 {
proxy . 8.8.8.8:53
@@ -97,11 +98,24 @@ func TestMetricsCache(t *testing.T) {
}
data := mtest.Scrape(t, "http://"+metrics.ListenAddr+"/metrics")
- // Get the value for the metrics where the one of the labels values matches "success".
- got, _ := mtest.MetricValueLabel(metricName, cache.Success, data)
+ // Get the value for the cache size metric where the one of the labels values matches "success".
+ got, _ := mtest.MetricValueLabel(cacheSizeMetricName, cache.Success, data)
if got != "1" {
- t.Errorf("Expected value %s for %s, but got %s", "1", metricName, got)
+ t.Errorf("Expected value %s for %s, but got %s", "1", cacheSizeMetricName, got)
+ }
+
+ // Second request for the same response to test hit counter.
+ if _, err = dns.Exchange(m, udp); err != nil {
+ t.Fatalf("Could not send message: %s", err)
+ }
+
+ data = mtest.Scrape(t, "http://"+metrics.ListenAddr+"/metrics")
+ // Get the value for the cache hit counter where the one of the labels values matches "success".
+ got, _ = mtest.MetricValueLabel(cacheHitMetricName, cache.Success, data)
+
+ if got != "1" {
+ t.Errorf("Expected value %s for %s, but got %s", "1", cacheHitMetricName, got)
}
}