Skip to content

Commit

Permalink
Merge pull request #2019 from Shopify/dnwe/throttle
Browse files Browse the repository at this point in the history
feat: add logging & a metric for producer throttle
  • Loading branch information
dnwe authored Sep 13, 2021
2 parents 796a50b + 6e6f059 commit 52ac254
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Broker struct {
brokerResponseRate metrics.Meter
brokerResponseSize metrics.Histogram
brokerRequestsInFlight metrics.Counter
brokerThrottleTime metrics.Histogram

kerberosAuthenticator GSSAPIKerberosAuth
}
Expand Down Expand Up @@ -336,6 +337,15 @@ func (b *Broker) Produce(request *ProduceRequest) (*ProduceResponse, error) {
} else {
response = new(ProduceResponse)
err = b.sendAndReceive(request, response)
if response.ThrottleTime != time.Duration(0) {
DebugLogger.Printf(
"producer/broker/%d ProduceResponse throttled %v\n",
b.ID(), response.ThrottleTime)
if b.brokerThrottleTime != nil {
throttleTimeInMs := int64(response.ThrottleTime / time.Millisecond)
b.brokerThrottleTime.Update(throttleTimeInMs)
}
}
}

if err != nil {
Expand Down Expand Up @@ -1527,6 +1537,7 @@ func (b *Broker) registerMetrics() {
b.brokerResponseRate = b.registerMeter("response-rate")
b.brokerResponseSize = b.registerHistogram("response-size")
b.brokerRequestsInFlight = b.registerCounter("requests-in-flight")
b.brokerThrottleTime = b.registerHistogram("throttle-time-in-ms")
}

func (b *Broker) unregisterMetrics() {
Expand Down

0 comments on commit 52ac254

Please sign in to comment.