Commit a29c725a authored by Jacob Vosmaer's avatar Jacob Vosmaer

Count senddata responses in prometheus

parent df0be2c4
......@@ -10,6 +10,7 @@ import (
type Injecter interface {
Match(string) bool
Inject(http.ResponseWriter, *http.Request, string)
Name() string
}
type Prefix string
......@@ -30,3 +31,7 @@ func (p Prefix) Unpack(result interface{}, sendData string) error {
}
return nil
}
func (p Prefix) Name() string {
return strings.TrimSuffix(string(p), ":")
}
......@@ -4,8 +4,24 @@ import (
"net/http"
"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 {
rw http.ResponseWriter
status int
......@@ -64,6 +80,7 @@ func (s *sendDataResponseWriter) tryInject() bool {
for _, injecter := range s.injecters {
if injecter.Match(header) {
s.hijacked = true
sendDataResponses.WithLabelValues(injecter.Name()).Inc()
helper.DisableResponseBuffering(s.rw)
injecter.Inject(s.rw, s.req, header)
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