aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2021-11-12 16:07:05 +0000
committerGravatar GitHub <noreply@github.com> 2021-11-12 16:07:05 +0000
commit6953ab2b4f23f916a08b68ba51b9a26e41e9a748 (patch)
tree4cd98dfc2314f4a56926a5ab5b0627e1eb040e9f /test
parent29cae579325e5968343d665f02f8d961624f9481 (diff)
downloadcoredns-6953ab2b4f23f916a08b68ba51b9a26e41e9a748.tar.gz
coredns-6953ab2b4f23f916a08b68ba51b9a26e41e9a748.tar.zst
coredns-6953ab2b4f23f916a08b68ba51b9a26e41e9a748.zip
Metrics: expand coredns_dns_responses_total with plugin label (#4914)
* Metrics: expand coredns_dns_responses_total with plugin label This adds (somewhat hacky?) code to add a plugin label to the coredns_dns_responses_total metric. It's completely obvlious to the plugin as we just check who called the *recorder.WriteMsg method. We use runtime.Caller( 1 2 3) to get multiple levels of callers, this should be deep enough, but it depends on the dns.ResponseWriter wrapping that's occuring. README.md of metrics updates and test added in test/metrics_test.go to check for the label being set. I went through the plugin to see what metrics could be removed, but actually didn't find any, the plugin push out metrics that make sense. Due to the path fiddling to figure out the plugin name I doubt this works (out-of-the-box) for external plugins, but I haven't tested that. Signed-off-by: Miek Gieben <miek@miek.nl> * better comment Signed-off-by: Miek Gieben <miek@miek.nl> * Metrics: expand coredns_dns_responses_total with plugin label This adds (somewhat hacky?) code to add a plugin label to the coredns_dns_responses_total metric. It's completely obvlious to the plugin as we just check who called the *recorder.WriteMsg method. We use runtime.Caller( 1 2 3) to get multiple levels of callers, this should be deep enough, but it depends on the dns.ResponseWriter wrapping that's occuring. README.md of metrics updates and test added in test/metrics_test.go to check for the label being set. I went through the plugin to see what metrics could be removed, but actually didn't find any, the plugin push out metrics that make sense. Due to the path fiddling to figure out the plugin name I doubt this works (out-of-the-box) for external plugins, but I haven't tested that. Signed-off-by: Miek Gieben <miek@miek.nl> * Update core/dnsserver/server.go Co-authored-by: dilyevsky <ilyevsky@gmail.com> * Use [3]string Signed-off-by: Miek Gieben <miek@miek.nl> * imports Signed-off-by: Miek Gieben <miek@miek.nl> * remove dnstest changes Signed-off-by: Miek Gieben <miek@miek.nl> * revert Signed-off-by: Miek Gieben <miek@miek.nl> * Add some sleeps to make it less flaky Signed-off-by: Miek Gieben <miek@miek.nl> * Revert "Add some sleeps to make it less flaky" This reverts commit b5c6655196e3ad570555f086832ceb1f48f6f2d5. * Remove forward when not needed Signed-off-by: Miek Gieben <miek@miek.nl> * remove newline Signed-off-by: Miek Gieben <miek@miek.nl> Co-authored-by: dilyevsky <ilyevsky@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/metrics_test.go25
1 files changed, 13 insertions, 12 deletions
diff --git a/test/metrics_test.go b/test/metrics_test.go
index 66c21ba0c..4de9dad3c 100644
--- a/test/metrics_test.go
+++ b/test/metrics_test.go
@@ -14,6 +14,9 @@ import (
"github.com/miekg/dns"
)
+// Because we don't properly shutdown the metrics servers we are re-using the metrics between tests, not a superbad issue
+// but depending on the ordering of the tests this trips up stuff.
+
// Start test server that has metrics enabled. Then tear it down again.
func TestMetricsServer(t *testing.T) {
corefile := `
@@ -22,7 +25,7 @@ func TestMetricsServer(t *testing.T) {
prometheus localhost:0
}
example.com:0 {
- forward . 8.8.4.4:53
+ log
prometheus localhost:0
}`
@@ -36,7 +39,7 @@ func TestMetricsServer(t *testing.T) {
func TestMetricsRefused(t *testing.T) {
metricName := "coredns_dns_responses_total"
corefile := `example.org:0 {
- forward . 8.8.8.8:53
+ whoami
prometheus localhost:0
}`
@@ -112,8 +115,8 @@ func TestMetricsAuto(t *testing.T) {
// Get the value for the metrics where the one of the labels values matches "example.org."
got, _ := test.MetricValueLabel(metricName, "example.org.", data)
- if got != "1" {
- t.Errorf("Expected value %s for %s, but got %s", "1", metricName, got)
+ if got == "0" {
+ t.Errorf("Expected value %s for %s, but got %s", "> 1", metricName, got)
}
// Remove db.example.org again. And see if the metric stops increasing.
@@ -126,8 +129,8 @@ func TestMetricsAuto(t *testing.T) {
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)
+ if got == "0" {
+ t.Errorf("Expected value %s for %s, but got %s", "> 1", metricName, got)
}
}
@@ -145,9 +148,7 @@ func TestMetricsSeveralBlocs(t *testing.T) {
}
google.com:0 {
prometheus ` + addrMetrics + `
- forward . 8.8.8.8:53 {
- force_tcp
- }
+ whoami
cache
}`
@@ -190,7 +191,7 @@ func TestMetricsPluginEnabled(t *testing.T) {
prometheus localhost:0
}
example.com:0 {
- forward . 8.8.4.4:53
+ whoami
prometheus localhost:0
}`
@@ -211,8 +212,8 @@ func TestMetricsPluginEnabled(t *testing.T) {
t.Errorf("Expected value %s for %s, but got %s", "1", metricName, got)
}
- // Get the value for the metrics where the one of the labels values matches "whoami".
- got, _ = test.MetricValueLabel(metricName, "whoami", data)
+ // Get the value for the metrics where the one of the labels values matches "erratic".
+ got, _ = test.MetricValueLabel(metricName, "erratic", data) // none of these tests use 'erratic'
if got != "" {
t.Errorf("Expected value %s for %s, but got %s", "", metricName, got)