Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: report method name in WS metrics #29

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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