Skip to content

Commit 191cd06

Browse files
nicklas-dohrnchombium
authored andcommitted
Add inline documentation
1 parent 5d838f9 commit 191cd06

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/pkg/egress/syslog/https_batch.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ import (
1313
"github.com/valyala/fasthttp"
1414
)
1515

16-
// --- Coordinator definition ---
16+
// --- Retry Coordinator Definition ---
17+
18+
// RetryCoordinator provides global concurrency control for retry operations
19+
// across all drain writers. It uses a semaphore pattern to enforce a configurable
20+
// limit on the number of concurrent retries, preventing resource exhaustion
21+
// and noisy-neighbor problems during periods of high retry load. When all
22+
// retry slots are in use, additional retries will wait until a slot becomes
23+
// available, ensuring the system remains stable while still attempting
24+
// delivery of all messages. This coordinator will be used as a singleton.
1725
type RetryCoordinator struct {
1826
sem chan struct{}
1927
}
@@ -31,6 +39,8 @@ func WithParallelRetries(n int) {
3139
}
3240
}
3341

42+
// GetGlobalRetryCoordinator returns a singleton instance of RetryCoordinator.
43+
// It initializes the coordinator with a semaphore that limits the number of concurrent retries.
3444
func GetGlobalRetryCoordinator() *RetryCoordinator {
3545
globalRetryCoordinatorOnce.Do(func() {
3646
globalRetryCoordinator = &RetryCoordinator{
@@ -55,6 +65,10 @@ func (c *RetryCoordinator) Release() {
5565
<-c.sem
5666
}
5767

68+
// --- RetryWriter Definition ---
69+
70+
// InternalRetryWriter is an interface that defines methods for configuring retry behavior
71+
// for syslog writers. It allows setting a retry duration function and the maximum number of retries.
5872
type InternalRetryWriter interface {
5973
ConfigureRetry(retryDuration RetryDuration, maxRetries int)
6074
}
@@ -66,6 +80,12 @@ type Retryer struct {
6680
coordinator *RetryCoordinator
6781
}
6882

83+
// Retryer handles retry logic for failed operations with configurable policies.
84+
// It coordinates with the global RetryCoordinator to limit concurrent retries,
85+
// implements exponential backoff with configurable intervals, and respects
86+
// context cancellation for graceful shutdown. The first attempt is always
87+
// performed without acquiring a retry slot (fast path), while subsequent
88+
// retries are subject to global concurrency limits.
6989
func NewRetryer(
7090
binding *URLBinding,
7191
retryDuration RetryDuration,
@@ -124,6 +144,8 @@ func (r *Retryer) Retry(batch []byte, msgCount float64, funcToRetry func([]byte,
124144
return true
125145
}
126146

147+
// --- HTTPSBatchWriter definition ---
148+
127149
type HTTPSBatchWriter struct {
128150
HTTPSWriter
129151
batchSize int
@@ -154,8 +176,6 @@ func WithSendInterval(interval time.Duration) Option {
154176
}
155177
}
156178

157-
// --- HTTPSBatchWriter definition ---
158-
159179
// HTTPSBatchWriter is an egress.WriteCloser implementation that batches syslog messages
160180
// and sends them via HTTPS in configurable batch sizes and intervals. It provides
161181
// backpressure to upstream callers by using a blocking channel for incoming messages.

src/pkg/egress/syslog/https_batch_retryer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var _ = Describe("Retryer", func() {
4444
It("retries the specified number of times on failure", func() {
4545
retryer.Retry([]byte("test-batch"), 10, func(batch []byte, msgCount float64) error {
4646
retryAttempts++
47-
return errors.New("wtf")
47+
return errors.New("test error")
4848
})
4949

5050
Expect(retryAttempts).To(Equal(3)) // Retries up to maxRetries

0 commit comments

Comments
 (0)