From bf47e5a8d0f7c620d8d325cc96ff68ed3999671e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Mon, 4 Jul 2022 18:23:35 +0200 Subject: [PATCH] cleanup. --- internal/http/metrics.go | 57 -------------------------------------- internal/http/router.go | 1 - internal/webrtc/metrics.go | 4 +-- 3 files changed, 2 insertions(+), 60 deletions(-) delete mode 100644 internal/http/metrics.go diff --git a/internal/http/metrics.go b/internal/http/metrics.go deleted file mode 100644 index 68623b1d..00000000 --- a/internal/http/metrics.go +++ /dev/null @@ -1,57 +0,0 @@ -package http - -import ( - "net/http" - "time" - - "github.com/go-chi/chi/middleware" - "github.com/prometheus/client_golang/prometheus" -) - -// Middleware is a handler that exposes prometheus metrics for the number of requests, -// the latency and the response size, partitioned by status code, method and HTTP path. -type metrics struct { - reqs *prometheus.CounterVec - latency *prometheus.HistogramVec -} - -// NewMiddleware returns a new prometheus Middleware handler. -func middlewareMetrics(next http.Handler) http.Handler { - var m metrics - - m.reqs = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Name: "requests_total", - Namespace: "neko", - Subsystem: "http", - Help: "How many HTTP requests processed, partitioned by status code, method and HTTP path.", - }, - []string{"code", "method", "path"}, - ) - prometheus.MustRegister(m.reqs) - - m.latency = prometheus.NewHistogramVec(prometheus.HistogramOpts{ - Name: "request_duration_milliseconds", - Namespace: "neko", - Subsystem: "http", - Help: "How long it took to process the request, partitioned by status code, method and HTTP path.", - Buckets: []float64{300, 1200, 5000}, - }, - []string{"code", "method", "path"}, - ) - - prometheus.MustRegister(m.latency) - return m.handler(next) -} - -func (c metrics) handler(next http.Handler) http.Handler { - fn := func(w http.ResponseWriter, r *http.Request) { - start := time.Now() - ww := middleware.NewWrapResponseWriter(w, r.ProtoMajor) - next.ServeHTTP(ww, r) - c.reqs.WithLabelValues(http.StatusText(ww.Status()), r.Method, r.URL.Path).Inc() - c.latency.WithLabelValues(http.StatusText(ww.Status()), r.Method, r.URL.Path).Observe(float64(time.Since(start).Nanoseconds()) / 1000000) - } - - return http.HandlerFunc(fn) -} diff --git a/internal/http/router.go b/internal/http/router.go index 30db7e4e..636cc4ca 100644 --- a/internal/http/router.go +++ b/internal/http/router.go @@ -20,7 +20,6 @@ func newRouter(logger zerolog.Logger) *router { r := chi.NewRouter() r.Use(middleware.RequestID) // Create a request ID for each request r.Use(middleware.RequestLogger(&logFormatter{logger})) - r.Use(middlewareMetrics) r.Use(middleware.Recoverer) // Recover from panics without crashing server return &router{r} } diff --git a/internal/webrtc/metrics.go b/internal/webrtc/metrics.go index 713b45e7..69498ed1 100644 --- a/internal/webrtc/metrics.go +++ b/internal/webrtc/metrics.go @@ -248,10 +248,10 @@ func (m *metricsCtx) SetVideoID(session types.Session, videoId string) { if _, found := met.videoIds[videoId]; !found { met.videoIds[videoId] = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "video_id", + Name: "video_listeners", Namespace: "neko", Subsystem: "webrtc", - Help: "Current Video ID of a session.", + Help: "Listeners for Video pipelines by a session.", ConstLabels: map[string]string{ "session_id": session.ID(), "video_id": videoId,