diff options
author | Vladimir Shushlin <vshushlin@gitlab.com> | 2021-12-07 16:10:24 +0300 |
---|---|---|
committer | Vladimir Shushlin <vshushlin@gitlab.com> | 2021-12-07 16:10:24 +0300 |
commit | 8ee29a24422e012c5ed9f6ada9d55f4e7c13673d (patch) | |
tree | 03aa0fc07dc73fb7fa9bf0118c6d037d4a971872 /internal | |
parent | 2828e3b72a0a786736c2d6bcd5f591d5034e2754 (diff) | |
parent | 86d8aac645d1a6ccb24ab57c87e4aacf535bec7b (diff) |
Merge branch 'upgrade-labkit-1-11-0' into 'master'
chore: upgrade to labkit 1.11.0
See merge request gitlab-org/gitlab-pages!633
Diffstat (limited to 'internal')
-rw-r--r-- | internal/artifact/artifact.go | 6 | ||||
-rw-r--r-- | internal/auth/auth.go | 45 | ||||
-rw-r--r-- | internal/domain/domain.go | 6 | ||||
-rw-r--r-- | internal/httperrors/httperrors.go | 2 | ||||
-rw-r--r-- | internal/serving/disk/reader.go | 2 | ||||
-rw-r--r-- | internal/vfs/serving/serving.go | 5 |
6 files changed, 39 insertions, 27 deletions
diff --git a/internal/artifact/artifact.go b/internal/artifact/artifact.go index 3cb9c940..053ea940 100644 --- a/internal/artifact/artifact.go +++ b/internal/artifact/artifact.go @@ -80,7 +80,7 @@ func (a *Artifact) makeRequest(w http.ResponseWriter, r *http.Request, reqURL *u req, err := http.NewRequestWithContext(r.Context(), "GET", reqURL.String(), nil) if err != nil { logging.LogRequest(r).WithError(err).Error(createArtifactRequestErrMsg) - errortracking.Capture(err, errortracking.WithRequest(r)) + errortracking.Capture(err, errortracking.WithRequest(r), errortracking.WithStackTrace()) httperrors.Serve500(w) return } @@ -92,7 +92,7 @@ func (a *Artifact) makeRequest(w http.ResponseWriter, r *http.Request, reqURL *u if err != nil { logging.LogRequest(r).WithError(err).Error(artifactRequestErrMsg) - errortracking.Capture(err, errortracking.WithRequest(r)) + errortracking.Capture(err, errortracking.WithRequest(r), errortracking.WithStackTrace()) httperrors.Serve502(w) return } @@ -110,7 +110,7 @@ func (a *Artifact) makeRequest(w http.ResponseWriter, r *http.Request, reqURL *u if resp.StatusCode == http.StatusInternalServerError { logging.LogRequest(r).Error(errArtifactResponse) - errortracking.Capture(errArtifactResponse, errortracking.WithRequest(r)) + errortracking.Capture(errArtifactResponse, errortracking.WithRequest(r), errortracking.WithStackTrace()) httperrors.Serve500(w) return } diff --git a/internal/auth/auth.go b/internal/auth/auth.go index 07af99fe..b5865836 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -108,7 +108,7 @@ func (a *Auth) checkSession(w http.ResponseWriter, r *http.Request) (*sessions.S errsave := session.Save(r, w) if errsave != nil { logRequest(r).WithError(errsave).Error(saveSessionErrMsg) - errortracking.Capture(errsave, errortracking.WithRequest(r)) + captureErrWithReqAndStackTrace(errsave, r) httperrors.Serve500(w) return nil, errsave } @@ -178,7 +178,7 @@ func (a *Auth) checkAuthenticationResponse(session *sessions.Session, w http.Res decryptedCode, err := a.DecryptCode(r.URL.Query().Get("code"), getRequestDomain(r)) if err != nil { logRequest(r).WithError(err).Error("failed to decrypt secure code") - errortracking.Capture(err, errortracking.WithRequest(r)) + captureErrWithReqAndStackTrace(err, r) httperrors.Serve500(w) return } @@ -193,7 +193,9 @@ func (a *Auth) checkAuthenticationResponse(session *sessions.Session, w http.Res errortracking.Capture( err, errortracking.WithRequest(r), - errortracking.WithField("redirect_uri", redirectURI)) + errortracking.WithField("redirect_uri", redirectURI), + errortracking.WithStackTrace(), + ) httperrors.Serve503(w) return @@ -204,7 +206,7 @@ func (a *Auth) checkAuthenticationResponse(session *sessions.Session, w http.Res err = session.Save(r, w) if err != nil { logRequest(r).WithError(err).Error(saveSessionErrMsg) - errortracking.Capture(err, errortracking.WithRequest(r)) + captureErrWithReqAndStackTrace(err, r) httperrors.Serve500(w) return @@ -240,7 +242,11 @@ func (a *Auth) handleProxyingAuth(session *sessions.Session, w http.ResponseWrit proxyurl, err := url.Parse(domain) if err != nil { logRequest(r).WithField("domain", domain).Error(queryParameterErrMsg) - errortracking.Capture(err, errortracking.WithRequest(r), errortracking.WithField("domain", domain)) + errortracking.Capture(err, + errortracking.WithRequest(r), + errortracking.WithField("domain", domain), + errortracking.WithStackTrace(), + ) httperrors.Serve500(w) return true @@ -263,7 +269,7 @@ func (a *Auth) handleProxyingAuth(session *sessions.Session, w http.ResponseWrit err = session.Save(r, w) if err != nil { logRequest(r).WithError(err).Error(saveSessionErrMsg) - errortracking.Capture(err, errortracking.WithRequest(r)) + captureErrWithReqAndStackTrace(err, r) httperrors.Serve500(w) return true @@ -294,7 +300,7 @@ func (a *Auth) handleProxyingAuth(session *sessions.Session, w http.ResponseWrit err := session.Save(r, w) if err != nil { logRequest(r).WithError(err).Error(saveSessionErrMsg) - errortracking.Capture(err, errortracking.WithRequest(r)) + captureErrWithReqAndStackTrace(err, r) httperrors.Serve500(w) return true @@ -308,7 +314,7 @@ func (a *Auth) handleProxyingAuth(session *sessions.Session, w http.ResponseWrit signedCode, err := a.EncryptAndSignCode(proxyDomain, query.Get("code")) if err != nil { logRequest(r).WithError(err).Error(saveSessionErrMsg) - errortracking.Capture(err, errortracking.WithRequest(r)) + captureErrWithReqAndStackTrace(err, r) httperrors.Serve503(w) return true @@ -405,7 +411,7 @@ func (a *Auth) fetchAccessToken(ctx context.Context, code string) (tokenResponse if resp.StatusCode != 200 { err = errResponseNotOk - errortracking.Capture(err, errortracking.WithRequest(req)) + captureErrWithReqAndStackTrace(err, req) return token, err } @@ -448,7 +454,7 @@ func (a *Auth) checkTokenExists(session *sessions.Session, w http.ResponseWriter err := session.Save(r, w) if err != nil { logRequest(r).WithError(err).Error(saveSessionErrMsg) - errortracking.Capture(err, errortracking.WithRequest(r)) + captureErrWithReqAndStackTrace(err, r) httperrors.Serve500(w) return true @@ -475,7 +481,7 @@ func destroySession(session *sessions.Session, w http.ResponseWriter, r *http.Re err := session.Save(r, w) if err != nil { logRequest(r).WithError(err).Error(saveSessionErrMsg) - errortracking.Capture(err, errortracking.WithRequest(r)) + captureErrWithReqAndStackTrace(err, r) httperrors.Serve500(w) return @@ -507,7 +513,7 @@ func (a *Auth) checkAuthentication(w http.ResponseWriter, r *http.Request, domai if err != nil { logRequest(r).WithError(err).Error(failAuthErrMsg) - errortracking.Capture(err, errortracking.WithRequest(req)) + captureErrWithReqAndStackTrace(err, r) httperrors.Serve500(w) return true @@ -518,7 +524,7 @@ func (a *Auth) checkAuthentication(w http.ResponseWriter, r *http.Request, domai if err != nil { logRequest(r).WithError(err).Error("Failed to retrieve info with token") - errortracking.Capture(err) + captureErrWithReqAndStackTrace(err, r) // call serve404 handler when auth fails domain.ServeNotFoundAuthFailed(w, r) return true @@ -532,8 +538,9 @@ func (a *Auth) checkAuthentication(w http.ResponseWriter, r *http.Request, domai if resp.StatusCode != http.StatusOK { // call serve404 handler when auth fails - logRequest(r).WithField("status", resp.Status).Error("Unexpected response fetching access token") - errortracking.Capture(fmt.Errorf("unexpected response fetching access token status: %d", resp.StatusCode)) + err := fmt.Errorf("unexpected response fetching access token status: %d", resp.StatusCode) + logRequest(r).WithError(err).WithField("status", resp.Status).Error("Unexpected response fetching access token") + captureErrWithReqAndStackTrace(err, r) domain.ServeNotFoundAuthFailed(w, r) return true } @@ -581,7 +588,7 @@ func (a *Auth) CheckAuthentication(w http.ResponseWriter, r *http.Request, domai if a == nil { logRequest(r).Error(errAuthNotConfigured) - errortracking.Capture(errAuthNotConfigured, errortracking.WithRequest(r)) + captureErrWithReqAndStackTrace(errAuthNotConfigured, r) httperrors.Serve500(w) return true @@ -618,7 +625,7 @@ func checkResponseForInvalidToken(resp *http.Response, session *sessions.Session defer resp.Body.Close() err := json.NewDecoder(resp.Body).Decode(&errResp) if err != nil { - errortracking.Capture(err) + captureErrWithReqAndStackTrace(err, r) return false } @@ -687,3 +694,7 @@ func New(pagesDomain, storeSecret, clientID, clientSecret, redirectURI, internal now: time.Now, }, nil } + +func captureErrWithReqAndStackTrace(err error, r *http.Request) { + errortracking.Capture(err, errortracking.WithRequest(r), errortracking.WithStackTrace()) +} diff --git a/internal/domain/domain.go b/internal/domain/domain.go index 94888e34..695bc166 100644 --- a/internal/domain/domain.go +++ b/internal/domain/domain.go @@ -131,7 +131,7 @@ func (d *Domain) ServeFileHTTP(w http.ResponseWriter, r *http.Request) bool { return true } - errortracking.Capture(err, errortracking.WithRequest(r)) + errortracking.Capture(err, errortracking.WithRequest(r), errortracking.WithStackTrace()) httperrors.Serve503(w) return true } @@ -149,7 +149,7 @@ func (d *Domain) ServeNotFoundHTTP(w http.ResponseWriter, r *http.Request) { return } - errortracking.Capture(err, errortracking.WithRequest(r)) + errortracking.Capture(err, errortracking.WithRequest(r), errortracking.WithStackTrace()) httperrors.Serve503(w) return } @@ -173,7 +173,7 @@ func (d *Domain) serveNamespaceNotFound(w http.ResponseWriter, r *http.Request) return } - errortracking.Capture(err, errortracking.WithRequest(r)) + errortracking.Capture(err, errortracking.WithRequest(r), errortracking.WithStackTrace()) httperrors.Serve503(w) return } diff --git a/internal/httperrors/httperrors.go b/internal/httperrors/httperrors.go index a96e4d85..7de3b6bc 100644 --- a/internal/httperrors/httperrors.go +++ b/internal/httperrors/httperrors.go @@ -214,7 +214,7 @@ func Serve500WithRequest(w http.ResponseWriter, r *http.Request, reason string, "host": r.Host, "path": r.URL.Path, }).WithError(err).Error(reason) - errortracking.Capture(err, errortracking.WithRequest(r)) + errortracking.Capture(err, errortracking.WithRequest(r), errortracking.WithStackTrace()) serveErrorPage(w, content500) } diff --git a/internal/serving/disk/reader.go b/internal/serving/disk/reader.go index 5a6122df..61316509 100644 --- a/internal/serving/disk/reader.go +++ b/internal/serving/disk/reader.go @@ -55,7 +55,7 @@ func (reader *Reader) tryRedirects(h serving.Handler) bool { if err != redirects.ErrNoRedirect { // We assume that rewrite failure is not fatal // and we only capture the error - errortracking.Capture(err, errortracking.WithRequest(h.Request)) + errortracking.Capture(err, errortracking.WithRequest(h.Request), errortracking.WithStackTrace()) } return false } diff --git a/internal/vfs/serving/serving.go b/internal/vfs/serving/serving.go index b797fed5..6da2c6ed 100644 --- a/internal/vfs/serving/serving.go +++ b/internal/vfs/serving/serving.go @@ -13,10 +13,11 @@ import ( "strings" "time" + "gitlab.com/gitlab-org/labkit/errortracking" + "gitlab.com/gitlab-org/gitlab-pages/internal/httperrors" "gitlab.com/gitlab-org/gitlab-pages/internal/logging" "gitlab.com/gitlab-org/gitlab-pages/internal/vfs" - "gitlab.com/gitlab-org/labkit/errortracking" ) var errUnknownContentType = errors.New("serving: unknown content type") @@ -40,7 +41,7 @@ func serveContent(w http.ResponseWriter, r *http.Request, modtime time.Time, con _, haveType := w.Header()["Content-Type"] if !haveType { // this shouldn't happen - errortracking.Capture(errUnknownContentType, errortracking.WithRequest(r)) + errortracking.Capture(errUnknownContentType, errortracking.WithRequest(r), errortracking.WithStackTrace()) logging.LogRequest(r).WithError(errUnknownContentType).Error("could not serve content") httperrors.Serve500(w) |