Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func Listen(cfg *config.Configuration, handler http.Handler, adminHandler http.H
stopAdmin := make(chan os.Signal)
stopMain := make(chan os.Signal)
stopPrometheus := make(chan os.Signal)
var stopChannels = []chan<- os.Signal{stopMain}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Maybe it's just me but I find append more straightforward, can we modify to append(stopChannels, stopMain)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, can we use the := operand instead of var?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"append" is superfluous to just initialize the slice

done := make(chan struct{})

if cfg.UnixSocketEnable && len(cfg.UnixSocketName) > 0 { // start the unix_socket server if config enable-it.
Expand Down Expand Up @@ -54,6 +55,7 @@ func Listen(cfg *config.Configuration, handler http.Handler, adminHandler http.H
}

if cfg.Admin.Enabled {
stopChannels = append(stopChannels, stopAdmin)
adminServer := newAdminServer(cfg, adminHandler)
go shutdownAfterSignals(adminServer, stopAdmin, done)

Expand All @@ -70,18 +72,18 @@ func Listen(cfg *config.Configuration, handler http.Handler, adminHandler http.H
prometheusListener net.Listener
prometheusServer = newPrometheusServer(cfg, metrics)
)
stopChannels = append(stopChannels, stopPrometheus)
go shutdownAfterSignals(prometheusServer, stopPrometheus, done)
if prometheusListener, err = newTCPListener(prometheusServer.Addr, nil); err != nil {
glog.Errorf("Error listening for TCP connections on %s: %v for prometheus server", prometheusServer.Addr, err)
return
}

go runServer(prometheusServer, "Prometheus", prometheusListener)
wait(stopSignals, done, stopMain, stopAdmin, stopPrometheus)
} else {
wait(stopSignals, done, stopMain, stopAdmin)
}

wait(stopSignals, done, stopChannels...)

return
}

Expand Down
Loading