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:
commit
53cbfca3ca
2 changed files with 7 additions and 2 deletions
1
Makefile
1
Makefile
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue