Commit a29c725a authored by Jacob Vosmaer's avatar Jacob Vosmaer

Count senddata responses in prometheus

parent df0be2c4
...@@ -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), ":")
}
...@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment