New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
admin: Implement a simple timer to pull config #4246
Conversation
mostly referenced to the issue re caddyserver#4106
Awesome, thanks for working on this! I'll take a look shortly. |
Here is an example {
"admin": {
"listen": "0.0.0.0:2019",
"config": {
"load_interval": "3s",
"load": { "module": "http", "url": "http://localhost:5000/config.json" }
}
},
"apps": {
"http": {
"servers": {
"local": {
"listen": [":8080"]
}
}
}
}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is a good looking PR.
The only thing I'm not real sure about is the fact that all config loading is now asynchronous. That does make me a little nervous since the vast majority of users won't use the pull feature, and would probably expect synchronous config loading. I am not sure of the consequences if we unblock while the config is loaded...
I do appreciate the simplicity of this approach, but I'm not sure what kinds of effects it will have. What do you think?
use `caddy.Duration` Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
I agree that load config asynchronously is a breaking change. I'm doing this because it's the simplest way to implement this feature. I will update this pr to keep loading config synchronously when no interval is specified as well as keep the code simple and clear. |
Co-authored-by: Francis Lavoie <lavofr@gmail.com>
caddy.go
Outdated
select { | ||
// if PullInterval is positive, will wait for the interval and then run with new config | ||
// otherwise, time.After(0) will return immediately, and run with new config | ||
case <-time.After(cfg.Admin.Config.PullInterval): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's still an issue here, CI failing. I think PullInterval
needs to be wrapped with a time.Duration()
to type convert it to a time.Duration
.
try not to make break change
admin.go
Outdated
// from config loader (eg. a http loader) with given interval. | ||
// | ||
// EXPERIMENTAL: Subject to change. | ||
PullInterval Duration `json:"pull_interval,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought... this affects how often the function specified by the load
property is run. So I wonder if, for consistency, we should call this LoadInterval
instead. Does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me!
Nice, this is a lot more like what I had envisioned. Does it work well? If so, there's just the matter of deciding the name for the property. Then we can merge this. |
It works as expected with the config I have given at #4246 (comment) And I tried another config without |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks for working on this and trying it out!
I had one more suggestion that I just noticed; otherwise, LGTM and let's merge this and give it a try.
Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
Implemented mostly referenced to the #4106
PullInterval
filed in configselect
with context and timerA trick point is that
https://github.com/colinaaa/caddy/blob/169bb265104d0ade5f8bab05d82e53eef30c0129/caddy.go#L485-L494
here I did not use if-else to check whether
PullInterval
is non-zero, but I directly usetime.After(PullInterval)
so that with 0 intervals.This will return immediately which is the same as executing without
time.After
re #4106