-
Notifications
You must be signed in to change notification settings - Fork 688
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
internal/health: separate health and metrics services #2407
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2407 +/- ##
==========================================
- Coverage 78.09% 77.16% -0.94%
==========================================
Files 62 65 +3
Lines 5292 5443 +151
==========================================
+ Hits 4133 4200 +67
- Misses 1070 1152 +82
- Partials 89 91 +2
Continue to review full report at Codecov.
|
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.
Currently, http-address/http-port specifies where to tell Envoy
to start its HTTP listener, so we don't need to change that. The
stats-address/stats-port flags specify where the metrics and health
servers listen.
If we add new flags for heath-address/health-port, then the health service
can run on that, distinct from the metrics service. As @stevesloka noted
on the issue, if the new flag is not specified, Contour should implement
the previous, backwards compatible behavior. This means that we need
to have some special handling (or special defaults) on the new flags,
since the default case should be to put both services on the same address.
If metrics and health services are allowed to be started in different
configurations, that creates a structural problem for the internal
packages, which are designed to create a http.Server
for every
internal service. One way to decouple this is to add a member function to
httpsvc.Service
that accepts an interface representing a HTTP endpoint,
possibly something like this:
type Handler interface {
Attach(*http.ServeMux)
}
Unfortunately, there's not really a good place to document this, but I
definitely think that it should be documented.
Finally, we should discuss whether we want to update the deployment YAML
to configure the services separately. I'm not sure what the trade-off
here is, but maybe we should enable this by default?
Finally finally, take a look at the contributing doc and the link I
send you on Slack about git commit messages. The former has the standard
outline that you should try to follow for Contour.
Hi @jpeach There seems to be some confusion as things currently are not named or mapped very well.
My proposal is to retain the An example of how this currently looks using defaults
and then specifying a
|
Oh I see. Yes, I got it wrong there :-/
In this case, I was expecting that calling ListenAndServe would cause an error when the second server tried to bind the same address. If Go makes that work, then you are right, and we don't have to do any refactoring. |
@pickledrick I took a better look at this, and I think that the approach we should use is to decouple metrics and health from The result would look something like this: metricsvc := httpsvc.Service{
Addr: ctx.metricsAddr,
Port: ctx.metricsPort,
FieldLogger: log.WithField("context", "metricsvc"),
ServeMux: http.ServeMux{},
}
metricsvc.ServeMux.Handle("/metrics", metrics.Handler(registry))
if ctx.healthAddr == ctx.metricsAddr && ctx.healthPort == ctx.metricsPort {
h := health.Handler(clients.ClientSet())
metricsvc.ServeMux.Handle("/health", h)
metricsvc.ServeMux.Handle("/healthz", h)
}
g.Add(metricsvc.Start)
if ctx.healthAddr != ctx.metricsAddr || ctx.healthPort != ctx.metricsPort {
healthsvc := httpsvc.Service{
Addr: ctx.healthAddr,
Port: ctx.healthPort,
FieldLogger: log.WithField("context", "healthsvc"),
}
h := health.Handler(clients.ClientSet())
healthsvc.ServeMux.Handle("/health", h)
healthsvc.ServeMux.Handle("/healthz", h)
g.Add(healthsvc.Start)
} This approach keeps the health and metrics packages separate, and also decouples them from how we set up HTTP serving. One issue that needs a bit of consideration is what log fields the HTTP service should use (since context could not be ambiguous). Note that we should add |
Thanks @jpeach wrt
Just clarifying if you are referring to the health service or the metrics service? |
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.
A small set of minor issues.
Looking at the latest changes, I think that what you have is fine. |
Thanks @jpeach for your thoroughness. |
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.
This is ready to go. Just need a small update to the health check doc.
Provides the ability to separate HTTP listeners for the health and metrics services. Both host/port are configurable. Defaults are maintained to support backward compatability. This Fixes #2380. Signed-off-by: Peter Grant <pegrant@vmware.com>
Fixes #2380
Signed-off-by: Peter Grant pegrant@vmware.com
Allows for separating health/metric services.