feat: Add limit on max buffered bytes in pattern-tee - #21855
Conversation
|
💻 Deploy preview deleted (feat: Add limit on max buffered bytes in pattern-tee). |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Autofix Details
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: New
IncandDecmethods are unused- Removed the unused MaxSampleCollector Inc and Dec convenience methods while leaving the Add/Sub API used by callers intact.
Or push these changes by commenting:
@cursor push 0c77582240
Preview (0c77582240)
diff --git a/pkg/util/metric/max_sample_collector.go b/pkg/util/metric/max_sample_collector.go
--- a/pkg/util/metric/max_sample_collector.go
+++ b/pkg/util/metric/max_sample_collector.go
@@ -40,16 +40,6 @@
c.val.Add(-delta)
}
-// Inc increments the counter.
-func (c *MaxSampleCollector) Inc() {
- c.val.Add(1)
-}
-
-// Dec decrements the counter.
-func (c *MaxSampleCollector) Dec() {
- c.val.Add(-1)
-}
-
// Describe implements [prometheus.Collector].
func (c *MaxSampleCollector) Describe(descs chan<- *prometheus.Desc) {
descs <- c.descYou can send follow-ups to the cloud agent here.
41bf637 to
c99b2ca
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Test uses
require.Containsincorrectly, missing second element check- Replaced each multi-value Contains assertion with separate checks for s1 and s3 so both buffered streams are verified.
Or push these changes by commenting:
@cursor push 8c120028cc
Preview (8c120028cc)
diff --git a/pkg/pattern/tee_service_test.go b/pkg/pattern/tee_service_test.go
--- a/pkg/pattern/tee_service_test.go
+++ b/pkg/pattern/tee_service_test.go
@@ -247,7 +247,8 @@
// tenantBuf should contain s1 and s3.
tenantBuf, ok = tee.buf["test"]
require.True(t, ok)
- require.Contains(t, tenantBuf, s1, s3)
+ require.Contains(t, tenantBuf, s1)
+ require.Contains(t, tenantBuf, s3)
// Stream should be rejected, total of s1, s3 and s4 is more than 1KB.
s4 := distributor.KeyedStream{
@@ -265,7 +266,8 @@
// tenantBuf should contain s1 and s3.
tenantBuf, ok = tee.buf["test"]
require.True(t, ok)
- require.Contains(t, tenantBuf, s1, s3)
+ require.Contains(t, tenantBuf, s1)
+ require.Contains(t, tenantBuf, s3)
// Flush s1 and s3, s4 should be accepted.
tee.flush()You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 7adeba9. Configure here.
5f08ef8 to
9755ae8
Compare
The base branch was changed.
This moves the check for streams with no entries out of batchesForTenant and into Duplicate. This means we no longer buffer streams, nor perform lookups in the ring, for streams that we are just going to discard anyway.
9755ae8 to
af5f76e
Compare


What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Checklist
CONTRIBUTING.mdguide (required)docs/sources/setup/upgrade/_index.mddeprecated-config.yamlanddeleted-config.yamlfiles respectively in thetools/deprecated-config-checkerdirectory. Example PRNote
Medium Risk
Adds a new buffering limit that can drop streams/flushes when the tee’s in-memory/queued payloads exceed a configured size, which changes backpressure/dropping behavior under load. The logic touches concurrency and accounting across buffering, batching, and send paths, so miscounting could lead to unexpected drops or memory growth.
Overview
Adds a new
tee_config.max_buffered_bytes/-pattern-ingester.tee.max-buffered-bytessetting to cap how many log bytes the pattern tee can buffer (disabled by default).TeeServicenow tracks total buffered bytes (in-memory buffer + queued flush requests) using atomic accounting; streams/flush requests are dropped when the cap would be exceeded, and bytes are released when requests are sent or dropped. A new max-sample metricpattern_ingester_tee_buffered_bytesis exported, and tests are updated/added to cover empty streams and the new limit behavior.Reviewed by Cursor Bugbot for commit 94cfbdd. Bugbot is set up for automated code reviews on this repo. Configure here.