outposts: don't panic when listening for metrics fails
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
8d1fd48003
commit
2ac9f5426d
|
@ -24,14 +24,15 @@ var (
|
|||
|
||||
func RunServer() {
|
||||
m := mux.NewRouter()
|
||||
l := log.WithField("logger", "authentik.outpost.metrics")
|
||||
m.HandleFunc("/akprox/ping", func(rw http.ResponseWriter, r *http.Request) {
|
||||
rw.WriteHeader(204)
|
||||
})
|
||||
m.Path("/metrics").Handler(promhttp.Handler())
|
||||
listen := "0.0.0.0:9300"
|
||||
log.WithField("logger", "authentik.outpost.metrics").WithField("listen", listen).Info("Starting Metrics server")
|
||||
l.WithField("listen", listen).Info("Starting Metrics server")
|
||||
err := http.ListenAndServe(listen, m)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
l.WithError(err).Warning("Failed to start metrics listener")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,14 +24,15 @@ var (
|
|||
|
||||
func RunServer() {
|
||||
m := mux.NewRouter()
|
||||
l := log.WithField("logger", "authentik.outpost.metrics")
|
||||
m.HandleFunc("/akprox/ping", func(rw http.ResponseWriter, r *http.Request) {
|
||||
rw.WriteHeader(204)
|
||||
})
|
||||
m.Path("/metrics").Handler(promhttp.Handler())
|
||||
listen := "0.0.0.0:9300"
|
||||
log.WithField("logger", "authentik.outpost.metrics").WithField("listen", listen).Info("Starting Metrics server")
|
||||
l.WithField("listen", listen).Info("Starting Metrics server")
|
||||
err := http.ListenAndServe(listen, m)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
l.WithError(err).Warning("Failed to start metrics listener")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ var (
|
|||
|
||||
func RunMetricsServer() {
|
||||
m := mux.NewRouter()
|
||||
l := log.WithField("logger", "authentik.router.metrics")
|
||||
m.Path("/metrics").HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
promhttp.InstrumentMetricHandler(
|
||||
prometheus.DefaultRegisterer, promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{
|
||||
|
@ -31,26 +32,27 @@ func RunMetricsServer() {
|
|||
// Get upstream metrics
|
||||
re, err := http.NewRequest("GET", "http://localhost:8000/metrics/", nil)
|
||||
if err != nil {
|
||||
log.WithError(err).Warning("failed to get upstream metrics")
|
||||
l.WithError(err).Warning("failed to get upstream metrics")
|
||||
return
|
||||
}
|
||||
re.SetBasicAuth("monitor", config.G.SecretKey)
|
||||
res, err := http.DefaultClient.Do(re)
|
||||
if err != nil {
|
||||
log.WithError(err).Warning("failed to get upstream metrics")
|
||||
l.WithError(err).Warning("failed to get upstream metrics")
|
||||
return
|
||||
}
|
||||
bm, err := ioutil.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
log.WithError(err).Warning("failed to get upstream metrics")
|
||||
l.WithError(err).Warning("failed to get upstream metrics")
|
||||
return
|
||||
}
|
||||
_, err = rw.Write(bm)
|
||||
if err != nil {
|
||||
log.WithError(err).Warning("failed to get upstream metrics")
|
||||
l.WithError(err).Warning("failed to get upstream metrics")
|
||||
return
|
||||
}
|
||||
})
|
||||
l.WithField("listen", config.G.Web.ListenMetrics).Info("Listening (metrics)")
|
||||
err := http.ListenAndServe(config.G.Web.ListenMetrics, m)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
@ -26,7 +26,7 @@ func (ws *WebServer) listenTLS() {
|
|||
ws.log.WithError(err).Fatalf("failed to listen")
|
||||
return
|
||||
}
|
||||
ws.log.WithField("addr", config.G.Web.ListenTLS).Info("Listening (TLS)")
|
||||
ws.log.WithField("listen", config.G.Web.ListenTLS).Info("Listening (TLS)")
|
||||
|
||||
proxyListener := &proxyproto.Listener{Listener: tcpKeepAliveListener{ln.(*net.TCPListener)}}
|
||||
defer proxyListener.Close()
|
||||
|
|
|
@ -74,7 +74,7 @@ func (ws *WebServer) listenPlain() {
|
|||
if err != nil {
|
||||
ws.log.WithError(err).Fatalf("failed to listen")
|
||||
}
|
||||
ws.log.WithField("addr", config.G.Web.Listen).Info("Listening")
|
||||
ws.log.WithField("listen", config.G.Web.Listen).Info("Listening")
|
||||
|
||||
proxyListener := &proxyproto.Listener{Listener: ln}
|
||||
defer proxyListener.Close()
|
||||
|
|
Reference in a new issue