mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
validate rpc method name
This commit is contained in:
parent
ff3fc68451
commit
d35ac55ee1
1 changed files with 7 additions and 1 deletions
|
@ -2,8 +2,10 @@ package metric
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"go.uber.org/zap"
|
||||||
"storj.io/drpc"
|
"storj.io/drpc"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
type prometheusDRPC struct {
|
type prometheusDRPC struct {
|
||||||
|
@ -14,7 +16,11 @@ type prometheusDRPC struct {
|
||||||
func (ph *prometheusDRPC) HandleRPC(stream drpc.Stream, rpc string) (err error) {
|
func (ph *prometheusDRPC) HandleRPC(stream drpc.Stream, rpc string) (err error) {
|
||||||
st := time.Now()
|
st := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
ph.SummaryVec.WithLabelValues(rpc).Observe(time.Since(st).Seconds())
|
if utf8.ValidString(rpc) {
|
||||||
|
ph.SummaryVec.WithLabelValues(rpc).Observe(time.Since(st).Seconds())
|
||||||
|
} else {
|
||||||
|
log.WarnCtx(stream.Context(), "invalid rpc string", zap.String("rpc", rpc))
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
return ph.Handler.HandleRPC(stream, rpc)
|
return ph.Handler.HandleRPC(stream, rpc)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue