Fix custom error pages health check when not exporting /metrics
Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com>
This commit is contained in:
parent
14278417d1
commit
4d5db854d1
1 changed files with 11 additions and 6 deletions
|
@ -71,11 +71,11 @@ const (
|
||||||
DefaultFormatVar = "DEFAULT_RESPONSE_FORMAT"
|
DefaultFormatVar = "DEFAULT_RESPONSE_FORMAT"
|
||||||
|
|
||||||
// IsExportMetricsVar is the name of the environment variable indicating
|
// IsExportMetricsVar is the name of the environment variable indicating
|
||||||
// whether or not to export /metrics and /healthz.
|
// whether or not to export /metrics and /debug/vars.
|
||||||
IsExportMetricsVar = "IS_EXPORT_METRICS"
|
IsExportMetricsVar = "IS_EXPORT_METRICS"
|
||||||
|
|
||||||
// MetricsPortVar is the name of the environment variable indicating
|
// MetricsPortVar is the name of the environment variable indicating
|
||||||
// the port on which to export /metrics and /healthz.
|
// the port on which to export /metrics and /debug/vars.
|
||||||
MetricsPortVar = "METRICS_PORT"
|
MetricsPortVar = "METRICS_PORT"
|
||||||
|
|
||||||
// CustomErrorPagesPort is the port on which to listen to serve custom error pages.
|
// CustomErrorPagesPort is the port on which to listen to serve custom error pages.
|
||||||
|
@ -123,6 +123,9 @@ func createListeners() []Listener {
|
||||||
if !isExportMetrics {
|
if !isExportMetrics {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/", errorHandler(errFilesPath, defaultFormat))
|
mux.HandleFunc("/", errorHandler(errFilesPath, defaultFormat))
|
||||||
|
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
})
|
||||||
listeners = append(listeners, Listener{mux, CustomErrorPagesPort})
|
listeners = append(listeners, Listener{mux, CustomErrorPagesPort})
|
||||||
return listeners
|
return listeners
|
||||||
}
|
}
|
||||||
|
@ -132,10 +135,10 @@ func createListeners() []Listener {
|
||||||
if metricsPort == CustomErrorPagesPort {
|
if metricsPort == CustomErrorPagesPort {
|
||||||
mux := http.DefaultServeMux
|
mux := http.DefaultServeMux
|
||||||
mux.Handle("/metrics", promhttp.Handler())
|
mux.Handle("/metrics", promhttp.Handler())
|
||||||
|
mux.HandleFunc("/", errorHandler(errFilesPath, defaultFormat))
|
||||||
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/", errorHandler(errFilesPath, defaultFormat))
|
|
||||||
listeners = append(listeners, Listener{mux, CustomErrorPagesPort})
|
listeners = append(listeners, Listener{mux, CustomErrorPagesPort})
|
||||||
return listeners
|
return listeners
|
||||||
}
|
}
|
||||||
|
@ -145,11 +148,13 @@ func createListeners() []Listener {
|
||||||
// against DefaultServerMux.
|
// against DefaultServerMux.
|
||||||
metricsMux := http.DefaultServeMux
|
metricsMux := http.DefaultServeMux
|
||||||
metricsMux.Handle("/metrics", promhttp.Handler())
|
metricsMux.Handle("/metrics", promhttp.Handler())
|
||||||
metricsMux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
})
|
|
||||||
errorsMux := http.NewServeMux()
|
errorsMux := http.NewServeMux()
|
||||||
errorsMux.HandleFunc("/", errorHandler(errFilesPath, defaultFormat))
|
errorsMux.HandleFunc("/", errorHandler(errFilesPath, defaultFormat))
|
||||||
|
errorsMux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
})
|
||||||
|
|
||||||
listeners = append(listeners, Listener{metricsMux, metricsPort}, Listener{errorsMux, CustomErrorPagesPort})
|
listeners = append(listeners, Listener{metricsMux, metricsPort}, Listener{errorsMux, CustomErrorPagesPort})
|
||||||
return listeners
|
return listeners
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue