Skip to content
Snippets Groups Projects
Commit a29c725a authored by Jacob Vosmaer (GitLab)'s avatar Jacob Vosmaer (GitLab)
Browse files

Count senddata responses in prometheus

parent df0be2c4
No related branches found
No related tags found
1 merge request!163Prometheus metrics for senddata and git archive cache
Loading
Loading
@@ -10,6 +10,7 @@ import (
type Injecter interface {
Match(string) bool
Inject(http.ResponseWriter, *http.Request, string)
Name() string
}
 
type Prefix string
Loading
Loading
@@ -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), ":")
}
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment