Skip to content

Commit

Permalink
Merge pull request #535 from lucaslorentz/custom-throttle-events-inte…
Browse files Browse the repository at this point in the history
…rval

Allow customizing the throttle interval for events
  • Loading branch information
lucaslorentz authored Sep 12, 2023
2 parents 024d217 + b253ae8 commit 86e2a82
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ Usage of docker-proxy:
Which mode this instance should run: standalone | controller | server
--polling-interval duration
Interval Caddy should manually check Docker for a new Caddyfile (default 30s)
--event-throttle-interval duration
Interval to throttle caddyfile updates triggered by docker events (default 100ms)
--process-caddyfile
Process Caddyfile before loading it, removing invalid servers (default true)
--proxy-service-tasks
Expand Down
15 changes: 15 additions & 0 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ func init() {
fs.Duration("polling-interval", 30*time.Second,
"Interval caddy should manually check docker for a new caddyfile")

fs.Duration("event-throttle-interval", 100*time.Millisecond,
"Interval to throttle caddyfile updates triggered by docker events")

return fs
}(),
})
Expand Down Expand Up @@ -143,6 +146,7 @@ func createOptions(flags caddycmd.Flags) *config.Options {
processCaddyfileFlag := flags.Bool("process-caddyfile")
scanStoppedContainersFlag := flags.Bool("scan-stopped-containers")
pollingIntervalFlag := flags.Duration("polling-interval")
eventThrottleIntervalFlag := flags.Duration("event-throttle-interval")
modeFlag := flags.String("mode")
controllerSubnetFlag := flags.String("controller-network")
dockerSocketsFlag := flags.String("docker-sockets")
Expand Down Expand Up @@ -254,5 +258,16 @@ func createOptions(flags caddycmd.Flags) *config.Options {
options.PollingInterval = pollingIntervalFlag
}

if eventThrottleIntervalEnv := os.Getenv("CADDY_DOCKER_EVENT_THROTTLE_INTERVAL"); eventThrottleIntervalEnv != "" {
if p, err := time.ParseDuration(eventThrottleIntervalEnv); err != nil {
log.Error("Failed to parse CADDY_DOCKER_EVENT_THROTTLE_INTERVAL", zap.String("CADDY_DOCKER_EVENT_THROTTLE_INTERVAL", eventThrottleIntervalEnv), zap.Error(err))
options.EventThrottleInterval = pollingIntervalFlag
} else {
options.EventThrottleInterval = p
}
} else {
options.EventThrottleInterval = eventThrottleIntervalFlag
}

return options
}
1 change: 1 addition & 0 deletions config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Options struct {
ProcessCaddyfile bool
ScanStoppedContainers bool
PollingInterval time.Duration
EventThrottleInterval time.Duration
Mode Mode
Secret string
ControllerNetwork *net.IPNet
Expand Down
2 changes: 1 addition & 1 deletion loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (dockerLoader *DockerLoader) listenEvents() {

if update {
dockerLoader.skipEvents[i] = true
dockerLoader.timer.Reset(100 * time.Millisecond)
dockerLoader.timer.Reset(dockerLoader.options.EventThrottleInterval)
}
case err := <-errorChan:
cancel()
Expand Down

0 comments on commit 86e2a82

Please sign in to comment.