in agent/healthcheck/health_check.go [92:142]
func (healthStatus *HealthStatus) computeHealthStatus(
pollData *EnvoyEndpointHttpData,
messageSources *messagesources.MessageSources,
agentConfig config.AgentConfig) {
healthStatus.AgentUptime = fmt.Sprintf("%.fs", time.Since(pollData.agentStartTime).Seconds())
healthStatus.EnvoyPid = strconv.Itoa(messageSources.GetPid())
healthStatus.EnvoyRestartCount = strconv.Itoa(messageSources.GetProcessRestartCount())
// Get readiness response from '/ready' endpoint of Envoy admin interface
// https://www.envoyproxy.io/docs/envoy/latest/operations/admin#get--ready
// Should output a string and error code reflecting the state of the server.
// 200 is returned for the LIVE state, and 503 otherwise.
response, err := pollData.client.Do(pollData.readyReq)
if err != nil {
log.Error("Envoy readiness check failed with: ", err)
healthStatus.EnvoyState = "UNREACHABLE"
}
if response != nil {
responseBody, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Warn("Envoy readiness check failed to read response with: ", err)
}
healthStatus.EnvoyState = strings.TrimSpace(string(responseBody))
log.Debugf("Envoy readiness check status %d, %s",
response.StatusCode, healthStatus.EnvoyState)
response.Body.Close()
}
response, err = pollData.client.Do(pollData.statsReq)
if err != nil {
log.Error("Envoy connectivity check failed with: ", err)
}
if response != nil {
responseBody, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Warn("Envoy connectivity check failed to read response with: ", err)
}
if !agentConfig.EnableRelayModeForXds {
// Get `control_plane.connected_state` from Envoy admin interface
log.Debugf("Envoy connectivity check status %d, %s",
response.StatusCode, string(responseBody))
healthStatus.computeManagementServerConnectionStatus(string(responseBody))
}
healthStatus.computeEnvoyReadinessState(string(responseBody))
response.Body.Close()
}
healthStatus.computeHealthCheck(agentConfig)
}