aboutsummaryrefslogtreecommitdiff
path: root/plugin/reload/setup.go
diff options
context:
space:
mode:
authorGravatar Francois Tur <ftur@infoblox.com> 2018-02-02 13:15:56 -0500
committerGravatar John Belamaric <jbelamaric@infoblox.com> 2018-02-02 13:15:56 -0500
commit244002477231ac5f1b92f415bee5a53d04fc33cc (patch)
tree42f58f33d6bc0e1ddece37a1f9c4e2775e005d41 /plugin/reload/setup.go
parent3fb07161b74b05fbea6e8f19cd4071fda8402480 (diff)
downloadcoredns-244002477231ac5f1b92f415bee5a53d04fc33cc.tar.gz
coredns-244002477231ac5f1b92f415bee5a53d04fc33cc.tar.zst
coredns-244002477231ac5f1b92f415bee5a53d04fc33cc.zip
Plugin/RELOAD - Tune usage of var global, add limit to options (#1457)
* tune usage of var global, add limit to options * update readme for minimal values * useless change to quick-off codecov * fix msgs for min values and tune the flag for end of reload usage, with a 'maybe' option * adding UT for min values, adding MD5 of corefile on the log
Diffstat (limited to 'plugin/reload/setup.go')
-rw-r--r--plugin/reload/setup.go26
1 files changed, 21 insertions, 5 deletions
diff --git a/plugin/reload/setup.go b/plugin/reload/setup.go
index af6fe1334..480bd5b74 100644
--- a/plugin/reload/setup.go
+++ b/plugin/reload/setup.go
@@ -1,6 +1,7 @@
package reload
import (
+ "fmt"
"math/rand"
"sync"
"time"
@@ -17,7 +18,11 @@ func init() {
})
}
-var r *reload
+// the info reload is global to all application, whatever number of reloads.
+// it is used to transmit data between Setup and start of the hook called 'onInstanceStartup'
+// channel for QUIT is never changed in purpose.
+// WARNING: this data may be unsync after an invalid attempt of reload Corefile.
+var r = reload{interval: defaultInterval, usage: unused, quit: make(chan bool)}
var once sync.Once
func setup(c *caddy.Controller) error {
@@ -32,19 +37,25 @@ func setup(c *caddy.Controller) error {
if len(args) > 0 {
d, err := time.ParseDuration(args[0])
if err != nil {
- return err
+ return plugin.Error("reload", err)
}
i = d
}
+ if i < minInterval {
+ return plugin.Error("reload", fmt.Errorf("interval value must be greater or equal to %v", minInterval))
+ }
j := defaultJitter
if len(args) > 1 {
d, err := time.ParseDuration(args[1])
if err != nil {
- return err
+ return plugin.Error("reload", err)
}
j = d
}
+ if j < minJitter {
+ return plugin.Error("reload", fmt.Errorf("jitter value must be greater or equal to %v", minJitter))
+ }
if j > i/2 {
j = i / 2
@@ -53,20 +64,25 @@ func setup(c *caddy.Controller) error {
jitter := time.Duration(rand.Int63n(j.Nanoseconds()) - (j.Nanoseconds() / 2))
i = i + jitter
- r = &reload{interval: i, quit: make(chan bool)}
+ // prepare info for next onInstanceStartup event
+ r.interval = i
+ r.usage = used
+
once.Do(func() {
caddy.RegisterEventHook("reload", hook)
})
+ // re-register on finalShutDown as the instance most-likely will be changed
c.OnFinalShutdown(func() error {
r.quit <- true
return nil
})
-
return nil
}
const (
+ minJitter = 1 * time.Second
+ minInterval = 2 * time.Second
defaultInterval = 30 * time.Second
defaultJitter = 15 * time.Second
)