-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 : Add in support for looking for substring in response #2204
Conversation
this looks good but I think it should support regex as well |
|
||
// Check the response for a regex match | ||
if h.ResponseStringMatch != "" { | ||
regex, compile_err := regexp.Compile(h.ResponseStringMatch) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change compile_err to err
if h.ResponseStringMatch != "" { | ||
regex, compile_err := regexp.Compile(h.ResponseStringMatch) | ||
if compile_err != nil { | ||
fields["response_string_match"] = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print an Error log message here to indicate that the regex compile failed
fields["response_string_match"] = 0 | ||
} | ||
|
||
bodyBytes, _ := ioutil.ReadAll(resp.Body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you shouldn't move on and read the response body if the regex compile failed
@@ -23,6 +23,11 @@ This input plugin will test HTTP/HTTPS connections. | |||
# {'fake':'data'} | |||
# ''' | |||
|
|||
## Optional : Look for substring in body of the response | |||
# response_string_match = "\"service_status\": \"up\"" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than the or
, you should put a list of examples above with two ##
in front of it
Looks like a missing docker image for testing docker run --name aerospike -p "3000:3000" -d aerospike/aerospike-server:3.9.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comments
@@ -54,6 +58,11 @@ var sampleConfig = ` | |||
# {'fake':'data'} | |||
# ''' | |||
|
|||
## Optional : Look for substring in body of the response. Can use regex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change the sample config here to match the README
fields["response_string_match"] = 0 | ||
} else { | ||
|
||
bodyBytes, _ := ioutil.ReadAll(resp.Body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't ignore the error here. If there is an error, log it and continue.
} else { | ||
|
||
bodyBytes, _ := ioutil.ReadAll(resp.Body) | ||
bodyString := string(bodyBytes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not convert the response body to a string, you can use regex.Match below (instead of regex.MatchString)
@@ -54,6 +58,11 @@ var sampleConfig = ` | |||
# {'fake':'data'} | |||
# ''' | |||
|
|||
## Optional substring or regex match in body of the response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 spaces instead of a tab here
|
||
// Check the response for a regex match | ||
if h.ResponseStringMatch != "" { | ||
regex, err := regexp.Compile(h.ResponseStringMatch) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you still need to change this to only compile the regex once
looking good, just a few more changes |
…nfluxdata#2204) * Add in support for looking for substring in response * Add note to CHANGELOG.md * Switch from substring match to regex match * Requested code changes * Make requested changes and refactor to avoid nested if-else. * Convert tabs to space and compile regex once
…2204) * Add in support for looking for substring in response * Add note to CHANGELOG.md * Switch from substring match to regex match * Requested code changes * Make requested changes and refactor to avoid nested if-else. * Convert tabs to space and compile regex once
When hitting a HTTP health_check it will return a valid HTTP status but will have an "healthy" or "un-healthy" message in the response. I've extended http_response to allow to specify a substring to search for in the HTTP response and return a metric of 1 if found, 0 if not. This would allow the metric to be passed or be pulled by monitoring.
Required for all PRs: