@@ -171,9 +171,7 @@ func (s *httpLineSender) Flush(ctx context.Context) error {
171171
172172func (s * httpLineSender ) flush0 (ctx context.Context , closing bool ) error {
173173 var (
174- req * http.Request
175- retryInterval time.Duration
176-
174+ retryInterval time.Duration
177175 maxRetryInterval = time .Second
178176 )
179177
@@ -198,25 +196,7 @@ func (s *httpLineSender) flush0(ctx context.Context, closing bool) error {
198196 // Always reset the buffer at the end of flush.
199197 defer s .buf .Reset ()
200198
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 )
220200 if ! retry {
221201 s .refreshFlushDeadline (err )
222202 return err
@@ -234,7 +214,7 @@ func (s *httpLineSender) flush0(ctx context.Context, closing bool) error {
234214 jitter := time .Duration (rand .Intn (10 )) * time .Millisecond
235215 time .Sleep (retryInterval + jitter )
236216
237- retry , err = s .makeRequest (ctx , req )
217+ retry , err = s .makeRequest (ctx )
238218 if ! retry {
239219 s .refreshFlushDeadline (err )
240220 return err
@@ -358,7 +338,23 @@ func (s *httpLineSender) At(ctx context.Context, ts time.Time) error {
358338}
359339
360340// 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+
362358 // reqTimeout = ( request.len() / min_throughput ) + request_timeout
363359 // nb: conversion from int to time.Duration is in milliseconds
364360 reqTimeout := time .Duration (s .buf .Len ()/ s .minThroughputBytesPerSecond )* time .Second + s .requestTimeout
0 commit comments