Skip to content

Commit

Permalink
feat: report method name in WS metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
mkykadir committed Jul 19, 2024
1 parent ec496f5 commit e790296
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion proxyd/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@ type WSProxier struct {
methodWhitelist *StringSet
readTimeout time.Duration
writeTimeout time.Duration
reqIdToMethod map[string]string
}

func NewWSProxier(backend *Backend, clientConn, backendConn *websocket.Conn, methodWhitelist *StringSet) *WSProxier {
Expand All @@ -986,6 +987,7 @@ func NewWSProxier(backend *Backend, clientConn, backendConn *websocket.Conn, met
methodWhitelist: methodWhitelist,
readTimeout: defaultWSReadTimeout,
writeTimeout: defaultWSWriteTimeout,
reqIdToMethod: make(map[string]string),
}
}

Expand Down Expand Up @@ -1078,6 +1080,7 @@ func (w *WSProxier) clientPump(ctx context.Context, errC chan error) {
errC <- err
return
}
w.reqIdToMethod[GetReqID(ctx)] = req.Method
}
}

Expand Down Expand Up @@ -1106,6 +1109,13 @@ func (w *WSProxier) backendPump(ctx context.Context, errC chan error) {
}

res, err := w.parseBackendMsg(msg)
method := w.reqIdToMethod[GetReqID(ctx)]
if method == "" {
method = MethodUnknown
} else {
delete(w.reqIdToMethod, GetReqID(ctx))
}

if err != nil {
var id json.RawMessage
if res != nil {
Expand All @@ -1123,7 +1133,7 @@ func (w *WSProxier) backendPump(ctx context.Context, errC chan error) {
"auth", GetAuthCtx(ctx),
"req_id", GetReqID(ctx),
)
RecordRPCError(ctx, w.backend.Name, MethodUnknown, res.Error)
RecordRPCError(ctx, w.backend.Name, method, res.Error)
} else {
log.Info(
"forwarded WS message to client",
Expand Down

0 comments on commit e790296

Please sign in to comment.