2021-02-22 17:27:13 +05:30
|
|
|
package upstream
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
2022-05-07 20:08:51 +05:30
|
|
|
|
|
|
|
"gitlab.com/gitlab-org/labkit/metrics"
|
2021-02-22 17:27:13 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
namespace = "gitlab_workhorse"
|
|
|
|
httpSubsystem = "http"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-01-26 12:08:38 +05:30
|
|
|
httpGeoProxiedRequestsTotal = promauto.NewCounterVec(
|
|
|
|
prometheus.CounterOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: httpSubsystem,
|
|
|
|
Name: "geo_proxied_requests_total",
|
|
|
|
Help: "A counter for Geo proxied requests through workhorse.",
|
|
|
|
},
|
|
|
|
[]string{"code", "method", "route"},
|
|
|
|
)
|
2022-05-07 20:08:51 +05:30
|
|
|
|
|
|
|
buildHandler = metrics.NewHandlerFactory(metrics.WithNamespace(namespace), metrics.WithLabels("route"))
|
2021-02-22 17:27:13 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
func instrumentRoute(next http.Handler, method string, regexpStr string) http.Handler {
|
2022-05-07 20:08:51 +05:30
|
|
|
return buildHandler(next, metrics.WithLabelValues(map[string]string{"route": regexpStr}))
|
2021-02-22 17:27:13 +05:30
|
|
|
}
|
2022-01-26 12:08:38 +05:30
|
|
|
|
|
|
|
func instrumentGeoProxyRoute(next http.Handler, method string, regexpStr string) http.Handler {
|
|
|
|
return promhttp.InstrumentHandlerCounter(httpGeoProxiedRequestsTotal.MustCurryWith(map[string]string{"route": regexpStr}), next)
|
|
|
|
}
|