From 215f76f91344c1ae6afc9af714406b810190b57c Mon Sep 17 00:00:00 2001 From: Travis Bischel Date: Tue, 11 May 2021 15:06:53 -0600 Subject: [PATCH] small breaking API: prefix hook interfaces with "Hook" This is to allow all hooks to be next to each other in godoc. Realistically, this will only break code that was checking that a type implemented the hook, so hopefully the scope of this breakage is small. --- pkg/kgo/broker.go | 12 ++++++------ pkg/kgo/hooks.go | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/kgo/broker.go b/pkg/kgo/broker.go index 4f8eefc3..4c2e53e8 100644 --- a/pkg/kgo/broker.go +++ b/pkg/kgo/broker.go @@ -492,7 +492,7 @@ func (b *broker) connect(ctx context.Context) (net.Conn, error) { conn, err := b.cl.cfg.dialFn(ctx, "tcp", b.addr) since := time.Since(start) b.cl.cfg.hooks.each(func(h Hook) { - if h, ok := h.(BrokerConnectHook); ok { + if h, ok := h.(HookBrokerConnect); ok { h.OnConnect(b.meta, since, conn, err) } }) @@ -826,7 +826,7 @@ func (cxn *brokerCxn) writeRequest(ctx context.Context, enqueuedForWritingAt tim bytesWritten, writeErr, writeWait, timeToWrite := cxn.writeConn(ctx, buf, wt, enqueuedForWritingAt) cxn.cl.cfg.hooks.each(func(h Hook) { - if h, ok := h.(BrokerWriteHook); ok { + if h, ok := h.(HookBrokerWrite); ok { h.OnWrite(cxn.b.meta, req.Key(), bytesWritten, writeWait, timeToWrite, writeErr) } }) @@ -986,7 +986,7 @@ func (cxn *brokerCxn) readResponse(ctx context.Context, timeout time.Duration, e nread, buf, err, readWait, timeToRead := cxn.readConn(ctx, timeout, enqueuedForReadingAt) cxn.cl.cfg.hooks.each(func(h Hook) { - if h, ok := h.(BrokerReadHook); ok { + if h, ok := h.(HookBrokerRead); ok { h.OnRead(cxn.b.meta, key, nread, readWait, timeToRead, err) } }) @@ -1019,7 +1019,7 @@ func (cxn *brokerCxn) readResponse(ctx context.Context, timeout time.Duration, e // which means we did not succeed enough to start handleResps. func (cxn *brokerCxn) closeConn() { cxn.cl.cfg.hooks.each(func(h Hook) { - if h, ok := h.(BrokerDisconnectHook); ok { + if h, ok := h.(HookBrokerDisconnect); ok { h.OnDisconnect(cxn.b.meta, cxn.conn) } }) @@ -1167,7 +1167,7 @@ func (cxn *brokerCxn) discard() { } cxn.cl.cfg.hooks.each(func(h Hook) { - if h, ok := h.(BrokerReadHook); ok { + if h, ok := h.(HookBrokerRead); ok { h.OnRead(cxn.b.meta, 0, nread, 0, timeToRead, err) } }) @@ -1211,7 +1211,7 @@ func (cxn *brokerCxn) handleResps() { } } cxn.cl.cfg.hooks.each(func(h Hook) { - if h, ok := h.(BrokerThrottleHook); ok { + if h, ok := h.(HookBrokerThrottle); ok { h.OnThrottle(cxn.b.meta, time.Duration(millis)*time.Millisecond, throttlesAfterResp) } }) diff --git a/pkg/kgo/hooks.go b/pkg/kgo/hooks.go index fc1f9a1f..26adbb33 100644 --- a/pkg/kgo/hooks.go +++ b/pkg/kgo/hooks.go @@ -27,26 +27,26 @@ func (hs hooks) each(fn func(Hook)) { } } -// BrokerConnectHook is called after a connection to a broker is opened. -type BrokerConnectHook interface { +// HookBrokerConnect is called after a connection to a broker is opened. +type HookBrokerConnect interface { // OnConnect is passed the broker metadata, how long it took to dial, // and either the dial's resulting net.Conn or error. OnConnect(meta BrokerMetadata, dialDur time.Duration, conn net.Conn, err error) } -// BrokerDisconnectHook is called when a connection to a broker is closed. -type BrokerDisconnectHook interface { +// HookBrokerDisconnect is called when a connection to a broker is closed. +type HookBrokerDisconnect interface { // OnDisconnect is passed the broker metadata and the connection that // is closing. OnDisconnect(meta BrokerMetadata, conn net.Conn) } -// BrokerWriteHook is called after a write to a broker. +// HookBrokerWrite is called after a write to a broker. // // Kerberos SASL does not cause write hooks, since it directly writes to the // connection. This may change in the future such that the sasl authenticate // key is used (even though sasl authenticate requests are not being issued). -type BrokerWriteHook interface { +type HookBrokerWrite interface { // OnWrite is passed the broker metadata, the key for the request that // was written, the number of bytes that were written (may not be the // whole request if there was an error), how long the request waited @@ -57,12 +57,12 @@ type BrokerWriteHook interface { OnWrite(meta BrokerMetadata, key int16, bytesWritten int, writeWait, timeToWrite time.Duration, err error) } -// BrokerReadHook is called after a read from a broker. +// HookBrokerRead is called after a read from a broker. // // Kerberos SASL does not cause read hooks, since it directly reads from the // connection. This may change in the future such that the sasl authenticate // key is used (even though sasl authenticate requests are not being issued). -type BrokerReadHook interface { +type HookBrokerRead interface { // OnRead is passed the broker metadata, the key for the response that // was read, the number of bytes read (may not be the whole read if // there was an error), how long the client waited before reading the @@ -72,9 +72,9 @@ type BrokerReadHook interface { OnRead(meta BrokerMetadata, key int16, bytesRead int, readWait, timeToRead time.Duration, err error) } -// BrokerThrottleHook is called after a response to a request is read +// HookBrokerThrottle is called after a response to a request is read // from a broker, and the response identifies throttling in effect. -type BrokerThrottleHook interface { +type HookBrokerThrottle interface { // OnThrottle is passed the broker metadata, the imposed throttling // interval, and whether the throttle was applied before Kafka // responded to them request or after.