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
000ebbf2
Commit
000ebbf2
authored
May 04, 2017
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Re-use CountingResponseWriter for Git HTTP metrics
parent
625b53a1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
31 deletions
+17
-31
internal/git/responsewriter.go
internal/git/responsewriter.go
+8
-31
internal/helper/countingresponsewriter.go
internal/helper/countingresponsewriter.go
+9
-0
No files found.
internal/git/responsewriter.go
View file @
000ebbf2
...
@@ -4,6 +4,8 @@ import (
...
@@ -4,6 +4,8 @@ import (
"net/http"
"net/http"
"strconv"
"strconv"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus"
)
)
...
@@ -42,39 +44,14 @@ func init() {
...
@@ -42,39 +44,14 @@ func init() {
}
}
type
GitHttpResponseWriter
struct
{
type
GitHttpResponseWriter
struct
{
rw
http
.
ResponseWriter
helper
.
CountingResponseWriter
status
int
written
int64
}
}
func
NewGitHttpResponseWriter
(
rw
http
.
ResponseWriter
)
*
GitHttpResponseWriter
{
func
NewGitHttpResponseWriter
(
rw
http
.
ResponseWriter
)
*
GitHttpResponseWriter
{
gitHTTPSessionsActive
.
Inc
()
gitHTTPSessionsActive
.
Inc
()
return
&
GitHttpResponseWriter
{
return
&
GitHttpResponseWriter
{
rw
:
rw
,
CountingResponseWriter
:
helper
.
NewCountingResponseWriter
(
rw
),
}
}
func
(
w
*
GitHttpResponseWriter
)
Header
()
http
.
Header
{
return
w
.
rw
.
Header
()
}
func
(
w
*
GitHttpResponseWriter
)
Write
(
data
[]
byte
)
(
n
int
,
err
error
)
{
if
w
.
status
==
0
{
w
.
WriteHeader
(
http
.
StatusOK
)
}
}
n
,
err
=
w
.
rw
.
Write
(
data
)
w
.
written
+=
int64
(
n
)
return
n
,
err
}
func
(
w
*
GitHttpResponseWriter
)
WriteHeader
(
status
int
)
{
if
w
.
status
!=
0
{
return
}
w
.
status
=
status
w
.
rw
.
WriteHeader
(
status
)
}
}
func
(
w
*
GitHttpResponseWriter
)
Log
(
r
*
http
.
Request
,
writtenIn
int64
)
{
func
(
w
*
GitHttpResponseWriter
)
Log
(
r
*
http
.
Request
,
writtenIn
int64
)
{
...
@@ -82,11 +59,11 @@ func (w *GitHttpResponseWriter) Log(r *http.Request, writtenIn int64) {
...
@@ -82,11 +59,11 @@ func (w *GitHttpResponseWriter) Log(r *http.Request, writtenIn int64) {
agent
:=
getRequestAgent
(
r
)
agent
:=
getRequestAgent
(
r
)
gitHTTPSessionsActive
.
Dec
()
gitHTTPSessionsActive
.
Dec
()
gitHTTPRequests
.
WithLabelValues
(
r
.
Method
,
strconv
.
Itoa
(
w
.
status
),
service
,
agent
)
.
Inc
()
gitHTTPRequests
.
WithLabelValues
(
r
.
Method
,
strconv
.
Itoa
(
w
.
Status
()
),
service
,
agent
)
.
Inc
()
gitHTTPBytes
.
WithLabelValues
(
r
.
Method
,
strconv
.
Itoa
(
w
.
status
),
service
,
agent
,
directionIn
)
.
gitHTTPBytes
.
WithLabelValues
(
r
.
Method
,
strconv
.
Itoa
(
w
.
Status
()
),
service
,
agent
,
directionIn
)
.
Add
(
float64
(
writtenIn
))
Add
(
float64
(
writtenIn
))
gitHTTPBytes
.
WithLabelValues
(
r
.
Method
,
strconv
.
Itoa
(
w
.
status
),
service
,
agent
,
directionOut
)
.
gitHTTPBytes
.
WithLabelValues
(
r
.
Method
,
strconv
.
Itoa
(
w
.
Status
()
),
service
,
agent
,
directionOut
)
.
Add
(
float64
(
w
.
written
))
Add
(
float64
(
w
.
Count
()
))
}
}
func
getRequestAgent
(
r
*
http
.
Request
)
string
{
func
getRequestAgent
(
r
*
http
.
Request
)
string
{
...
...
internal/helper/countingresponsewriter.go
View file @
000ebbf2
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
type
CountingResponseWriter
interface
{
type
CountingResponseWriter
interface
{
http
.
ResponseWriter
http
.
ResponseWriter
Count
()
int64
Count
()
int64
Status
()
int
}
}
type
countingResponseWriter
struct
{
type
countingResponseWriter
struct
{
...
@@ -42,6 +43,14 @@ func (c *countingResponseWriter) WriteHeader(status int) {
...
@@ -42,6 +43,14 @@ func (c *countingResponseWriter) WriteHeader(status int) {
c
.
rw
.
WriteHeader
(
status
)
c
.
rw
.
WriteHeader
(
status
)
}
}
// Count returns the number of bytes written to the ResponseWriter. This
// function is not thread-safe.
func
(
c
*
countingResponseWriter
)
Count
()
int64
{
func
(
c
*
countingResponseWriter
)
Count
()
int64
{
return
c
.
count
return
c
.
count
}
}
// Status returns the first HTTP status value that was written to the
// ResponseWriter. This function is not thread-safe.
func
(
c
*
countingResponseWriter
)
Status
()
int
{
return
c
.
status
}
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