diff options
author | 2020-01-03 17:06:37 +0800 | |
---|---|---|
committer | 2020-01-03 10:06:37 +0100 | |
commit | 99e7c3dee750f4b80a0724b22acbeef6bf12dd7a (patch) | |
tree | 289bebfc9bfa039e81880fcd0605f355b536d582 /test/metrics_test.go | |
parent | 908508a9bd5cf0b0e41fb63ca97d2f4d492e3505 (diff) | |
download | coredns-99e7c3dee750f4b80a0724b22acbeef6bf12dd7a.tar.gz coredns-99e7c3dee750f4b80a0724b22acbeef6bf12dd7a.tar.zst coredns-99e7c3dee750f4b80a0724b22acbeef6bf12dd7a.zip |
registry cache_miss logic (#3578)
Signed-off-by: zouyee <zounyee1989@gmail.com>
Diffstat (limited to 'test/metrics_test.go')
-rw-r--r-- | test/metrics_test.go | 37 |
1 files changed, 37 insertions, 0 deletions
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) + } +} |