-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add /liveness route to metrics server. This route will report the status from pkg/core/status. fleet-gateway will now report a degraded state if a checkin fails. This may not propogate to fleet-server as a failed checkin means communications between the agent and the server are not working. It may also lead to the server reporting degraded for up to 30s (fleet-server polling time) when teh agent is able to successfully connect.
- Loading branch information
1 parent
fa82d1a
commit 3b3fee7
Showing
10 changed files
with
313 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package status | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
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, | ||
} | ||
status := 200 | ||
if s.Status != Healthy { | ||
status = 503 | ||
} | ||
|
||
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) | ||
} | ||
} |
Oops, something went wrong.