diff options
Diffstat (limited to 'test/metrics_test.go')
-rw-r--r-- | test/metrics_test.go | 80 |
1 files changed, 9 insertions, 71 deletions
diff --git a/test/metrics_test.go b/test/metrics_test.go index 6f27ada89..da7e7b322 100644 --- a/test/metrics_test.go +++ b/test/metrics_test.go @@ -8,10 +8,9 @@ import ( "testing" "time" - "github.com/coredns/coredns/plugin/cache" "github.com/coredns/coredns/plugin/metrics" - mtest "github.com/coredns/coredns/plugin/metrics/test" "github.com/coredns/coredns/plugin/metrics/vars" + "github.com/coredns/coredns/plugin/test" "github.com/miekg/dns" ) @@ -56,8 +55,8 @@ func TestMetricsRefused(t *testing.T) { t.Fatalf("Could not send message: %s", err) } - data := mtest.Scrape(t, "http://"+metrics.ListenAddr+"/metrics") - got, labels := mtest.MetricValue(metricName, data) + data := test.Scrape("http://" + metrics.ListenAddr + "/metrics") + got, labels := test.MetricValue(metricName, data) if got != "1" { t.Errorf("Expected value %s for refused, but got %s", "1", got) @@ -70,67 +69,6 @@ func TestMetricsRefused(t *testing.T) { } } -// TODO(miek): disabled for now - fails in weird ways in travis. -func TestMetricsCache(t *testing.T) { - cacheSizeMetricName := "coredns_cache_size" - cacheHitMetricName := "coredns_cache_hits_total" - - corefile := `example.net:0 { - proxy . 8.8.8.8:53 - prometheus localhost:0 - cache -} -` - srv, err := CoreDNSServer(corefile) - if err != nil { - t.Fatalf("Could not get CoreDNS serving instance: %s", err) - } - defer srv.Stop() - - udp, _ := CoreDNSServerPorts(srv, 0) - - // send an initial query to set properly the cache size metric - m := new(dns.Msg) - m.SetQuestion("example.net.", dns.TypeA) - - if _, err = dns.Exchange(m, udp); err != nil { - t.Fatalf("Could not send message: %s", err) - } - - beginCacheSizeSuccess := mtest.ScrapeMetricAsInt(t, metrics.ListenAddr, cacheSizeMetricName, cache.Success, 0) - beginCacheHitSuccess := mtest.ScrapeMetricAsInt(t, metrics.ListenAddr, cacheHitMetricName, cache.Success, 0) - - m = new(dns.Msg) - m.SetQuestion("www.example.net.", dns.TypeA) - - if _, err = dns.Exchange(m, udp); err != nil { - t.Fatalf("Could not send message: %s", err) - } - - // Get the value for the cache size metric where the one of the labels values matches "success". - got := mtest.ScrapeMetricAsInt(t, metrics.ListenAddr, cacheSizeMetricName, cache.Success, 0) - - if got-beginCacheSizeSuccess != 1 { - t.Errorf("Expected value %d for %s, but got %d", 1, cacheSizeMetricName, got-beginCacheSizeSuccess) - } - - // 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) - } - // Third request for the same response to test hit counter for the second time - if _, err = dns.Exchange(m, udp); err != nil { - t.Fatalf("Could not send message: %s", err) - } - - // Get the value for the cache hit counter where the one of the labels values matches "success". - got = mtest.ScrapeMetricAsInt(t, metrics.ListenAddr, cacheHitMetricName, cache.Success, 0) - - if got-beginCacheHitSuccess != 2 { - t.Errorf("Expected value %d for %s, but got %d", 2, cacheHitMetricName, got-beginCacheHitSuccess) - } -} - func TestMetricsAuto(t *testing.T) { tmpdir, err := ioutil.TempDir(os.TempDir(), "coredns") if err != nil { @@ -172,9 +110,9 @@ func TestMetricsAuto(t *testing.T) { metricName := "coredns_dns_request_count_total" //{zone, proto, family} - data := mtest.Scrape(t, "http://"+metrics.ListenAddr+"/metrics") + data := test.Scrape("http://" + metrics.ListenAddr + "/metrics") // Get the value for the metrics where the one of the labels values matches "example.org." - got, _ := mtest.MetricValueLabel(metricName, "example.org.", data) + got, _ := test.MetricValueLabel(metricName, "example.org.", data) if got != "1" { t.Errorf("Expected value %s for %s, but got %s", "1", metricName, got) @@ -187,8 +125,8 @@ func TestMetricsAuto(t *testing.T) { t.Fatalf("Could not send message: %s", err) } - data = mtest.Scrape(t, "http://"+metrics.ListenAddr+"/metrics") - got, _ = mtest.MetricValueLabel(metricName, "example.org.", data) + data = test.Scrape("http://" + metrics.ListenAddr + "/metrics") + got, _ = test.MetricValueLabel(metricName, "example.org.", data) if got != "1" { t.Errorf("Expected value %s for %s, but got %s", "1", metricName, got) @@ -230,7 +168,7 @@ google.com:0 { t.Fatalf("Could not send message: %s", err) } - beginCacheSize := mtest.ScrapeMetricAsInt(t, addrMetrics, cacheSizeMetricName, "", 0) + beginCacheSize := test.ScrapeMetricAsInt(addrMetrics, cacheSizeMetricName, "", 0) // send an query, different from initial to ensure we have another add to the cache m = new(dns.Msg) @@ -240,7 +178,7 @@ google.com:0 { t.Fatalf("Could not send message: %s", err) } - endCacheSize := mtest.ScrapeMetricAsInt(t, addrMetrics, cacheSizeMetricName, "", 0) + endCacheSize := test.ScrapeMetricAsInt(addrMetrics, cacheSizeMetricName, "", 0) if err != nil { t.Errorf("Unexpected metric data retrieved for %s : %s", cacheSizeMetricName, err) } |