From c51f9ef9401bbc61cc7039562508bd4d3f83b8bf Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 27 Jan 2024 00:25:49 -0800 Subject: [PATCH] fix: regression in internode bytes counting (#18880) wire up missing metrics since #18461 Bonus: fix trace output inconsistency --- internal/grid/connection.go | 7 ++++--- internal/grid/manager.go | 22 ++++++++++++---------- internal/grid/trace.go | 15 +++++++++++++-- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/internal/grid/connection.go b/internal/grid/connection.go index f2f887bb3..73875c6b8 100644 --- a/internal/grid/connection.go +++ b/internal/grid/connection.go @@ -757,6 +757,10 @@ func (c *Connection) receive(conn net.Conn, r receiver) error { if op != ws.OpBinary { return fmt.Errorf("unexpected connect response type %v", op) } + if c.incomingBytes != nil { + c.incomingBytes(int64(len(b))) + } + var m message _, _, err = m.parse(b) if err != nil { @@ -938,9 +942,6 @@ func (c *Connection) handleMessages(ctx context.Context, conn net.Conn) { logger.LogIfNot(ctx, fmt.Errorf("ws read: %w", err), net.ErrClosed, io.EOF) return } - if c.incomingBytes != nil { - c.incomingBytes(int64(len(msg))) - } // Parse the received message var m message subID, remain, err := m.parse(msg) diff --git a/internal/grid/manager.go b/internal/grid/manager.go index d291f29e5..626ebcdb6 100644 --- a/internal/grid/manager.go +++ b/internal/grid/manager.go @@ -105,16 +105,18 @@ func NewManager(ctx context.Context, o ManagerOptions) (*Manager, error) { continue } m.targets[host] = newConnection(connectionParams{ - ctx: ctx, - id: m.ID, - local: o.Local, - remote: host, - dial: o.Dialer, - handlers: &m.handlers, - auth: o.AddAuth, - blockConnect: o.BlockConnect, - tlsConfig: o.TLSConfig, - publisher: o.TraceTo, + ctx: ctx, + id: m.ID, + local: o.Local, + remote: host, + dial: o.Dialer, + handlers: &m.handlers, + auth: o.AddAuth, + blockConnect: o.BlockConnect, + tlsConfig: o.TLSConfig, + publisher: o.TraceTo, + incomingBytes: o.Incoming, + outgoingBytes: o.Outgoing, }) } if !found { diff --git a/internal/grid/trace.go b/internal/grid/trace.go index f1f30f2b0..2fe65644d 100644 --- a/internal/grid/trace.go +++ b/internal/grid/trace.go @@ -22,6 +22,7 @@ import ( "fmt" "net/http" "net/url" + "strings" "time" "github.com/minio/madmin-go/v3" @@ -64,10 +65,20 @@ type tracer struct { Subroute string } +const ( + httpScheme = "http://" + httpsScheme = "https://" +) + func (c *muxClient) traceRoundtrip(ctx context.Context, t *tracer, h HandlerID, req []byte) ([]byte, error) { if t == nil || t.Publisher.NumSubscribers(t.TraceType) == 0 { return c.roundtrip(h, req) } + + // Following trimming is needed for consistency between outputs with other internode traces. + local := strings.TrimPrefix(strings.TrimPrefix(t.Local, httpsScheme), httpScheme) + remote := strings.TrimPrefix(strings.TrimPrefix(t.Remote, httpsScheme), httpScheme) + start := time.Now() body := bytesOrLength(req) resp, err := c.roundtrip(h, req) @@ -90,7 +101,7 @@ func (c *muxClient) traceRoundtrip(ctx context.Context, t *tracer, h HandlerID, trace := madmin.TraceInfo{ TraceType: t.TraceType, FuncName: prefix + "." + h.String(), - NodeName: t.Remote, + NodeName: remote, Time: start, Duration: end.Sub(start), Path: t.Subroute, @@ -100,7 +111,7 @@ func (c *muxClient) traceRoundtrip(ctx context.Context, t *tracer, h HandlerID, Time: start, Proto: "grid", Method: "REQ", - Client: t.Local, + Client: local, Headers: nil, Path: t.Subroute, Body: []byte(body),