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
625b53a1
Commit
625b53a1
authored
May 04, 2017
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Count senddata bytes in prometheus
parent
a29c725a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
1 deletion
+58
-1
internal/helper/countingresponsewriter.go
internal/helper/countingresponsewriter.go
+47
-0
internal/senddata/senddata.go
internal/senddata/senddata.go
+11
-1
No files found.
internal/helper/countingresponsewriter.go
0 → 100644
View file @
625b53a1
package
helper
import
(
"net/http"
)
type
CountingResponseWriter
interface
{
http
.
ResponseWriter
Count
()
int64
}
type
countingResponseWriter
struct
{
rw
http
.
ResponseWriter
status
int
count
int64
}
func
NewCountingResponseWriter
(
rw
http
.
ResponseWriter
)
CountingResponseWriter
{
return
&
countingResponseWriter
{
rw
:
rw
}
}
func
(
c
*
countingResponseWriter
)
Header
()
http
.
Header
{
return
c
.
rw
.
Header
()
}
func
(
c
*
countingResponseWriter
)
Write
(
data
[]
byte
)
(
n
int
,
err
error
)
{
if
c
.
status
==
0
{
c
.
WriteHeader
(
http
.
StatusOK
)
}
n
,
err
=
c
.
rw
.
Write
(
data
)
c
.
count
+=
int64
(
n
)
return
n
,
err
}
func
(
c
*
countingResponseWriter
)
WriteHeader
(
status
int
)
{
if
c
.
status
!=
0
{
return
}
c
.
status
=
status
c
.
rw
.
WriteHeader
(
status
)
}
func
(
c
*
countingResponseWriter
)
Count
()
int64
{
return
c
.
count
}
internal/senddata/senddata.go
View file @
625b53a1
...
...
@@ -16,10 +16,18 @@ var (
},
[]
string
{
"name"
},
)
sendDataResponseBytes
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"gitlab_workhorse_senddata_response_bytes"
,
Help
:
"How many bytes have been written by workhorse senddata response hijackers"
,
},
[]
string
{
"name"
},
)
)
func
init
()
{
prometheus
.
MustRegister
(
sendDataResponses
)
prometheus
.
MustRegister
(
sendDataResponseBytes
)
}
type
sendDataResponseWriter
struct
{
...
...
@@ -82,7 +90,9 @@ func (s *sendDataResponseWriter) tryInject() bool {
s
.
hijacked
=
true
sendDataResponses
.
WithLabelValues
(
injecter
.
Name
())
.
Inc
()
helper
.
DisableResponseBuffering
(
s
.
rw
)
injecter
.
Inject
(
s
.
rw
,
s
.
req
,
header
)
crw
:=
helper
.
NewCountingResponseWriter
(
s
.
rw
)
injecter
.
Inject
(
crw
,
s
.
req
,
header
)
sendDataResponseBytes
.
WithLabelValues
(
injecter
.
Name
())
.
Add
(
float64
(
crw
.
Count
()))
return
true
}
}
...
...
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