-
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
Add result_type field for http_response input #2814
Conversation
82fc8c8
to
9d523b6
Compare
if h.FollowRedirects { | ||
return nil, err | ||
log.Printf("E! Failed to open HTTP connection: %s", err) | ||
return fields, nil |
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.
Why are we directly logging the error instead of returning it?
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.
The other option would be to give the the fields and the errors one level up and logging the errors there. I thought about that and my reasoning to do it this way is the following:
Currently we either return the fields or the error and this would break this pattern. In my opinion the way I chose is a little easier to understand.
However I don't have a strong opinion on it. I can change it, if it's important for you.
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.
The reason I bring it up is 2 things. Doing it this way results in the log messages not having context. Meaning that if you have multiple inputs defined, you don't know which one is generating the error. The other problem is that I think we have an open issue somewhere to track statistics on per-input error counts, which requires errors going through Accumulator.AddError()
.
Check out my comment on #2784. |
9d523b6
to
5e37c54
Compare
@phemmer I amended my commit to reflect your comments. Can you have a look? |
5e37c54
to
3847faf
Compare
I updated the pull request to reflect the discussion in #2784 |
3847faf
to
585326b
Compare
if h.FollowRedirects { | ||
return nil, err | ||
return fields, err |
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.
In general, returning an error indicates that the value is not valid, if we are returning fields then we shouldn't have an error. Later on, we will need to make sure we don't call AddFields if it is nil.
if err != nil { | ||
fields["http_response_code"] = -1 | ||
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.
There was no response so these fields should not be set.
if netErr, ok := err.(net.Error); ok && netErr.Timeout() { | ||
fields["response_timeout"] = time.Since(start).Seconds() | ||
} else { | ||
fields["response_time"] = time.Since(start).Seconds() |
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.
I think this goes away too, there was no response.
585326b
to
f5cfa58
Compare
Thanks for your comments. I updated the pull request to reflect them :) |
f5cfa58
to
a43a168
Compare
@@ -148,6 +154,7 @@ func (h *HTTPResponse) httpGather() (map[string]interface{}, error) { | |||
|
|||
fields["response_time"] = time.Since(start).Seconds() | |||
fields["http_response_code"] = resp.StatusCode | |||
fields["connection_failed"] = 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.
@phemmer What do you think, should we return this field if everything went okay?
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.
My thoughts:
It looks like we have 3 different fields that behave similarly, connection_failed, response_timeout, and response_string_match. This feels wrong to me. All three fields are exclusive of each other. You'll never have more than one of them true. So it seems like we should instead have one field which indicates the result. Something like result_type
with the values connection failed
/timeout
/response mismatch
/response match
.
If we do keep them separate fields, I would at least argue that they should be booleans, not ints.
And that I think the field should be emitted, just set to false.
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.
One consequence of combining them is that we would not be able to store how long the timeout took, but maybe we don't care about this since it is basically set by hand.
Interesting idea to work match/mismatch in, do you think we would leave the field off if no match string is provided? Perhaps we have a success result_type?
I was letting the int slide here because this plugin already has the response match field with one, but yeah in general we should use booleans.
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.
I think it is a good idea to always return a status whether the connection failed or not. If someone (i.e. me) wants to gather the latest value of the status and it is only returned when an error occured the value is always "error".
Do we have a plan if we want to combine the fields and if so: how?
I can change the int fields to boolean if you want, however that would mean a breaking change for the response_match field.
Sorry for the late reply, we had public holidays in Germany and I had to go rock climbing ;)
} | ||
// Add metrics | ||
acc.AddFields("http_response", fields, tags) |
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.
Should be able to remove both of these hunks, returning an error works the same as AddError with return nil.
a43a168
to
727a7b9
Compare
@danielnelson, @phemmer Do we have a plan for the "connection_failed" field? Currently I have the feeling that we are kind of stuck in the discussion of how to deal with the flag-fields. I think it is an important discussion and I appreciate that you take it seriously. But to be honest my current main concern is "getting the bug fixed soon, so that my alerting system is reliable". |
As usual, @phemmer's solution is quite a bit better than the one i suggested earlier, so how about:
Even with this change, it would probably be a good idea to make sure you are alerting if the measurement you are looking for stops being reported. |
727a7b9
to
de3b6c4
Compare
Done :) Please have a look |
de3b6c4
to
683725a
Compare
Leave the old response_string_mismatch field around so we don't break anything. |
683725a
to
c4fa8f4
Compare
@danielnelson done :) |
@froth It's in! Thanks and sorry about all the backtracking while we figured out what to do. |
Fix for #2784 & #2624.
Does return measurement data even if no http connection can be established.
This is based on pull request #2813, as it depends on the fixes.
Required for all PRs: