Skip to content

Commit

Permalink
metrics: Do not rely on global HTTP server
Browse files Browse the repository at this point in the history
This moves away from the global Golang HTTP server for serving the
metrics for both Hubble and Cilium. Instead, a local instance is
created, which allows the two metrics server to run concurrently.

Fixes: #11066

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
  • Loading branch information
gandro committed Apr 20, 2020
1 parent 7bb9ed6 commit a15fb54
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions pkg/hubble/metrics/metrics.go
Expand Up @@ -56,8 +56,13 @@ func Init(address string, enabled api.Map) (<-chan error, error) {
errChan := make(chan error, 1)

go func() {
http.Handle("/metrics", promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
errChan <- http.ListenAndServe(address, nil)
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
srv := http.Server{
Addr: address,
Handler: mux,
}
errChan <- srv.ListenAndServe()
}()

return errChan, nil
Expand Down
9 changes: 7 additions & 2 deletions pkg/metrics/metrics.go
Expand Up @@ -1123,8 +1123,13 @@ func Enable(addr string) <-chan error {
go func() {
// The Handler function provides a default handler to expose metrics
// via an HTTP server. "/metrics" is the usual endpoint for that.
http.Handle("/metrics", promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
errs <- http.ListenAndServe(addr, nil)
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
srv := http.Server{
Addr: addr,
Handler: mux,
}
errs <- srv.ListenAndServe()
}()

return errs
Expand Down

0 comments on commit a15fb54

Please sign in to comment.