diff options
author | 2019-03-23 10:43:15 +0100 | |
---|---|---|
committer | 2019-03-23 09:43:15 +0000 | |
commit | 0e137b23f152c70590e82f0b5985b2faf104c8e0 (patch) | |
tree | f2c492c823b7575957b0e51946fb22b9c935235d /test | |
parent | a3dd8cdf8de1a9aacc36fe8cf0f268e69bd8a45d (diff) | |
download | coredns-0e137b23f152c70590e82f0b5985b2faf104c8e0.tar.gz coredns-0e137b23f152c70590e82f0b5985b2faf104c8e0.tar.zst coredns-0e137b23f152c70590e82f0b5985b2faf104c8e0.zip |
plugin/metrics: Add a metric to monitor which plugin(s) is(are) enabled (#2700)
* Add a GaugeVec for enabled plugins monitoring.
Signed-off-by: Jiacheng Xu <xjcmaxwellcjx@gmail.com>
* Add server label and zone label for enable_plugin matric.
* Add a test for PluginEnabled metric
* Add description for enabledPlugin metric.
* Change the description for the enabledPlugin metric.
* Reset the enabledPlugin metric when restart the server.
* Add the bug session for enabledPlugin metric.
* Remove the resolveTCPAddr
Diffstat (limited to 'test')
-rw-r--r-- | test/metrics_test.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/metrics_test.go b/test/metrics_test.go index c37126a74..4aaf89036 100644 --- a/test/metrics_test.go +++ b/test/metrics_test.go @@ -186,3 +186,39 @@ google.com:0 { t.Errorf("Expected metric data retrieved for %s, expected %d, got %d", cacheSizeMetricName, 1, endCacheSize-beginCacheSize) } } + +func TestMetricsPluginEnabled(t *testing.T) { + corefile := `example.org:0 { + chaos CoreDNS-001 miek@miek.nl + prometheus localhost:0 +} + +example.com:0 { + forward . 8.8.4.4:53 + prometheus localhost:0 +} +` + srv, err := CoreDNSServer(corefile) + if err != nil { + t.Fatalf("Could not get CoreDNS serving instance: %s", err) + } + defer srv.Stop() + + metricName := "coredns_plugin_enabled" //{server, zone, name} + + data := test.Scrape("http://" + metrics.ListenAddr + "/metrics") + + // Get the value for the metrics where the one of the labels values matches "chaos". + got, _ := test.MetricValueLabel(metricName, "chaos", data) + + if got != "1" { + 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) + + if got != "" { + t.Errorf("Expected value %s for %s, but got %s", "", metricName, got) + } +} |