mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(mwaa): also detect a crashed sibling Postgres container, not just Airflow (#3454)
hasAirflowContainerExited only inspected the Airflow container. If the sibling Postgres container dies instead (out of memory, its volume filling up), Airflow keeps running but never reports metadatabase healthy, so the environment sat at CREATING exactly as before this existed, the same failure mode #3446 fixed for the Airflow container alone. Generalized into hasAnyContainerExited, backed by a shared per-container helper, checking both Environment.getDbContainerId() and getAirflowContainerId(). checkReadiness and its log messages updated to match; behavior for a lone Airflow-container failure is unchanged. Follow-up from hectorvent's review on #3446.
This commit is contained in:
1 parent
0a45d2e131
commit
fe076212c2
5 files changed
+70
-41
No files matched your search
+17
-10
@@ -264,15 +264,22 @@ public class MwaaEnvironmentManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* True when the Airflow container was created but is no longer running, for example because a
|
||||
* startup script or {@code airflow db migrate} failed after {@code docker start} returned.
|
||||
* {@code docker start} only launches the entrypoint and returns immediately, so nothing else
|
||||
* observes a failure like that; {@link MwaaService}'s readiness poller uses this to stop
|
||||
* waiting on a container that will never answer {@code /health}, instead of leaving the
|
||||
* environment at CREATING forever.
|
||||
* True when either container backing this environment, Postgres or Airflow, was created but is
|
||||
* no longer running: for example a startup script or {@code airflow db migrate} failing
|
||||
* partway through kills the Airflow container, or the Postgres container itself dies (out of
|
||||
* memory, its volume filling up), which never surfaces as an Airflow-side failure since the
|
||||
* Airflow process itself keeps running, just never reporting {@code metadatabase} healthy.
|
||||
* {@code docker start} only launches a container's entrypoint and returns immediately, so
|
||||
* nothing else observes either of those; {@link MwaaService}'s readiness poller uses this to
|
||||
* stop waiting on containers that will never let the environment answer {@code /health},
|
||||
* instead of leaving the environment at CREATING forever.
|
||||
*/
|
||||
public boolean hasAirflowContainerExited(Environment environment) {
|
||||
String containerId = environment.getAirflowContainerId();
|
||||
public boolean hasAnyContainerExited(Environment environment) {
|
||||
return hasContainerExited(environment.getDbContainerId(), "Postgres", environment)
|
||||
|| hasContainerExited(environment.getAirflowContainerId(), "Airflow", environment);
|
||||
}
|
||||
|
||||
private boolean hasContainerExited(String containerId, String label, Environment environment) {
|
||||
if (containerId == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -287,8 +294,8 @@ public class MwaaEnvironmentManager {
|
||||
// bad inspect doesn't wrongly fail this environment or, since the readiness poller
|
||||
// shares one loop across every CREATING environment, escape and starve every other
|
||||
// environment's check for this poll tick.
|
||||
LOG.warnv("Could not inspect Airflow container {0} for environment {1}: {2}",
|
||||
containerId, environment.getName(), e.getMessage());
|
||||
LOG.warnv("Could not inspect {0} container {1} for environment {2}: {3}",
|
||||
label, containerId, environment.getName(), e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -458,9 +458,9 @@ public class MwaaService implements TagHandler {
|
||||
return;
|
||||
}
|
||||
boolean ready = environmentManager.isReady(environment);
|
||||
boolean exited = !ready && environmentManager.hasAirflowContainerExited(environment);
|
||||
boolean exited = !ready && environmentManager.hasAnyContainerExited(environment);
|
||||
|
||||
// isReady()/hasAirflowContainerExited() are blocking Docker/HTTP calls, long enough for a
|
||||
// isReady()/hasAnyContainerExited() are blocking Docker/HTTP calls, long enough for a
|
||||
// concurrent DeleteEnvironment (which sets DELETING on this same Environment instance
|
||||
// before tearing down its containers) to have moved this environment past CREATING in the
|
||||
// meantime. Re-checking right before writing avoids resurrecting a just-deleted environment
|
||||
@@ -473,12 +473,12 @@ public class MwaaService implements TagHandler {
|
||||
environment.setStatus(EnvironmentStatus.AVAILABLE);
|
||||
putEnvironment(environment);
|
||||
} else if (exited) {
|
||||
// docker start returns as soon as the entrypoint launches, so a script or migration
|
||||
// failing partway through never surfaces here on its own; without this check the
|
||||
// environment would poll a dead container and report CREATING forever instead of the
|
||||
// CREATE_FAILED a real failure should be.
|
||||
LOG.errorv("MWAA environment {0}''s Airflow container exited before becoming ready; "
|
||||
+ "marking CREATE_FAILED", environment.getName());
|
||||
// docker start returns as soon as a container's entrypoint launches, so its Postgres or
|
||||
// Airflow container dying partway through never surfaces here on its own; without this
|
||||
// check the environment would poll dead containers and report CREATING forever instead
|
||||
// of the CREATE_FAILED a real failure should be.
|
||||
LOG.errorv("MWAA environment {0}''s Postgres or Airflow container exited before "
|
||||
+ "becoming ready; marking CREATE_FAILED", environment.getName());
|
||||
environment.setStatus(EnvironmentStatus.CREATE_FAILED);
|
||||
putEnvironment(environment);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user