Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metric for internal publish latency #397

Merged
merged 2 commits into from Nov 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions pulsar/producer_partition.go
Expand Up @@ -82,6 +82,12 @@ var (
Help: "Publish latency experienced by the client",
Buckets: []float64{.0005, .001, .005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10},
})

publishRPCLatency = promauto.NewHistogram(prometheus.HistogramOpts{
Name: "pulsar_client_producer_rpc_latency_seconds",
Help: "Publish RPC latency experienced internally by the client when sending data to receiving an ack",
Buckets: []float64{.0005, .001, .005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10},
})
)

type partitionProducer struct {
Expand Down Expand Up @@ -424,6 +430,7 @@ type pendingItem struct {
sync.Mutex
batchData internal.Buffer
sequenceID uint64
sentAt int64
sendRequests []interface{}
completed bool
}
Expand All @@ -437,6 +444,7 @@ func (p *partitionProducer) internalFlushCurrentBatch() {
p.pendingQueue.Put(&pendingItem{
batchData: batchData,
sequenceID: sequenceID,
sentAt: time.Now().UnixNano(),
sendRequests: callbacks,
})
p.cnx.WriteData(batchData)
Expand Down Expand Up @@ -545,6 +553,9 @@ func (p *partitionProducer) ReceivedSendReceipt(response *pb.CommandSendReceipt)
// lock the pending item while sending the requests
pi.Lock()
defer pi.Unlock()
if pi.sentAt > 0 {
publishRPCLatency.Observe(float64(now-pi.sentAt) / 1.0e9)
}
for idx, i := range pi.sendRequests {
sr := i.(*sendRequest)
if sr.msg != nil {
Expand Down