-
Notifications
You must be signed in to change notification settings - Fork 155
feat(buffer_memory): spillover and active metrics #575
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
Merged
jem-davies
merged 3 commits into
warpstreamlabs:main
from
alecmerdler:buffer-memory-metrics
Dec 1, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,13 +44,21 @@ This buffer intentionally weakens the delivery guarantees of the pipeline and th | |
|
|
||
| ## Batching | ||
|
|
||
| It is possible to batch up messages sent from this buffer using a [batch policy](/docs/configuration/batching#batch-policy).`). | ||
| It is possible to batch up messages sent from this buffer using a [batch policy](/docs/configuration/batching#batch-policy). | ||
|
|
||
| ## Metrics | ||
|
|
||
| - ` + "`buffer_active`" + ` Gauge metric tracking the current number of bytes in the buffer. | ||
| - ` + "`buffer_spillover`" + ` Counter metric tracking the total number of bytes dropped because of spillover. | ||
|
|
||
| `). | ||
| Field(service.NewIntField("limit"). | ||
| Description(`The maximum buffer size (in bytes) to allow before applying backpressure upstream.`). | ||
| Default(524288000)). | ||
| Field(service.NewBoolField("spillover"). | ||
| Description("Whether to drop incoming messages that will exceed the buffer limit."). | ||
| Advanced(). | ||
| Version("1.13.0"). | ||
| Default(false)). | ||
| Field(service.NewInternalField(bs)) | ||
| } | ||
|
|
@@ -97,7 +105,7 @@ func newMemoryBufferFromConfig(conf *service.ParsedConfig, res *service.Resource | |
| } | ||
| } | ||
|
|
||
| return newMemoryBuffer(limit, spilloverEnabled, batcher), nil | ||
| return newMemoryBuffer(limit, spilloverEnabled, batcher, res), nil | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------ | ||
|
|
@@ -118,14 +126,19 @@ type memoryBuffer struct { | |
| closed bool | ||
|
|
||
| batcher *service.Batcher | ||
|
|
||
| activeBytes *service.MetricGauge | ||
| spilloverBytes *service.MetricCounter | ||
| } | ||
|
|
||
| func newMemoryBuffer(capacity int, spilloverEnabled bool, batcher *service.Batcher) *memoryBuffer { | ||
| func newMemoryBuffer(capacity int, spilloverEnabled bool, batcher *service.Batcher, res *service.Resources) *memoryBuffer { | ||
| return &memoryBuffer{ | ||
| cap: capacity, | ||
| spilloverEnabled: spilloverEnabled, | ||
| cond: sync.NewCond(&sync.Mutex{}), | ||
| batcher: batcher, | ||
| activeBytes: res.Metrics().NewGauge("buffer_active"), | ||
| spilloverBytes: res.Metrics().NewCounter("buffer_spillover"), | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -224,6 +237,7 @@ func (m *memoryBuffer) ReadBatch(ctx context.Context) (service.MessageBatch, ser | |
| defer m.cond.L.Unlock() | ||
| if err == nil { | ||
| m.bytes -= outSize | ||
| m.activeBytes.Set(int64(m.bytes)) | ||
| } else { | ||
| m.batches = append(batchSources, m.batches...) | ||
| } | ||
|
|
@@ -262,6 +276,7 @@ func (m *memoryBuffer) WriteBatch(ctx context.Context, msgBatch service.MessageB | |
|
|
||
| for (m.bytes + extraBytes) > m.cap { | ||
| if m.spilloverEnabled { | ||
| m.spilloverBytes.Incr(int64(extraBytes)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This |
||
| return component.ErrLimitReached | ||
| } | ||
|
|
||
|
|
@@ -276,6 +291,7 @@ func (m *memoryBuffer) WriteBatch(ctx context.Context, msgBatch service.MessageB | |
| size: extraBytes, | ||
| }) | ||
| m.bytes += extraBytes | ||
| m.activeBytes.Set(int64(m.bytes)) | ||
|
|
||
| m.cond.Broadcast() | ||
| return nil | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a note in the docs that these metrics will now be tracked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alecmerdler - was going to add but we don't have access so raised a PR: alecmerdler#1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I merged it and pulled in the changes to this branch now.