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

Conversation

mirath
Copy link
Contributor

@mirath mirath commented Feb 21, 2018

This merge request aims to solve #3803 #3802 and #3801. These issues pertain mainly some bugs in the http_response input plugin and making the metrics that it generates Prometheus friendly

Work in progress, do not merge

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

Germán Jaber added 19 commits February 18, 2018 00:24
… failed to

                     compile or the plugin failed to read the response body
…tags/fields are expected to be present/absent and with what values
…processing

the net/http library was not reliably outputing accurate error types for these, so they were dropped
@mirath
Copy link
Contributor Author

mirath commented Feb 25, 2018

@danielnelson This PR is ready for review.

One thing that bothers me, I discovered that the plugin doesn't capitalize the method used before adding it as a tag, so if you set method to get, the tag will be lower case. If I would've designed the plugin, I would've standardized the capitalization of the method tag. I don't know why would you not capitalize it, and the change might break some dashboards, so I'm hesitant to 'fix' it. What do you think?

h.compiledStringMatch, err = regexp.Compile(h.ResponseStringMatch)
if err != nil {
log.Printf("E! Failed to compile regular expression %s : %s", h.ResponseStringMatch, err)
return err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just return the decorated error here and it will be logged:

return fmt.Errorf("failed to compile regular expression %s: %s", h.ResponseStringMatch, err)

@@ -113,18 +119,63 @@ func (h *HTTPResponse) createHttpClient() (*http.Client, error) {
return client, nil
}

func set_result(result_string string, fields *map[string]interface{}, tags *map[string]string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for pointers to maps, since they are shallow copies anyway. Also use normal Go camelCase naming convention on function names and variable names:

func setResult(resultString string, fields map[string]interface{}, tags map[string]string) {

}

func set_error(err error, fields *map[string]interface{}, tags *map[string]string) error {
if timeoutError, ok := err.(net.Error); ok && timeoutError.Timeout() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function can be improved by using a type switch

@@ -24,6 +24,10 @@ This input plugin will test HTTP/HTTPS connections.
# {'fake':'data'}
# '''

# Log network errors in the Telegraf log
# Turned off by default to avoid filling the logs with exessive repetitive strings
# log_network_errors = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this option log the network issues at debug level with log.Printf("D! foo")


### Example Output:

```
http_response,method=GET,server=http://www.github.com http_response_code=200i,response_time=6.223266528 1459419354977857955
http_response,method=GET,server=http://www.github.com,status_code="200",result="sucess" http_response_code=200i,response_time=6.223266528,result_type="sucess",result_code="0" 1459419354977857955
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example output should have int result_code, also typo in "success".

@danielnelson
Copy link
Contributor

On the method thing, I agree that it would have been nice to uppercase but I think just leave it how it is to avoid a breaking change.

Germán Jaber added 6 commits March 5, 2018 23:57
Remove `log_network_errors` option in favor of logging all errors annotated so
they only show in debug mode
Fix typos in docs
Return error in case the regex fails to compile, instead of
logging and returning no metrics
Simplify funcions signatures and use camelcase instead of underscores
for a couple of function names
Remove log_network_errors option from tests
Add type switch in the error handling routines to make them more clear
@danielnelson danielnelson merged commit 81a93fc into influxdata:master Mar 8, 2018
@danielnelson danielnelson added this to the 1.6.0 milestone Mar 8, 2018
@danielnelson
Copy link
Contributor

Thanks, it's in for 1.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants