in images/airflow/2.9.2/python/mwaa/subprocess/conditions.py [0:0]
def _check(self, process_status: ProcessStatus) -> ProcessConditionResponse:
"""
Execute the condition and return the response.
:returns A ProcessConditionResponse containing data about the response.
"""
if self.socket is None:
raise RuntimeError(
"Unexpected error: socket object and start time shouldn't be None."
)
try:
status, _ = self.socket.recvfrom(SOCKET_BUFFER_SIZE)
status = status.decode("utf-8")
match status.lower():
case "red":
response = ProcessConditionResponse(
condition=self,
successful=False,
message=f"Status received from sidecar: {status}",
)
logger.error(response.message)
case "blue" | "yellow":
# We treat blue/yellow as healthy to avoid unnecessary restarts,
# but we log a warning.
response = ProcessConditionResponse(
condition=self,
successful=True,
message=f"Status received from sidecar: {status}",
)
logger.warning(response.message)
case "healthy":
response = ProcessConditionResponse(
condition=self,
successful=True,
message=f"Status received from sidecar: {status}",
)
logger.info(response.message)
case _:
response = ProcessConditionResponse(
condition=self,
successful=True,
message=f"Unexpected response retrieved from sidecar: {status}. "
"Treating the status as HEALTHY. This may be a false positive "
"so it should be investigated, unless it is happening at the "
"start of the container before the sidecar monitoring is up "
"and emitting health indicators.",
)
logger.warning(response.message)
except Exception:
if (
time.time() - self.container_start_time
> _SIDECAR_WAIT_PERIOD.total_seconds()
):
response = ProcessConditionResponse(
condition=self,
successful=True,
message="Reading the health status from the sidecar timed out. "
"Unable to positively determine health, so assuming healthy. This "
"may be a false positive so it should be investigated.",
)
logger.error(response.message, exc_info=sys.exc_info())
else:
response = ProcessConditionResponse(
condition=self,
successful=True,
message="Reading the health status from the sidecar timed out, but "
"ignoring this since the container just started, so the sidecar "
"monitoring might not have been initialized yet.",
)
logger.info(response.message)
if not response.successful:
self._generate_autorestart_plog()
return response