@@ -171,9 +171,7 @@ func (s *httpLineSender) Flush(ctx context.Context) error {
171
171
172
172
func (s * httpLineSender ) flush0 (ctx context.Context , closing bool ) error {
173
173
var (
174
- req * http.Request
175
- retryInterval time.Duration
176
-
174
+ retryInterval time.Duration
177
175
maxRetryInterval = time .Second
178
176
)
179
177
@@ -198,25 +196,7 @@ func (s *httpLineSender) flush0(ctx context.Context, closing bool) error {
198
196
// Always reset the buffer at the end of flush.
199
197
defer s .buf .Reset ()
200
198
201
- // We rely on the following HTTP client implicit behavior:
202
- // s.buf implements WriteTo method which is used by the client.
203
- req , err = http .NewRequest (
204
- http .MethodPost ,
205
- s .uri ,
206
- bytes .NewReader (s .buf .Bytes ()),
207
- )
208
- if err != nil {
209
- return err
210
- }
211
- req .ContentLength = int64 (s .BufLen ())
212
-
213
- if s .user != "" && s .pass != "" {
214
- req .SetBasicAuth (s .user , s .pass )
215
- } else if s .token != "" {
216
- req .Header .Add ("Authorization" , fmt .Sprintf ("Bearer %s" , s .token ))
217
- }
218
-
219
- retry , err := s .makeRequest (ctx , req )
199
+ retry , err := s .makeRequest (ctx )
220
200
if ! retry {
221
201
s .refreshFlushDeadline (err )
222
202
return err
@@ -234,7 +214,7 @@ func (s *httpLineSender) flush0(ctx context.Context, closing bool) error {
234
214
jitter := time .Duration (rand .Intn (10 )) * time .Millisecond
235
215
time .Sleep (retryInterval + jitter )
236
216
237
- retry , err = s .makeRequest (ctx , req )
217
+ retry , err = s .makeRequest (ctx )
238
218
if ! retry {
239
219
s .refreshFlushDeadline (err )
240
220
return err
@@ -358,7 +338,23 @@ func (s *httpLineSender) At(ctx context.Context, ts time.Time) error {
358
338
}
359
339
360
340
// makeRequest returns a boolean if we need to retry the request
361
- func (s * httpLineSender ) makeRequest (ctx context.Context , req * http.Request ) (bool , error ) {
341
+ func (s * httpLineSender ) makeRequest (ctx context.Context ) (bool , error ) {
342
+ req , err := http .NewRequest (
343
+ http .MethodPost ,
344
+ s .uri ,
345
+ bytes .NewReader (s .buf .Bytes ()),
346
+ )
347
+ if err != nil {
348
+ return false , err
349
+ }
350
+ req .ContentLength = int64 (s .BufLen ())
351
+
352
+ if s .user != "" && s .pass != "" {
353
+ req .SetBasicAuth (s .user , s .pass )
354
+ } else if s .token != "" {
355
+ req .Header .Add ("Authorization" , fmt .Sprintf ("Bearer %s" , s .token ))
356
+ }
357
+
362
358
// reqTimeout = ( request.len() / min_throughput ) + request_timeout
363
359
// nb: conversion from int to time.Duration is in milliseconds
364
360
reqTimeout := time .Duration (s .buf .Len ()/ s .minThroughputBytesPerSecond )* time .Second + s .requestTimeout
0 commit comments