-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Add HealthCheck #918
Add HealthCheck #918
Conversation
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.
Hey @juliens thanks a lot for this :)
I made few comments.
I'm not entirely sure on the "one go routine" design. If one check takes a long time, it will defers other checks. We can't have different healthchecks for different backends (and we will need that). WDYT @containous/traefik ?
server.go
Outdated
@@ -524,6 +525,9 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo | |||
redirectHandlers := make(map[string]http.Handler) | |||
|
|||
backends := map[string]http.Handler{} | |||
|
|||
backendsHealcheck := map[string]*healthcheck.BackendHealthCheck{} |
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.
typo
healthcheck/healthcheck.go
Outdated
singleton = newHealthCheck() | ||
singleton.execute() | ||
}) | ||
return singleton |
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.
Maybe an init
function would be simpler ?
healthcheck/healthcheck.go
Outdated
} | ||
|
||
func testHealth(serverURL *url.URL, checkURL string) bool { | ||
resp, err := http.Get(serverURL.String() + checkURL) |
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.
We need a timeout here
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.
Hey @juliens, I made a few comments in the code :)
Could you also update the documentation (doc/
)?
Thanks a lot !
/cc @containous/traefik
healthcheck/healthcheck.go
Outdated
} | ||
} | ||
|
||
func testHealth(serverURL *url.URL, checkURL string) bool { |
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.
Can you change this to checkHealth
instead, we could confuse with a real test ;)
server.go
Outdated
@@ -732,6 +742,7 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo | |||
} | |||
} | |||
} | |||
healthcheck.GetHealthCheck().SetBackendsConfiguration(backendsHealthcheck) |
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.
Could you add a parameter server.routinesPool.Ctx()
here ?
healthcheck/healthcheck.go
Outdated
if hc.cancel != nil { | ||
hc.cancel() | ||
} | ||
ctx, cancel := context.WithCancel(context.Background()) |
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.
Could you use the global context from server.routinesPool.Ctx()
?
healthcheck/healthcheck.go
Outdated
|
||
func (hc *HealthCheck) execute(ctx context.Context) { | ||
for backendID, backend := range hc.Backends { | ||
go func(backendID string, backend *BackendHealthCheck) { |
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.
I think we should be safer here. We need to recover in case of a panic in those goroutines.
Could you use the safe.Go()
wrapper here ?
types/types.go
Outdated
@@ -35,6 +36,11 @@ type CircuitBreaker struct { | |||
Expression string `json:"expression,omitempty"` | |||
} | |||
|
|||
// HealthCheck holds healthchk configuration |
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.
HealthCheck holds healthchk
*HealthCheck
healthcheck/healthcheck.go
Outdated
ticker := time.NewTicker(time.Second * 30) | ||
select { | ||
case <-ctx.Done(): | ||
log.Debugf("Refreshing All Healthcheck goroutines") |
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.
You mean stopping ?
healthcheck/healthcheck.go
Outdated
var newDisabledURLs []*url.URL | ||
for _, url := range backend.DisabledURLs { | ||
if testHealth(url, backend.URL) { | ||
log.Debugf("Upsert %s", url.String()) |
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.
Could you log more info in this log ?
healthcheck/healthcheck.go
Outdated
|
||
for _, url := range enabledURLs { | ||
if !testHealth(url, backend.URL) { | ||
log.Debugf("Remove %s", url.String()) |
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.
Could you log more info in this log ?
@juliens are you still working on this? I'm interested in this feature and can take a look at addressing the comments, etc, if you don't have time. |
@bakins I think that will be difficult to handle this before the next release (tomorrow, I guess). I'll try to do it before the end of the week. |
04f1dfd
to
e3ad4ff
Compare
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.
@juliens Thank you for your corrections :)
I think we can merge this one. We will need another PR later to add tests and documentation during the RC phase.
/cc @containous/traefik
66b85d9
to
9d726c1
Compare
Seems like I can close my issue then :) Good work. |
No description provided.