mirror of
https://github.com/netbirdio/netbird.git
synced 2025-04-01 03:36:16 +02:00
Measure write requests separately from read requests (#880)
This commit is contained in:
parent
03a42de5a0
commit
48265b32f3
2
go.mod
2
go.mod
@ -56,6 +56,7 @@ require (
|
||||
github.com/rs/xid v1.3.0
|
||||
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
|
||||
github.com/stretchr/testify v1.8.1
|
||||
go.opentelemetry.io/otel v1.11.1
|
||||
go.opentelemetry.io/otel/exporters/prometheus v0.33.0
|
||||
go.opentelemetry.io/otel/metric v0.33.0
|
||||
go.opentelemetry.io/otel/sdk/metric v0.33.0
|
||||
@ -123,7 +124,6 @@ require (
|
||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
|
||||
github.com/yashtewari/glob-intersection v0.1.0 // indirect
|
||||
github.com/yuin/goldmark v1.4.13 // indirect
|
||||
go.opentelemetry.io/otel v1.11.1 // indirect
|
||||
go.opentelemetry.io/otel/sdk v1.11.1 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.11.1 // indirect
|
||||
golang.org/x/image v0.0.0-20200430140353-33d19683fad8 // indirect
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
time "time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/instrument"
|
||||
"go.opentelemetry.io/otel/metric/instrument/syncint64"
|
||||
@ -163,7 +164,14 @@ func (m *HTTPMiddleware) Handler(h http.Handler) http.Handler {
|
||||
fn := func(rw http.ResponseWriter, r *http.Request) {
|
||||
reqStart := time.Now()
|
||||
defer func() {
|
||||
m.totalHTTPRequestDuration.Record(m.ctx, time.Since(reqStart).Milliseconds())
|
||||
tookMs := time.Since(reqStart).Milliseconds()
|
||||
m.totalHTTPRequestDuration.Record(m.ctx, tookMs)
|
||||
|
||||
if r.Method == http.MethodPut || r.Method == http.MethodPost || r.Method == http.MethodDelete {
|
||||
m.totalHTTPRequestDuration.Record(m.ctx, tookMs, attribute.String("type", "write"))
|
||||
} else {
|
||||
m.totalHTTPRequestDuration.Record(m.ctx, tookMs, attribute.String("type", "read"))
|
||||
}
|
||||
}()
|
||||
traceID := hash(fmt.Sprintf("%v", r))
|
||||
log.Tracef("HTTP request %v: %v %v", traceID, r.Method, r.URL)
|
||||
|
Loading…
Reference in New Issue
Block a user