Skip to content

Commit

Permalink
small breaking API: prefix hook interfaces with "Hook"
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
twmb committed May 11, 2021
1 parent 20837ec commit 215f76f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions pkg/kgo/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
Expand Down Expand Up @@ -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)
}
})
Expand Down Expand Up @@ -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)
}
})
Expand Down Expand Up @@ -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)
}
})
Expand Down Expand Up @@ -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)
}
})
Expand Down Expand Up @@ -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)
}
})
Expand Down
20 changes: 10 additions & 10 deletions pkg/kgo/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit 215f76f

Please sign in to comment.