Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app.go
diff options
context:
space:
mode:
authorKrasimir Angelov <kangelov@gitlab.com>2020-02-27 03:56:42 +0300
committerKrasimir Angelov <kangelov@gitlab.com>2020-02-28 04:38:10 +0300
commitd12e59eefc3ce15ba9dac808c5e345bf26ad5d45 (patch)
tree542ab5ae19f0c8a8696f0761e307f5ae7b993cba /app.go
parent70879969bde8aaf97d5ed97d15b904747a44bfb0 (diff)
Extract health check in its own middleware
This way we short-circuit health check requests and avoid doing domain lookup for them. We also do not report them in exported Prometheus metrics and this way avoid trigger alerts during deploys. Related to: * https://gitlab.com/gitlab-org/gitlab-pages/issues/350 * https://gitlab.com/gitlab-com/gl-infra/production/issues/1681
Diffstat (limited to 'app.go')
-rw-r--r--app.go37
1 files changed, 30 insertions, 7 deletions
diff --git a/app.go b/app.go
index 2626be49..22264eb8 100644
--- a/app.go
+++ b/app.go
@@ -124,12 +124,6 @@ func (a *theApp) checkAuthenticationIfNotExists(domain *domain.Domain, w http.Re
}
func (a *theApp) tryAuxiliaryHandlers(w http.ResponseWriter, r *http.Request, https bool, host string, domain *domain.Domain) bool {
- // short circuit content serving to check for a status page
- if r.RequestURI == a.appConfig.StatusPath {
- a.healthCheck(w, r, https)
- return true
- }
-
// Add auto redirect
if !https && a.RedirectHTTP {
a.redirectToHTTPS(w, r, http.StatusTemporaryRedirect)
@@ -177,6 +171,27 @@ func (a *theApp) routingMiddleware(handler http.Handler) http.Handler {
})
}
+// healthCheckMiddleware is serving the application status check
+func (a *theApp) healthCheckMiddleware(handler http.Handler) (http.Handler, error) {
+ healthCheck := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ a.healthCheck(w, r, request.IsHTTPS(r))
+ })
+
+ loggedHealthCheck, err := logging.BasicAccessLogger(healthCheck, a.LogFormat, nil)
+ if err != nil {
+ return nil, err
+ }
+
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.RequestURI == a.appConfig.StatusPath {
+ loggedHealthCheck.ServeHTTP(w, r)
+ return
+ }
+
+ handler.ServeHTTP(w, r)
+ }), nil
+}
+
// customHeadersMiddleware will inject custom headers into the response
func (a *theApp) customHeadersMiddleware(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -310,7 +325,6 @@ func (a *theApp) buildHandlerPipeline() (http.Handler, error) {
handler = a.auxiliaryMiddleware(handler)
handler = a.authMiddleware(handler)
handler = a.acmeMiddleware(handler)
- handler = a.customHeadersMiddleware(handler)
handler, err := logging.AccessLogger(handler, a.LogFormat)
if err != nil {
return nil, err
@@ -322,6 +336,15 @@ func (a *theApp) buildHandlerPipeline() (http.Handler, error) {
handler = a.routingMiddleware(handler)
+ // Health Check
+ handler, err = a.healthCheckMiddleware(handler)
+ if err != nil {
+ return nil, err
+ }
+
+ // Custom response headers
+ handler = a.customHeadersMiddleware(handler)
+
return handler, nil
}