From 488102039cb5e79114954ad91663ce28c99153c8 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 7 Mar 2020 00:46:26 -0800 Subject: Log internal HTTP requests This restores the previous behavior of logging the success and failures of internal HTTP requests. Part of https://gitlab.com/gitlab-org/gitlab/issues/207916 --- internal/gitlabnet/client.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'internal/gitlabnet/client.go') diff --git a/internal/gitlabnet/client.go b/internal/gitlabnet/client.go index bb8655a..7c8f431 100644 --- a/internal/gitlabnet/client.go +++ b/internal/gitlabnet/client.go @@ -8,8 +8,11 @@ import ( "io" "net/http" "strings" + "time" + log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitlab-shell/internal/config" + "gitlab.com/gitlab-org/gitlab-shell/internal/logger" ) const ( @@ -111,15 +114,26 @@ func (c *GitlabClient) DoRequest(method, path string, data interface{}) (*http.R request.Header.Add("Content-Type", "application/json") request.Close = true + start := time.Now() response, err := c.httpClient.Do(request) + fields := log.Fields{ + "method": method, + "url": request.URL.String(), + "duration_ms": logger.ElapsedTime(start), + } + if err != nil { + log.WithError(err).WithFields(fields).Error("Internal API unreachable") return nil, fmt.Errorf("Internal API unreachable") } if err := parseError(response); err != nil { + log.WithError(err).WithFields(fields).Error("Internal API error") return nil, err } + log.WithFields(fields).Info("Finished HTTP request") + return response, nil } -- cgit v1.2.1