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

Commit

Permalink
Resolved conflict while merging branch based off master to 6.3.x
Browse files Browse the repository at this point in the history
[proc] shorten timeout value, trim code
  • Loading branch information
shang-wang committed Jul 10, 2018
1 parent 2d57874 commit 7228f2a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion agent/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"context"
"io"
"io/ioutil"
"math/rand"
Expand Down Expand Up @@ -59,7 +60,7 @@ func NewCollector(cfg *config.AgentConfig) (Collector, error) {
rtIntervalCh: make(chan time.Duration),
cfg: cfg,
groupID: rand.Int31(),
httpClient: http.Client{Transport: cfg.Transport},
httpClient: http.Client{Timeout: HTTPTimeout, Transport: cfg.Transport},
enabledChecks: enabledChecks,

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

ctx, cancel := context.WithTimeout(context.Background(), ReqCtxTimeout)
defer cancel()
req.WithContext(ctx)

resp, err := l.httpClient.Do(req)
if err != nil {
if isHTTPTimeout(err) {
Expand Down
8 changes: 8 additions & 0 deletions agent/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ package main

import (
"strings"
"time"
)

const (
// HTTPTimeout is the timeout in seconds for process-agent to send process payloads to DataDog
HTTPTimeout = 20 * time.Second
// ReqCtxTimeout is the timeout in seconds for process-agent to cancel POST request using context timeout
ReqCtxTimeout = 30 * time.Second
)

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

0 comments on commit 7228f2a

Please sign in to comment.