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 b5c6655196
.
* 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>
This commit is contained in:
parent
29cae57932
commit
6953ab2b4f
8 changed files with 85 additions and 20 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue