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
a29c725a
Commit
a29c725a
authored
May 04, 2017
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Count senddata responses in prometheus
parent
df0be2c4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
internal/senddata/injecter.go
internal/senddata/injecter.go
+5
-0
internal/senddata/senddata.go
internal/senddata/senddata.go
+17
-0
No files found.
internal/senddata/injecter.go
View file @
a29c725a
...
@@ -10,6 +10,7 @@ import (
...
@@ -10,6 +10,7 @@ import (
type
Injecter
interface
{
type
Injecter
interface
{
Match
(
string
)
bool
Match
(
string
)
bool
Inject
(
http
.
ResponseWriter
,
*
http
.
Request
,
string
)
Inject
(
http
.
ResponseWriter
,
*
http
.
Request
,
string
)
Name
()
string
}
}
type
Prefix
string
type
Prefix
string
...
@@ -30,3 +31,7 @@ func (p Prefix) Unpack(result interface{}, sendData string) error {
...
@@ -30,3 +31,7 @@ func (p Prefix) Unpack(result interface{}, sendData string) error {
}
}
return
nil
return
nil
}
}
func
(
p
Prefix
)
Name
()
string
{
return
strings
.
TrimSuffix
(
string
(
p
),
":"
)
}
internal/senddata/senddata.go
View file @
a29c725a
...
@@ -4,8 +4,24 @@ import (
...
@@ -4,8 +4,24 @@ import (
"net/http"
"net/http"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
"github.com/prometheus/client_golang/prometheus"
)
var
(
sendDataResponses
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"gitlab_workhorse_senddata_responses"
,
Help
:
"How many HTTP responses have been hijacked by a workhorse senddata injecter"
,
},
[]
string
{
"name"
},
)
)
)
func
init
()
{
prometheus
.
MustRegister
(
sendDataResponses
)
}
type
sendDataResponseWriter
struct
{
type
sendDataResponseWriter
struct
{
rw
http
.
ResponseWriter
rw
http
.
ResponseWriter
status
int
status
int
...
@@ -64,6 +80,7 @@ func (s *sendDataResponseWriter) tryInject() bool {
...
@@ -64,6 +80,7 @@ func (s *sendDataResponseWriter) tryInject() bool {
for
_
,
injecter
:=
range
s
.
injecters
{
for
_
,
injecter
:=
range
s
.
injecters
{
if
injecter
.
Match
(
header
)
{
if
injecter
.
Match
(
header
)
{
s
.
hijacked
=
true
s
.
hijacked
=
true
sendDataResponses
.
WithLabelValues
(
injecter
.
Name
())
.
Inc
()
helper
.
DisableResponseBuffering
(
s
.
rw
)
helper
.
DisableResponseBuffering
(
s
.
rw
)
injecter
.
Inject
(
s
.
rw
,
s
.
req
,
header
)
injecter
.
Inject
(
s
.
rw
,
s
.
req
,
header
)
return
true
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