Skip to content
This repository was archived by the owner on Jul 27, 2023. It is now read-only.

Commit 7228f2a

Browse files
committed
Resolved conflict while merging branch based off master to 6.3.x
[proc] shorten timeout value, trim code
1 parent 2d57874 commit 7228f2a

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

agent/collector.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"bytes"
5+
"context"
56
"io"
67
"io/ioutil"
78
"math/rand"
@@ -59,7 +60,7 @@ func NewCollector(cfg *config.AgentConfig) (Collector, error) {
5960
rtIntervalCh: make(chan time.Duration),
6061
cfg: cfg,
6162
groupID: rand.Int31(),
62-
httpClient: http.Client{Transport: cfg.Transport},
63+
httpClient: http.Client{Timeout: HTTPTimeout, Transport: cfg.Transport},
6364
enabledChecks: enabledChecks,
6465

6566
// Defaults for real-time on start
@@ -180,6 +181,10 @@ func (l *Collector) postMessage(endpoint string, m model.MessageBody) {
180181
req.Header.Add("X-Dd-Hostname", l.cfg.HostName)
181182
req.Header.Add("X-Dd-Processagentversion", Version)
182183

184+
ctx, cancel := context.WithTimeout(context.Background(), ReqCtxTimeout)
185+
defer cancel()
186+
req.WithContext(ctx)
187+
183188
resp, err := l.httpClient.Do(req)
184189
if err != nil {
185190
if isHTTPTimeout(err) {

agent/util.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ package main
22

33
import (
44
"strings"
5+
"time"
6+
)
7+
8+
const (
9+
// HTTPTimeout is the timeout in seconds for process-agent to send process payloads to DataDog
10+
HTTPTimeout = 20 * time.Second
11+
// ReqCtxTimeout is the timeout in seconds for process-agent to cancel POST request using context timeout
12+
ReqCtxTimeout = 30 * time.Second
513
)
614

715
// IsTimeout returns true if the error is due to reaching the timeout limit on the http.client

0 commit comments

Comments
 (0)