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

Http response fixes #3814

Merged
merged 25 commits into from
Mar 8, 2018
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cf87092
Http_response input: Reorder, simplify and comment error handling code
Feb 18, 2018
a0f52b0
http_response input: fix typo in comment
Feb 18, 2018
0f23ab0
http_response input: Add options to log the response time even in the…
Feb 18, 2018
a9c8e72
http_response input: Add tags containing the http code and a field wi…
Feb 21, 2018
be3520d
http_response input: Remove feature to add a fixed latency in case of…
Feb 21, 2018
9c44462
http_response input: Fix confusing error handling when the body regex…
Feb 21, 2018
6436ff0
http_response input: Remove flags
Feb 21, 2018
de49945
http_response input: Factor out network error processing
Feb 21, 2018
319b66f
http_response input: Add handling error types other than timeout
Feb 21, 2018
a3722e7
http_response input: Update documentation
Feb 22, 2018
7627aa9
http_response: Fix broken timeout error handling
Feb 22, 2018
81722d8
http_response input: Add testing helper functions to eliminate repeat…
Feb 24, 2018
02dd69c
http_response input: Fix a couple of bugs in the helper functions
Feb 24, 2018
b80d0ff
http_response input: Reformat maps that ran past column 80
Feb 24, 2018
8ab127c
http_response input: Make test more rigorous, including exactly what …
Feb 25, 2018
17c8929
http_response input: Add tests for network errors and the plugin's in…
Feb 25, 2018
fb2f83b
http_response input: Remove UnknownNetwork and Address network error …
Feb 25, 2018
d6e1ecc
http_response input: Update README
Feb 25, 2018
817fb66
http_response input: Run make fmt
Feb 25, 2018
1751563
http_response input:
Mar 6, 2018
4c1e52c
http_response input:
Mar 6, 2018
69be2a8
http_response input:
Mar 6, 2018
cc3a0cd
http_response input:
Mar 6, 2018
7029079
http_response input:
Mar 6, 2018
927ec73
http_response input:
Mar 6, 2018
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
Prev Previous commit
Next Next commit
http_response input: Add tests for network errors and the plugin's in…
…ternal errors
  • Loading branch information
Germán Jaber committed Feb 25, 2018
commit 17c89298fde158977068b02e27a439e59d4630b3
91 changes: 90 additions & 1 deletion plugins/inputs/http_response/http_response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ func TestPluginErrors(t *testing.T) {
ts := httptest.NewServer(mux)
defer ts.Close()

// Bad regex test
// Bad regex test. Should return an error and return nothing
h := &HTTPResponse{
Address: ts.URL + "/good",
Body: "{ 'test': 'data'}",
Expand All @@ -598,4 +598,93 @@ func TestPluginErrors(t *testing.T) {
var acc testutil.Accumulator
err := h.Gather(&acc)
require.Error(t, err)

absentFields := []string{"http_response_code", "response_time", "response_string_match", "result_type", "result_code"}
absentTags := []string{"status_code", "result", "server", "method"}
checkOutput(t, acc, nil, nil, absentFields, absentTags)

// Attempt to read empty body test
h = &HTTPResponse{
Address: ts.URL + "/redirect",
Body: "",
Method: "GET",
ResponseStringMatch: ".*",
ResponseTimeout: internal.Duration{Duration: time.Second * 20},
FollowRedirects: false,
}

acc = testutil.Accumulator{}
err = h.Gather(&acc)
require.NoError(t, err)

expectedFields := map[string]interface{}{
"http_response_code": http.StatusMovedPermanently,
"response_string_match": 0,
"result_type": "body_read_error",
"result_code": 2,
"response_time": nil,
}
expectedTags := map[string]interface{}{
"server": nil,
"method": "GET",
"status_code": "301",
"result": "body_read_error",
}
checkOutput(t, acc, expectedFields, expectedTags, nil, nil)
}

func TestNetworkErrors(t *testing.T) {
// DNS error
h := &HTTPResponse{
Address: "https://nonexistent.nonexistent", // Any non-resolvable URL works here
Body: "",
Method: "GET",
ResponseTimeout: internal.Duration{Duration: time.Second * 20},
FollowRedirects: false,
LogNetworkErrors: true,
}

var acc testutil.Accumulator
err := h.Gather(&acc)
require.NoError(t, err)

expectedFields := map[string]interface{}{
"result_type": "dns_error",
"result_code": 5,
}
expectedTags := map[string]interface{}{
"server": nil,
"method": "GET",
"result": "dns_error",
}
absentFields := []string{"http_response_code", "response_time", "response_string_match"}
absentTags := []string{"status_code"}
checkOutput(t, acc, expectedFields, expectedTags, absentFields, absentTags)

// Connecton failed
h = &HTTPResponse{
Address: "https://127.127.127.127", // Any non-routable IP works here
Body: "",
Method: "GET",
ResponseTimeout: internal.Duration{Duration: time.Second * 20},
FollowRedirects: false,
LogNetworkErrors: true,
}

acc = testutil.Accumulator{}
err = h.Gather(&acc)
require.NoError(t, err)

expectedFields = map[string]interface{}{
"result_type": "connection_failed",
"result_code": 3,
}
expectedTags = map[string]interface{}{
"server": nil,
"method": "GET",
"result": "connection_failed",
}
absentFields = []string{"http_response_code", "response_time", "response_string_match"}
absentTags = []string{"status_code"}
checkOutput(t, acc, expectedFields, expectedTags, absentFields, absentTags)
}