Skip to content

Commit 5ab7a94

Browse files
authored
add metric: docappender.blocked.add counter (#219)
This monotonic counter increments every time Appender.Add detects that bulkItems channel length and capacity are equal before sending the created BulkIndexerItem to the channel. As bulkItems is a buffered channel, monitoring length and capacity allow us to detect possible blocking events when sending to the channel due to exhausted capacity. As Appender.Add could be called from multiple goroutines, we are not guaranteed that every time this metric is incremented the channel send will block, but should give us a reasonably approximated picture.
1 parent d7a82ed commit 5ab7a94

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

appender.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type Appender struct {
7575
availableBulkRequests int64
7676
activeCreated int64
7777
activeDestroyed int64
78+
blockedAdd int64
7879

7980
scalingInfo atomic.Value
8081

@@ -278,6 +279,10 @@ func (a *Appender) Add(ctx context.Context, index string, document io.WriterTo)
278279
Index: index,
279280
Body: document,
280281
}
282+
if len(a.bulkItems) == cap(a.bulkItems) {
283+
a.addCount(1, &a.blockedAdd, a.metrics.blockedAdd)
284+
}
285+
281286
select {
282287
case <-ctx.Done():
283288
return ctx.Err()

metric.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type metrics struct {
3838
availableBulkRequests metric.Int64UpDownCounter
3939
activeCreated metric.Int64Counter
4040
activeDestroyed metric.Int64Counter
41+
blockedAdd metric.Int64Counter
4142
}
4243

4344
type histogramMetric struct {
@@ -132,6 +133,11 @@ func newMetrics(cfg Config) (metrics, error) {
132133
description: "The number of times an active indexer was destroyed.",
133134
p: &ms.activeDestroyed,
134135
},
136+
{
137+
name: "docappender.blocked.add",
138+
description: "The number of times Add could block due to exhausted capacity in bulkItems channel",
139+
p: &ms.blockedAdd,
140+
},
135141
}
136142
for _, m := range counters {
137143
err := newInt64Counter(meter, m)

0 commit comments

Comments
 (0)