1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-11 02:13:49 +09:00

Merge pull request #25 from anyproto/fix-metric-panic

validate rpc method name
This commit is contained in:
Sergey Cherepanov 2023-06-14 15:27:46 +02:00 committed by GitHub
commit 53cbfca3ca
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -25,7 +25,6 @@ deps:
go mod download
go build -o deps storj.io/drpc/cmd/protoc-gen-go-drpc
go build -o deps github.com/gogo/protobuf/protoc-gen-gogofaster
go build -o deps github.com/golang/mock/mockgen
test:
go test ./... --cover

View file

@ -2,8 +2,10 @@ package metric
import (
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"
"storj.io/drpc"
"time"
"unicode/utf8"
)
type prometheusDRPC struct {
@ -14,7 +16,11 @@ type prometheusDRPC struct {
func (ph *prometheusDRPC) HandleRPC(stream drpc.Stream, rpc string) (err error) {
st := time.Now()
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)
}