Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gitlab-runner
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Seipel
gitlab-runner
Commits
6ce1d59f
Unverified
Commit
6ce1d59f
authored
6 years ago
by
Tomasz Maczukin
Browse files
Options
Downloads
Patches
Plain Diff
Add logging of body of requests sent from Runner to GitLab
parent
d0f94c53
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
network/client.go
+53
-1
53 additions, 1 deletion
network/client.go
network/gitlab_test.go
+14
-0
14 additions, 0 deletions
network/gitlab_test.go
with
67 additions
and
1 deletion
network/client.go
+
53
−
1
View file @
6ce1d59f
...
@@ -23,8 +23,8 @@ import (
...
@@ -23,8 +23,8 @@ import (
"github.com/jpillora/backoff"
"github.com/jpillora/backoff"
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"
"gitlab.com/gitlab-org/gitlab-runner/common"
"gitlab.com/gitlab-org/gitlab-runner/common"
"gitlab.com/gitlab-org/gitlab-runner/helpers"
)
)
type
requestCredentials
interface
{
type
requestCredentials
interface
{
...
@@ -251,6 +251,9 @@ func (n *client) do(uri, method string, request io.Reader, requestType string, h
...
@@ -251,6 +251,9 @@ func (n *client) do(uri, method string, request io.Reader, requestType string, h
return
return
}
}
reqID
,
_
:=
helpers
.
GenerateRandomUUID
(
10
)
dumpRequestBody
(
reqID
,
method
,
url
,
request
)
req
,
err
:=
http
.
NewRequest
(
method
,
url
.
String
(),
request
)
req
,
err
:=
http
.
NewRequest
(
method
,
url
.
String
(),
request
)
if
err
!=
nil
{
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"failed to create NewRequest: %v"
,
err
)
err
=
fmt
.
Errorf
(
"failed to create NewRequest: %v"
,
err
)
...
@@ -269,9 +272,58 @@ func (n *client) do(uri, method string, request io.Reader, requestType string, h
...
@@ -269,9 +272,58 @@ func (n *client) do(uri, method string, request io.Reader, requestType string, h
n
.
ensureTLSConfig
()
n
.
ensureTLSConfig
()
res
,
err
=
n
.
doBackoffRequest
(
req
)
res
,
err
=
n
.
doBackoffRequest
(
req
)
dumpResponseBody
(
reqID
,
method
,
url
,
res
)
return
return
}
}
func
dumpRequestBody
(
reqID
string
,
method
string
,
url
*
url
.
URL
,
request
io
.
Reader
)
{
if
logrus
.
GetLevel
()
<
logrus
.
DebugLevel
||
request
==
nil
{
return
}
req
,
ok
:=
request
.
(
*
bytes
.
Reader
)
if
!
ok
{
return
}
body
,
err
:=
ioutil
.
ReadAll
(
req
)
req
.
Reset
(
body
)
if
err
==
nil
{
logrus
.
WithFields
(
logrus
.
Fields
{
"reqID"
:
reqID
,
"Method"
:
method
,
"URI"
:
url
.
String
(),
})
.
Debugf
(
"Sending request: %s"
,
string
(
body
))
}
else
{
logrus
.
WithError
(
err
)
.
Debug
(
"Error while LOGGING sent request."
)
}
}
func
dumpResponseBody
(
reqID
string
,
method
string
,
url
*
url
.
URL
,
response
*
http
.
Response
)
{
if
logrus
.
GetLevel
()
<
logrus
.
DebugLevel
||
response
==
nil
||
response
.
Body
==
nil
{
return
}
body
,
err
:=
ioutil
.
ReadAll
(
response
.
Body
)
response
.
Body
.
Close
()
response
.
Body
=
ioutil
.
NopCloser
(
bytes
.
NewReader
(
body
))
if
err
==
nil
{
logrus
.
WithFields
(
logrus
.
Fields
{
"reqID"
:
reqID
,
"Method"
:
method
,
"URI"
:
url
.
String
(),
"StatusCode"
:
response
.
StatusCode
,
"Status"
:
response
.
Status
,
})
.
Debugf
(
"Received response: %s"
,
string
(
body
))
}
else
{
logrus
.
WithError
(
err
)
.
Debug
(
"Error while LOGGING received response."
)
}
}
func
(
n
*
client
)
doJSON
(
uri
,
method
string
,
statusCode
int
,
request
interface
{},
response
interface
{})
(
int
,
string
,
ResponseTLSData
,
*
http
.
Response
)
{
func
(
n
*
client
)
doJSON
(
uri
,
method
string
,
statusCode
int
,
request
interface
{},
response
interface
{})
(
int
,
string
,
ResponseTLSData
,
*
http
.
Response
)
{
var
body
io
.
Reader
var
body
io
.
Reader
...
...
This diff is collapsed.
Click to expand it.
network/gitlab_test.go
+
14
−
0
View file @
6ce1d59f
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
"strings"
"strings"
"testing"
"testing"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
...
@@ -118,7 +119,18 @@ func testRegisterRunnerHandler(w http.ResponseWriter, r *http.Request, t *testin
...
@@ -118,7 +119,18 @@ func testRegisterRunnerHandler(w http.ResponseWriter, r *http.Request, t *testin
w
.
Write
(
output
)
w
.
Write
(
output
)
}
}
func
setLogrusDebug
()
func
()
{
oldLevel
:=
logrus
.
GetLevel
()
logrus
.
SetLevel
(
logrus
.
DebugLevel
)
return
func
()
{
logrus
.
SetLevel
(
oldLevel
)
}
}
func
TestRegisterRunner
(
t
*
testing
.
T
)
{
func
TestRegisterRunner
(
t
*
testing
.
T
)
{
defer
setLogrusDebug
()()
s
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
s
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testRegisterRunnerHandler
(
w
,
r
,
t
)
testRegisterRunnerHandler
(
w
,
r
,
t
)
}))
}))
...
@@ -188,6 +200,8 @@ func testUnregisterRunnerHandler(w http.ResponseWriter, r *http.Request, t *test
...
@@ -188,6 +200,8 @@ func testUnregisterRunnerHandler(w http.ResponseWriter, r *http.Request, t *test
}
}
func
TestUnregisterRunner
(
t
*
testing
.
T
)
{
func
TestUnregisterRunner
(
t
*
testing
.
T
)
{
defer
setLogrusDebug
()()
handler
:=
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
handler
:=
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testUnregisterRunnerHandler
(
w
,
r
,
t
)
testUnregisterRunnerHandler
(
w
,
r
,
t
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment