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

Fix bug with httpjson client pointer receiver #861

Merged
merged 1 commit into from
Mar 16, 2016
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## v0.11.1 [unreleased]

### Features

### Bugfixes
- [#852](https://github.com/influxdata/telegraf/issues/852): Windows zip package fix
- [#859](https://github.com/influxdata/telegraf/issues/859): httpjson plugin panic

## v0.11.0 [2016-03-15]

### Release Notes
Expand Down
10 changes: 6 additions & 4 deletions plugins/inputs/httpjson/httpjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ type RealHTTPClient struct {
client *http.Client
}

func (c RealHTTPClient) MakeRequest(req *http.Request) (*http.Response, error) {
func (c *RealHTTPClient) MakeRequest(req *http.Request) (*http.Response, error) {
return c.client.Do(req)
}

func (c RealHTTPClient) SetHTTPClient(client *http.Client) {
func (c *RealHTTPClient) SetHTTPClient(client *http.Client) {
c.client = client
}

func (c RealHTTPClient) HTTPClient() *http.Client {
func (c *RealHTTPClient) HTTPClient() *http.Client {
return c.client
}

Expand Down Expand Up @@ -289,6 +289,8 @@ func (h *HttpJson) sendRequest(serverURL string) (string, float64, error) {

func init() {
inputs.Add("httpjson", func() telegraf.Input {
return &HttpJson{client: RealHTTPClient{}}
return &HttpJson{
client: &RealHTTPClient{},
}
})
}
16 changes: 8 additions & 8 deletions plugins/inputs/httpjson/httpjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ type mockHTTPClient struct {
// Mock implementation of MakeRequest. Usually returns an http.Response with
// hard-coded responseBody and statusCode. However, if the request uses a
// nonstandard method, it uses status code 405 (method not allowed)
func (c mockHTTPClient) MakeRequest(req *http.Request) (*http.Response, error) {
func (c *mockHTTPClient) MakeRequest(req *http.Request) (*http.Response, error) {
resp := http.Response{}
resp.StatusCode = c.statusCode

Expand All @@ -147,10 +147,10 @@ func (c mockHTTPClient) MakeRequest(req *http.Request) (*http.Response, error) {
return &resp, nil
}

func (c mockHTTPClient) SetHTTPClient(_ *http.Client) {
func (c *mockHTTPClient) SetHTTPClient(_ *http.Client) {
}

func (c mockHTTPClient) HTTPClient() *http.Client {
func (c *mockHTTPClient) HTTPClient() *http.Client {
return nil
}

Expand All @@ -164,7 +164,7 @@ func (c mockHTTPClient) HTTPClient() *http.Client {
func genMockHttpJson(response string, statusCode int) []*HttpJson {
return []*HttpJson{
&HttpJson{
client: mockHTTPClient{responseBody: response, statusCode: statusCode},
client: &mockHTTPClient{responseBody: response, statusCode: statusCode},
Servers: []string{
"http://server1.example.com/metrics/",
"http://server2.example.com/metrics/",
Expand All @@ -181,7 +181,7 @@ func genMockHttpJson(response string, statusCode int) []*HttpJson {
},
},
&HttpJson{
client: mockHTTPClient{responseBody: response, statusCode: statusCode},
client: &mockHTTPClient{responseBody: response, statusCode: statusCode},
Servers: []string{
"http://server3.example.com/metrics/",
"http://server4.example.com/metrics/",
Expand Down Expand Up @@ -241,7 +241,7 @@ func TestHttpJsonGET_URL(t *testing.T) {
Servers: []string{ts.URL + "?api_key=mykey"},
Name: "",
Method: "GET",
client: RealHTTPClient{client: &http.Client{}},
client: &RealHTTPClient{client: &http.Client{}},
}

var acc testutil.Accumulator
Expand Down Expand Up @@ -314,7 +314,7 @@ func TestHttpJsonGET(t *testing.T) {
Name: "",
Method: "GET",
Parameters: params,
client: RealHTTPClient{client: &http.Client{}},
client: &RealHTTPClient{client: &http.Client{}},
}

var acc testutil.Accumulator
Expand Down Expand Up @@ -388,7 +388,7 @@ func TestHttpJsonPOST(t *testing.T) {
Name: "",
Method: "POST",
Parameters: params,
client: RealHTTPClient{client: &http.Client{}},
client: &RealHTTPClient{client: &http.Client{}},
}

var acc testutil.Accumulator
Expand Down