Skip to content

Commit 035e4cf

Browse files
committed
Fix bug with httpjson client pointer receiver
fixes influxdata#859
1 parent 18fff4a commit 035e4cf

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## v0.11.1 [unreleased]
2+
3+
### Features
4+
5+
### Bugfixes
6+
- [#852](https://github.com/influxdata/telegraf/issues/852): Windows zip package fix
7+
- [#859](https://github.com/influxdata/telegraf/issues/859): httpjson plugin panic
8+
19
## v0.11.0 [2016-03-15]
210

311
### Release Notes

plugins/inputs/httpjson/httpjson.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ type RealHTTPClient struct {
5555
client *http.Client
5656
}
5757

58-
func (c RealHTTPClient) MakeRequest(req *http.Request) (*http.Response, error) {
58+
func (c *RealHTTPClient) MakeRequest(req *http.Request) (*http.Response, error) {
5959
return c.client.Do(req)
6060
}
6161

62-
func (c RealHTTPClient) SetHTTPClient(client *http.Client) {
62+
func (c *RealHTTPClient) SetHTTPClient(client *http.Client) {
6363
c.client = client
6464
}
6565

66-
func (c RealHTTPClient) HTTPClient() *http.Client {
66+
func (c *RealHTTPClient) HTTPClient() *http.Client {
6767
return c.client
6868
}
6969

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

290290
func init() {
291291
inputs.Add("httpjson", func() telegraf.Input {
292-
return &HttpJson{client: RealHTTPClient{}}
292+
return &HttpJson{
293+
client: &RealHTTPClient{},
294+
}
293295
})
294296
}

plugins/inputs/httpjson/httpjson_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ type mockHTTPClient struct {
125125
// Mock implementation of MakeRequest. Usually returns an http.Response with
126126
// hard-coded responseBody and statusCode. However, if the request uses a
127127
// nonstandard method, it uses status code 405 (method not allowed)
128-
func (c mockHTTPClient) MakeRequest(req *http.Request) (*http.Response, error) {
128+
func (c *mockHTTPClient) MakeRequest(req *http.Request) (*http.Response, error) {
129129
resp := http.Response{}
130130
resp.StatusCode = c.statusCode
131131

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

150-
func (c mockHTTPClient) SetHTTPClient(_ *http.Client) {
150+
func (c *mockHTTPClient) SetHTTPClient(_ *http.Client) {
151151
}
152152

153-
func (c mockHTTPClient) HTTPClient() *http.Client {
153+
func (c *mockHTTPClient) HTTPClient() *http.Client {
154154
return nil
155155
}
156156

@@ -164,7 +164,7 @@ func (c mockHTTPClient) HTTPClient() *http.Client {
164164
func genMockHttpJson(response string, statusCode int) []*HttpJson {
165165
return []*HttpJson{
166166
&HttpJson{
167-
client: mockHTTPClient{responseBody: response, statusCode: statusCode},
167+
client: &mockHTTPClient{responseBody: response, statusCode: statusCode},
168168
Servers: []string{
169169
"http://server1.example.com/metrics/",
170170
"http://server2.example.com/metrics/",
@@ -181,7 +181,7 @@ func genMockHttpJson(response string, statusCode int) []*HttpJson {
181181
},
182182
},
183183
&HttpJson{
184-
client: mockHTTPClient{responseBody: response, statusCode: statusCode},
184+
client: &mockHTTPClient{responseBody: response, statusCode: statusCode},
185185
Servers: []string{
186186
"http://server3.example.com/metrics/",
187187
"http://server4.example.com/metrics/",
@@ -241,7 +241,7 @@ func TestHttpJsonGET_URL(t *testing.T) {
241241
Servers: []string{ts.URL + "?api_key=mykey"},
242242
Name: "",
243243
Method: "GET",
244-
client: RealHTTPClient{client: &http.Client{}},
244+
client: &RealHTTPClient{client: &http.Client{}},
245245
}
246246

247247
var acc testutil.Accumulator
@@ -314,7 +314,7 @@ func TestHttpJsonGET(t *testing.T) {
314314
Name: "",
315315
Method: "GET",
316316
Parameters: params,
317-
client: RealHTTPClient{client: &http.Client{}},
317+
client: &RealHTTPClient{client: &http.Client{}},
318318
}
319319

320320
var acc testutil.Accumulator
@@ -388,7 +388,7 @@ func TestHttpJsonPOST(t *testing.T) {
388388
Name: "",
389389
Method: "POST",
390390
Parameters: params,
391-
client: RealHTTPClient{client: &http.Client{}},
391+
client: &RealHTTPClient{client: &http.Client{}},
392392
}
393393

394394
var acc testutil.Accumulator

0 commit comments

Comments
 (0)