Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
1dba31ee
Commit
1dba31ee
authored
Mar 25, 2020
by
Zou Nengren
Committed by
GitHub
Mar 25, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
export config file hash in a metric (#3768)
Signed-off-by:
zounengren
<
zounengren@cmss.chinamobile.com
>
parent
17665683
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
3 deletions
+19
-3
plugin/reload/README.md
plugin/reload/README.md
+3
-0
plugin/reload/metrics.go
plugin/reload/metrics.go
+7
-0
plugin/reload/reload.go
plugin/reload/reload.go
+4
-1
plugin/reload/setup.go
plugin/reload/setup.go
+5
-2
No files found.
plugin/reload/README.md
View file @
1dba31ee
...
@@ -99,6 +99,9 @@ CoreDNS v1.7.0 and later does parse the Corefile and supports detecting changes
...
@@ -99,6 +99,9 @@ CoreDNS v1.7.0 and later does parse the Corefile and supports detecting changes
If monitoring is enabled (via the
*prometheus*
plugin) then the following metric is exported:
If monitoring is enabled (via the
*prometheus*
plugin) then the following metric is exported:
*
`coredns_reload_failed_count_total{}`
- counts the number of failed reload attempts.
*
`coredns_reload_failed_count_total{}`
- counts the number of failed reload attempts.
*
`coredns_reload_version_info{hash, value}`
- record the hash value during reload.
Currently the type of
`hash`
is "md5", the
`value`
is the returned hash value.
## Also See
## Also See
...
...
plugin/reload/metrics.go
View file @
1dba31ee
...
@@ -14,4 +14,11 @@ var (
...
@@ -14,4 +14,11 @@ var (
Name
:
"failed_count_total"
,
Name
:
"failed_count_total"
,
Help
:
"Counter of the number of failed reload attempts."
,
Help
:
"Counter of the number of failed reload attempts."
,
})
})
reloadInfo
=
prometheus
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Namespace
:
plugin
.
Namespace
,
Subsystem
:
"reload"
,
Name
:
"version_info"
,
Help
:
"A metric with a constant '1' value labeled by hash, and value which type of hash generated."
,
},
[]
string
{
"hash"
,
"value"
})
)
)
plugin/reload/reload.go
View file @
1dba31ee
...
@@ -4,12 +4,14 @@ package reload
...
@@ -4,12 +4,14 @@ package reload
import
(
import
(
"bytes"
"bytes"
"crypto/md5"
"crypto/md5"
"encoding/hex"
"encoding/json"
"encoding/json"
"sync"
"sync"
"time"
"time"
"github.com/caddyserver/caddy"
"github.com/caddyserver/caddy"
"github.com/caddyserver/caddy/caddyfile"
"github.com/caddyserver/caddy/caddyfile"
"github.com/prometheus/client_golang/prometheus"
)
)
const
(
const
(
...
@@ -61,7 +63,6 @@ func hook(event caddy.EventName, info interface{}) error {
...
@@ -61,7 +63,6 @@ func hook(event caddy.EventName, info interface{}) error {
if
event
!=
caddy
.
InstanceStartupEvent
{
if
event
!=
caddy
.
InstanceStartupEvent
{
return
nil
return
nil
}
}
// if reload is removed from the Corefile, then the hook
// if reload is removed from the Corefile, then the hook
// is still registered but setup is never called again
// is still registered but setup is never called again
// so we need a flag to tell us not to reload
// so we need a flag to tell us not to reload
...
@@ -96,12 +97,14 @@ func hook(event caddy.EventName, info interface{}) error {
...
@@ -96,12 +97,14 @@ func hook(event caddy.EventName, info interface{}) error {
}
}
s
:=
md5
.
Sum
(
parsedCorefile
)
s
:=
md5
.
Sum
(
parsedCorefile
)
if
s
!=
md5sum
{
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.
// Let not try to restart with the same file, even though it is wrong.
md5sum
=
s
md5sum
=
s
// now lets consider that plugin will not be reload, unless appear in next config file
// 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
// change status of usage will be reset in setup if the plugin appears in config file
r
.
setUsage
(
maybeUsed
)
r
.
setUsage
(
maybeUsed
)
_
,
err
:=
instance
.
Restart
(
corefile
)
_
,
err
:=
instance
.
Restart
(
corefile
)
reloadInfo
.
WithLabelValues
(
"md5"
,
hex
.
EncodeToString
(
md5sum
[
:
]))
.
Set
(
1
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Errorf
(
"Corefile changed but reload failed: %s"
,
err
)
log
.
Errorf
(
"Corefile changed but reload failed: %s"
,
err
)
FailedCount
.
Add
(
1
)
FailedCount
.
Add
(
1
)
...
...
plugin/reload/setup.go
View file @
1dba31ee
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"time"
"time"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
clog
"github.com/coredns/coredns/plugin/pkg/log"
clog
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/caddyserver/caddy"
"github.com/caddyserver/caddy"
...
@@ -67,11 +68,13 @@ func setup(c *caddy.Controller) error {
...
@@ -67,11 +68,13 @@ func setup(c *caddy.Controller) error {
// prepare info for next onInstanceStartup event
// prepare info for next onInstanceStartup event
r
.
setInterval
(
i
)
r
.
setInterval
(
i
)
r
.
setUsage
(
used
)
r
.
setUsage
(
used
)
once
.
Do
(
func
()
{
once
.
Do
(
func
()
{
caddy
.
RegisterEventHook
(
"reload"
,
hook
)
caddy
.
RegisterEventHook
(
"reload"
,
hook
)
c
.
OnRestart
(
func
()
error
{
metrics
.
MustRegister
(
c
,
reloadInfo
)
return
nil
})
})
})
// re-register on finalShutDown as the instance most-likely will be changed
// re-register on finalShutDown as the instance most-likely will be changed
shutOnce
.
Do
(
func
()
{
shutOnce
.
Do
(
func
()
{
c
.
OnFinalShutdown
(
func
()
error
{
c
.
OnFinalShutdown
(
func
()
error
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment