-
Notifications
You must be signed in to change notification settings - Fork 145
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
status identifies failing component, fleet gateway may report degraded, liveness endpoint added #569
status identifies failing component, fleet gateway may report degraded, liveness endpoint added #569
Changes from 6 commits
3b3fee7
41249f5
f2bba1a
c0da95c
e2b6e3c
7a7ac40
bcd1262
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package status | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
// LivenessResponse is the response body for the liveness endpoint. | ||
type LivenessResponse struct { | ||
ID string `json:"id"` | ||
Status string `json:"status"` | ||
Message string `json:"message"` | ||
UpdateTime time.Time `json:"update_timestamp"` | ||
} | ||
|
||
// ServeHTTP is an HTTP Handler for the status controller. | ||
// Respose code is 200 for a healthy agent, and 503 otherwise. | ||
// Response body is a JSON object that contains the agent ID, status, message, and the last status update time. | ||
func (r *controller) ServeHTTP(wr http.ResponseWriter, req *http.Request) { | ||
s := r.Status() | ||
lr := LivenessResponse{ | ||
ID: r.agentID, | ||
Status: s.Status.String(), | ||
Message: s.Message, | ||
UpdateTime: s.UpdateTime, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will give the overall agent status, and to have per input we would need v2 is that correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is for the agent liveness, endpoints for inputs/units can be added later when v2 status reporting has been implemented. |
||
status := http.StatusOK | ||
if s.Status != Healthy { | ||
status = http.StatusServiceUnavailable | ||
} | ||
|
||
wr.Header().Set("Content-Type", "application/json") | ||
wr.WriteHeader(status) | ||
enc := json.NewEncoder(wr) | ||
if err := enc.Encode(lr); err != nil { | ||
r.log.Errorf("Unable to encode liveness response: %v", err) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @michel-laterman When we add the new information for the liveness check we refactor the handler do a dependency injection style and have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this is probably going to be the case for the v2 implementation. |
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.
Can we put that magic number into a constant?
IRC, this mean that if Agent is not able to reach Fleet-Server for 1 min (assuming 30sec backoff?), it will me marked has failed?
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 so, the wait function in the loop is an exponential backoff