code: func (l *lagLogger) Rate() int64 {
  	if len(l.measurements) < 2 {
  		return 0
  	}
  
  	latestLag := l.measurements[l.pos]
  	var earliestLag offsetMeasurement
  
  	if len(l.measurements) == cap(l.measurements) {
  		earliestLag = l.measurements[(l.pos+1)%len(l.measurements)]
  	} else {
  		earliestLag = l.measurements[0]
  	}
  
  	high, low := latestLag.highWaterMark, earliestLag.highWaterMark
  
  	// If there are no longer any incoming messages, use our read offsets to compute rate
  	if high == low {
  		high, low = latestLag.readOffset, earliestLag.readOffset
  	}
  	if high < low {
  		// Offset must have wrapped around...seems unlikely. Estimate growth using MaxInt64
  		high = math.MaxInt64
  	}
  
  	totalGrowth := float64(high - low)
  	totalDurationSec := float64(latestLag.ts.UnixNano()-earliestLag.ts.UnixNano()) / float64(time.Second.Nanoseconds())
  
  	return int64(totalGrowth / totalDurationSec)
  }
docs: // Rate returns an average rate calculation over the last N measurements (configured at construction)
  // after startup, reported rate may be 0 if we haven't been up long enough to determine it yet.