osbase/logtree: add WithStreamBufferSize option
Change-Id: I3aa2e39a2a191d8bac6812181df00f17660c99a9
Reviewed-on: https://review.monogon.dev/c/monogon/+/4446
Tested-by: Jenkins CI
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
diff --git a/osbase/logtree/logtree_access.go b/osbase/logtree/logtree_access.go
index fe58fbe..1582a8f 100644
--- a/osbase/logtree/logtree_access.go
+++ b/osbase/logtree/logtree_access.go
@@ -20,6 +20,7 @@
onlyLeveled bool
onlyRaw bool
leveledWithMinimumSeverity logging.Severity
+ withStreamBufferSize int
}
// WithChildren makes Read return/stream data for both a given DN and all its
@@ -38,6 +39,15 @@
}
}
+// WithStreamBuffer applies WithStream and overrides the default stream buffer
+// size of 128.
+func WithStreamBuffer(size int) LogReadOption {
+ return func(lro *logReaderOptions) {
+ lro.withStreamBufferSize = size
+ lro.withStream = true
+ }
+}
+
// WithBacklog makes Read return already recorded log entries, up to count
// elements.
func WithBacklog(count int) LogReadOption {
@@ -109,7 +119,9 @@
l.journal.mu.RLock()
defer l.journal.mu.RUnlock()
- var lro logReaderOptions
+ lro := logReaderOptions{
+ withStreamBufferSize: 128,
+ }
for _, opt := range opts {
opt(&lro)
@@ -147,8 +159,7 @@
lr := &LogReader{}
if lro.withStream {
sub := &subscriber{
- // TODO(q3k): make buffer size configurable
- dataC: make(chan *LogEntry, 128),
+ dataC: make(chan *LogEntry, lro.withStreamBufferSize),
doneC: make(chan struct{}),
filters: filters,
}