summaryrefslogtreecommitdiff
path: root/internal/gitlabnet/client.go
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2020-03-07 00:46:26 -0800
committerStan Hu <stanhu@gmail.com>2020-03-10 00:41:24 -0700
commit488102039cb5e79114954ad91663ce28c99153c8 (patch)
tree808256b23022449477aa8e17ad3865ba6a3213b6 /internal/gitlabnet/client.go
parentb920520599142435ce06ad155099544adc923618 (diff)
downloadgitlab-shell-sh-log-http-requests.tar.gz
Log internal HTTP requestssh-log-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
Diffstat (limited to 'internal/gitlabnet/client.go')
-rw-r--r--internal/gitlabnet/client.go14
1 files changed, 14 insertions, 0 deletions
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
}