Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #33 Support for http.client timeout #35

Merged
merged 3 commits into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Changelog for go-wavefront.

## [1.5.0]

*Feature to configure http client timeout*

- Expose http client timeout parameter

## [1.4.0]

*Add Missing Fields to Dashboards*
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ vet:
fi

errcheck:
@sh -c "'$(CURDIR)/scripts/errcheck.sh'" | grep -v example
@sh -c "'$(CURDIR)/scripts/errcheck.sh'"

test: fmtcheck
go test -i $(TEST) || exit 1
Expand Down
23 changes: 17 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"time"
)

// Wavefronter is an interface that a Wavefront client must satisfy
Expand All @@ -28,6 +29,10 @@ type Config struct {
// Token is an authentication token that will be passed with all requests
Token string

// Timeout exposes the http client timeout
// https://golang.org/src/net/http/client.go
Timeout time.Duration

// SET HTTP Proxy configuration
HttpProxy string

Expand Down Expand Up @@ -59,15 +64,21 @@ func NewClient(config *Config) (*Client, error) {
return nil, err
}

// Added timeout to http client
// Timeout of zero means no timeout
h := &http.Client{
Timeout: config.Timeout,
Transport: &http.Transport{
TLSNextProto: map[string]func(authority string, c *tls.Conn) http.RoundTripper{},
},
}

// need to disable http/2 as it doesn't play nicely with nginx
// to do so we set TLSNextProto to an empty, non-nil map
c := &Client{Config: config,
c := &Client{
Config: config,
BaseURL: baseURL,
httpClient: &http.Client{
Transport: &http.Transport{
TLSNextProto: map[string]func(authority string, c *tls.Conn) http.RoundTripper{},
},
},
httpClient: h,
debug: false,
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/errcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ err_files=$(errcheck -ignoretests \
-ignore 'github.com/hashicorp/terraform/helper/schema:Set' \
-ignore 'bytes:.*' \
-ignore 'io:Close|Write' \
$(go list ./...| grep -v /vendor/))
$(go list ./...| grep -v /vendor/ | grep -v examples))

if [[ -n ${err_files} ]]; then
echo 'Unchecked errors found in the following places:'
Expand Down