diff options
author | 2020-03-25 21:33:04 +0800 | |
---|---|---|
committer | 2020-03-25 14:33:04 +0100 | |
commit | 1dba31ee7d7ea5d4d02f3f2f519f25e5c9a3c379 (patch) | |
tree | bea207cbd0e67ec288f1a09c969aa484dabef46c /plugin/reload/reload.go | |
parent | 1766568398e3120c85d44f5c6237a724248b652e (diff) | |
download | coredns-1dba31ee7d7ea5d4d02f3f2f519f25e5c9a3c379.tar.gz coredns-1dba31ee7d7ea5d4d02f3f2f519f25e5c9a3c379.tar.zst coredns-1dba31ee7d7ea5d4d02f3f2f519f25e5c9a3c379.zip |
export config file hash in a metric (#3768)
Signed-off-by: zounengren <zounengren@cmss.chinamobile.com>
Diffstat (limited to 'plugin/reload/reload.go')
-rw-r--r-- | plugin/reload/reload.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/plugin/reload/reload.go b/plugin/reload/reload.go index 817582c8c..0b58d2a8e 100644 --- a/plugin/reload/reload.go +++ b/plugin/reload/reload.go @@ -4,12 +4,14 @@ package reload import ( "bytes" "crypto/md5" + "encoding/hex" "encoding/json" "sync" "time" "github.com/caddyserver/caddy" "github.com/caddyserver/caddy/caddyfile" + "github.com/prometheus/client_golang/prometheus" ) const ( @@ -61,7 +63,6 @@ func hook(event caddy.EventName, info interface{}) error { if event != caddy.InstanceStartupEvent { return nil } - // if reload is removed from the Corefile, then the hook // is still registered but setup is never called again // so we need a flag to tell us not to reload @@ -96,12 +97,14 @@ func hook(event caddy.EventName, info interface{}) error { } s := md5.Sum(parsedCorefile) if s != md5sum { + reloadInfo.Delete(prometheus.Labels{"hash": "md5", "value": hex.EncodeToString(md5sum[:])}) // Let not try to restart with the same file, even though it is wrong. md5sum = s // now lets consider that plugin will not be reload, unless appear in next config file // change status of usage will be reset in setup if the plugin appears in config file r.setUsage(maybeUsed) _, err := instance.Restart(corefile) + reloadInfo.WithLabelValues("md5", hex.EncodeToString(md5sum[:])).Set(1) if err != nil { log.Errorf("Corefile changed but reload failed: %s", err) FailedCount.Add(1) |