Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-workhorse
Commits
5f36b358
Commit
5f36b358
authored
Dec 16, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add metrics to internal/api package
parent
20ee508c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
1 deletion
+29
-1
internal/api/api.go
internal/api/api.go
+29
-1
No files found.
internal/api/api.go
View file @
5f36b358
...
@@ -8,8 +8,11 @@ import (
...
@@ -8,8 +8,11 @@ import (
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
"net/url"
"net/url"
"strconv"
"strings"
"strings"
"github.com/prometheus/client_golang/prometheus"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/badgateway"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/badgateway"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/secret"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/secret"
...
@@ -26,6 +29,27 @@ type API struct {
...
@@ -26,6 +29,27 @@ type API struct {
Version
string
Version
string
}
}
var
(
requestsCounter
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"gitlab_workhorse_internal_api_requests"
,
Help
:
"How many internal API requests have been completed by gitlab-workhorse, partitioned by status code and HTTP method."
,
},
[]
string
{
"code"
,
"method"
},
)
bytesTotal
=
prometheus
.
NewCounter
(
prometheus
.
CounterOpts
{
Name
:
"gitlab_workhorse_internal_api_failure_response_bytes"
,
Help
:
"How many bytes have been returned by upstream GitLab in API failure/rejection response bodies."
,
},
)
)
func
init
()
{
prometheus
.
MustRegister
(
requestsCounter
)
prometheus
.
MustRegister
(
bytesTotal
)
}
func
NewAPI
(
myURL
*
url
.
URL
,
version
string
,
roundTripper
*
badgateway
.
RoundTripper
)
*
API
{
func
NewAPI
(
myURL
*
url
.
URL
,
version
string
,
roundTripper
*
badgateway
.
RoundTripper
)
*
API
{
return
&
API
{
return
&
API
{
Client
:
&
http
.
Client
{
Transport
:
roundTripper
},
Client
:
&
http
.
Client
{
Transport
:
roundTripper
},
...
@@ -161,6 +185,7 @@ func (api *API) PreAuthorize(suffix string, r *http.Request) (httpResponse *http
...
@@ -161,6 +185,7 @@ func (api *API) PreAuthorize(suffix string, r *http.Request) (httpResponse *http
httpResponse
=
nil
httpResponse
=
nil
}
}
}()
}()
requestsCounter
.
WithLabelValues
(
strconv
.
Itoa
(
httpResponse
.
StatusCode
),
authReq
.
Method
)
.
Inc
()
if
httpResponse
.
StatusCode
!=
http
.
StatusOK
{
if
httpResponse
.
StatusCode
!=
http
.
StatusOK
{
return
httpResponse
,
nil
,
nil
return
httpResponse
,
nil
,
nil
...
@@ -205,6 +230,7 @@ func (api *API) PreAuthorizeHandler(next HandleFunc, suffix string) http.Handler
...
@@ -205,6 +230,7 @@ func (api *API) PreAuthorizeHandler(next HandleFunc, suffix string) http.Handler
helper
.
Fail500
(
w
,
r
,
err
)
helper
.
Fail500
(
w
,
r
,
err
)
}
}
httpResponse
.
Body
.
Close
()
// Free up the Unicorn worker
httpResponse
.
Body
.
Close
()
// Free up the Unicorn worker
bytesTotal
.
Add
(
float64
(
responseBody
.
Len
()))
for
k
,
v
:=
range
httpResponse
.
Header
{
for
k
,
v
:=
range
httpResponse
.
Header
{
// Accomodate broken clients that do case-sensitive header lookup
// Accomodate broken clients that do case-sensitive header lookup
...
@@ -215,7 +241,9 @@ func (api *API) PreAuthorizeHandler(next HandleFunc, suffix string) http.Handler
...
@@ -215,7 +241,9 @@ func (api *API) PreAuthorizeHandler(next HandleFunc, suffix string) http.Handler
}
}
}
}
w
.
WriteHeader
(
httpResponse
.
StatusCode
)
w
.
WriteHeader
(
httpResponse
.
StatusCode
)
io
.
Copy
(
w
,
responseBody
)
if
_
,
err
:=
io
.
Copy
(
w
,
responseBody
);
err
!=
nil
{
helper
.
LogError
(
r
,
err
)
}
return
return
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment