44 "bytes"
55 "crypto/tls"
66 "log"
7+ "net/url"
78 "sync"
89 "time"
910
@@ -13,6 +14,19 @@ import (
1314 "github.com/valyala/fasthttp"
1415)
1516
17+ // --- Common Definitions ---
18+
19+ // redactedURL returns a copy of the URL with user info and query parameters removed for safe logging.
20+ func redactedURL (u * url.URL ) string {
21+ if u == nil {
22+ return ""
23+ }
24+ redacted := * u
25+ redacted .User = nil
26+ redacted .RawQuery = ""
27+ return redacted .String ()
28+ }
29+
1630// --- Retry Coordinator Definition ---
1731
1832// RetryCoordinator provides global concurrency control for retry operations
@@ -50,13 +64,13 @@ func GetGlobalRetryCoordinator() *RetryCoordinator {
5064 return globalRetryCoordinator
5165}
5266
53- func (c * RetryCoordinator ) Acquire (URL string ) {
67+ func (c * RetryCoordinator ) Acquire (URL string , appId string ) {
5468 select {
5569 case c .sem <- struct {}{}:
5670 return
5771 default :
58- log .Printf ("All retry slots (%d) are in use. Log delivery for %s may be delayed." ,
59- maxParallelRetries , URL )
72+ log .Printf ("All retry slots (%d) are in use. Log delivery for %s for application %s may be delayed." ,
73+ maxParallelRetries , URL , appId )
6074 c .sem <- struct {}{}
6175 }
6276}
@@ -111,36 +125,36 @@ func (r *Retryer) Retry(batch []byte, msgCount float64, funcToRetry func([]byte,
111125 }
112126
113127 if egress .ContextDone (r .binding .Context ) {
114- log .Printf ("Context cancelled for %s, aborting retries" , r .binding .URL . Host )
128+ log .Printf ("Context cancelled for %s for application %s , aborting retries" , redactedURL ( r .binding .URL ), r . binding . AppID )
115129 return true
116130 }
117131
118- log .Printf ("Failed to write to %s, retrying in %s, err: %s" , r .binding .URL . Host , r .retryDuration (0 ), err )
132+ log .Printf ("Failed to write to %s for application %s , retrying in %s, err: %s" , redactedURL ( r .binding .URL ), r . binding . AppID , r .retryDuration (0 ), err )
119133
120134 for i := 0 ; i < r .maxRetries - 1 ; i ++ {
121135
122136 if egress .ContextDone (r .binding .Context ) {
123- log .Printf ("Context cancelled for %s, aborting retries" , r .binding .URL . Host )
137+ log .Printf ("Context cancelled for %s for application %s , aborting retries" , redactedURL ( r .binding .URL ), r . binding . AppID )
124138 return true
125139 }
126140
127141 sleepDuration := r .retryDuration (i )
128142 time .Sleep (sleepDuration )
129143
130- r .coordinator .Acquire (r .binding .URL . Host )
144+ r .coordinator .Acquire (redactedURL ( r .binding .URL ), r . binding . AppID )
131145 func () {
132146 defer r .coordinator .Release ()
133147 err = funcToRetry (batch , msgCount )
134148 }()
135149 if err == nil {
136150 return false
137151 }
138- log .Printf ("Failed to write to %s, retrying in %s, err: %s" , r .binding .URL . Host , r .retryDuration (i + 1 ), err )
152+ log .Printf ("Failed to write to %s for application %s , retrying in %s, err: %s" , redactedURL ( r .binding .URL ), r . binding . AppID , r .retryDuration (i + 1 ), err )
139153
140154 }
141155
142- log .Printf ("Exhausted retries for %s, dropping batch with %.0f messages, err: %s" ,
143- r .binding .URL . Host , msgCount , err )
156+ log .Printf ("Exhausted retries for %s for application %s , dropping batch with %.0f messages, err: %s" ,
157+ redactedURL ( r .binding .URL ), r . binding . AppID , msgCount , err )
144158 return true
145159}
146160
@@ -247,8 +261,8 @@ func (w *HTTPSBatchWriter) startSender() {
247261 if msgBatch .Len () > 0 {
248262 failed := w .retryer .Retry (msgBatch .Bytes (), msgCount , w .sendHttpRequest )
249263 if failed {
250- log .Printf ("Failed to deliver %.0f messages to %s after all retries, dropping batch" ,
251- msgCount , w .url . Host )
264+ log .Printf ("Failed to deliver %.0f messages to %s for application %s after all retries, dropping batch" ,
265+ msgCount , redactedURL ( w .url ), w . appID )
252266 }
253267 msgBatch .Reset ()
254268 msgCount = 0
0 commit comments