forked from kedacore/http-add-on
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.go
37 lines (28 loc) · 778 Bytes
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package middleware
import (
"net/http"
"github.com/kedacore/http-add-on/interceptor/metrics"
)
type Metrics struct {
upstreamHandler http.Handler
}
func NewMetrics(upstreamHandler http.Handler) *Metrics {
return &Metrics{
upstreamHandler: upstreamHandler,
}
}
func (m *Metrics) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w = newResponseWriter(w)
defer m.metrics(w, r)
m.upstreamHandler.ServeHTTP(w, r)
}
func (m *Metrics) metrics(w http.ResponseWriter, r *http.Request) {
mrw := w.(*responseWriter)
if mrw == nil {
mrw = newResponseWriter(w)
}
// exclude readiness & liveness probes from the emitted metrics
if r.URL.Path != "/livez" && r.URL.Path != "/readyz" {
metrics.RecordRequestCount(r.Method, r.URL.Path, mrw.statusCode, r.Host)
}
}