Skip to content
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

Publish hybrid requirements and startup script logs to CloudWatch #212

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions images/airflow/2.10.1/python/mwaa/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ async def install_user_requirements(cmd: str, environ: dict[str, str]):
"""
requirements_file = environ.get("MWAA__CORE__REQUIREMENTS_PATH")
logger.info(f"MWAA__CORE__REQUIREMENTS_PATH = {requirements_file}")
# For hybrid worker/scheduler containers we publish the requirement install logs
# to the worker CloudWatch log group.
logger_prefix = "worker" if cmd == "hybrid" else cmd;
if requirements_file and os.path.isfile(requirements_file):
logger.info(f"Installing user requirements from {requirements_file}...")

Expand All @@ -237,7 +240,7 @@ async def install_user_requirements(cmd: str, environ: dict[str, str]):
# use CloudWatch for logging.
*set(
[
logging.getLogger(MWAA_LOGGERS.get(f"{cmd}_requirements")),
logging.getLogger(MWAA_LOGGERS.get(f"{logger_prefix}_requirements")),
logger,
]
),
Expand Down Expand Up @@ -266,7 +269,7 @@ async def install_user_requirements(cmd: str, environ: dict[str, str]):
conditions=[
TimeoutCondition(USER_REQUIREMENTS_MAX_INSTALL_TIME),
],
friendly_name=f"{cmd}_requirements",
friendly_name=f"{logger_prefix}_requirements",
)
pip_process.start()
if pip_process.process and pip_process.process.returncode != 0:
Expand Down Expand Up @@ -296,7 +299,10 @@ def execute_startup_script(cmd: str, environ: Dict[str, str]) -> Dict[str, str]:

EXECUTE_USER_STARTUP_SCRIPT_PATH = "execute-user-startup-script"
POST_STARTUP_SCRIPT_VERIFICATION_PATH = "post-startup-script-verification"
PROCESS_LOGGER = logging.getLogger(MWAA_LOGGERS.get(f"{cmd}_startup"))
# For hybrid worker/scheduler containers we publish the startup script logs
# to the worker CloudWatch log group.
PROCESS_LOGGER_PREFIX = "worker" if cmd == "hybrid" else cmd;
PROCESS_LOGGER = logging.getLogger(MWAA_LOGGERS.get(f"{PROCESS_LOGGER_PREFIX}_startup"))

if os.path.isfile(startup_script_path):
logger.info("Executing customer startup script.")
Expand All @@ -309,7 +315,7 @@ def execute_startup_script(cmd: str, environ: Dict[str, str]) -> Dict[str, str]:
conditions=[
TimeoutCondition(STARTUP_SCRIPT_MAX_EXECUTION_TIME),
],
friendly_name=f"{cmd}_startup",
friendly_name=f"{PROCESS_LOGGER_PREFIX}_startup",
sigterm_patience_interval=STARTUP_SCRIPT_SIGTERM_PATIENCE_INTERVAL,
)
startup_script_process.start()
Expand All @@ -325,7 +331,7 @@ def execute_startup_script(cmd: str, environ: Dict[str, str]) -> Dict[str, str]:
conditions=[
TimeoutCondition(STARTUP_SCRIPT_MAX_EXECUTION_TIME),
],
friendly_name=f"{cmd}_startup",
friendly_name=f"{PROCESS_LOGGER_PREFIX}_startup",
)
verification_process.start()

Expand Down
17 changes: 11 additions & 6 deletions images/airflow/2.10.3/python/mwaa/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,16 @@ async def install_user_requirements(cmd: str, environ: dict[str, str]):
logger.info(f"MWAA__CORE__REQUIREMENTS_PATH = {requirements_file}")
if requirements_file and os.path.isfile(requirements_file):
logger.info(f"Installing user requirements from {requirements_file}...")

# For hybrid worker/scheduler containers we publish the requirement install logs
# to the worker CloudWatch log group.
logger_prefix = "worker" if cmd == "hybrid" else cmd;
subprocess_logger = CompositeLogger(
"requirements_composite_logging", # name can be anything unused.
# We use a set to avoid double logging to console if the user doesn't
# use CloudWatch for logging.
*set(
[
logging.getLogger(MWAA_LOGGERS.get(f"{cmd}_requirements")),
logging.getLogger(MWAA_LOGGERS.get(f"{logger_prefix}_requirements")),
logger,
]
),
Expand Down Expand Up @@ -266,7 +268,7 @@ async def install_user_requirements(cmd: str, environ: dict[str, str]):
conditions=[
TimeoutCondition(USER_REQUIREMENTS_MAX_INSTALL_TIME),
],
friendly_name=f"{cmd}_requirements",
friendly_name=f"{logger_prefix}_requirements",
)
pip_process.start()
if pip_process.process and pip_process.process.returncode != 0:
Expand Down Expand Up @@ -296,7 +298,10 @@ def execute_startup_script(cmd: str, environ: Dict[str, str]) -> Dict[str, str]:

EXECUTE_USER_STARTUP_SCRIPT_PATH = "execute-user-startup-script"
POST_STARTUP_SCRIPT_VERIFICATION_PATH = "post-startup-script-verification"
PROCESS_LOGGER = logging.getLogger(MWAA_LOGGERS.get(f"{cmd}_startup"))
# For hybrid worker/scheduler containers we publish the startup script logs
# to the worker CloudWatch log group.
PROCESS_LOGGER_PREFIX = "worker" if cmd == "hybrid" else cmd;
PROCESS_LOGGER = logging.getLogger(MWAA_LOGGERS.get(f"{PROCESS_LOGGER_PREFIX}_startup"))

if os.path.isfile(startup_script_path):
logger.info("Executing customer startup script.")
Expand All @@ -309,7 +314,7 @@ def execute_startup_script(cmd: str, environ: Dict[str, str]) -> Dict[str, str]:
conditions=[
TimeoutCondition(STARTUP_SCRIPT_MAX_EXECUTION_TIME),
],
friendly_name=f"{cmd}_startup",
friendly_name=f"{PROCESS_LOGGER_PREFIX}_startup",
sigterm_patience_interval=STARTUP_SCRIPT_SIGTERM_PATIENCE_INTERVAL,
)
startup_script_process.start()
Expand All @@ -325,7 +330,7 @@ def execute_startup_script(cmd: str, environ: Dict[str, str]) -> Dict[str, str]:
conditions=[
TimeoutCondition(STARTUP_SCRIPT_MAX_EXECUTION_TIME),
],
friendly_name=f"{cmd}_startup",
friendly_name=f"{PROCESS_LOGGER_PREFIX}_startup",
)
verification_process.start()

Expand Down
16 changes: 11 additions & 5 deletions images/airflow/2.9.2/python/mwaa/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ async def install_user_requirements(cmd: str, environ: dict[str, str]):
"""
requirements_file = environ.get("MWAA__CORE__REQUIREMENTS_PATH")
logger.info(f"MWAA__CORE__REQUIREMENTS_PATH = {requirements_file}")
# For hybrid worker/scheduler containers we publish the requirements logs to the worker
# CloudWatch log group.
logger_prefix = "worker" if cmd == "hybrid" else cmd;
if requirements_file and os.path.isfile(requirements_file):
logger.info(f"Installing user requirements from {requirements_file}...")

Expand All @@ -273,7 +276,7 @@ async def install_user_requirements(cmd: str, environ: dict[str, str]):
# use CloudWatch for logging.
*set(
[
logging.getLogger(MWAA_LOGGERS.get(f"{cmd}_requirements")),
logging.getLogger(MWAA_LOGGERS.get(f"{logger_prefix}_requirements")),
logger,
]
),
Expand Down Expand Up @@ -302,7 +305,7 @@ async def install_user_requirements(cmd: str, environ: dict[str, str]):
conditions=[
TimeoutCondition(USER_REQUIREMENTS_MAX_INSTALL_TIME),
],
friendly_name=f"{cmd}_requirements",
friendly_name=f"{logger_prefix}_requirements",
)
pip_process.start()
if pip_process.process and pip_process.process.returncode != 0:
Expand Down Expand Up @@ -332,7 +335,10 @@ def execute_startup_script(cmd: str, environ: Dict[str, str]) -> Dict[str, str]:

EXECUTE_USER_STARTUP_SCRIPT_PATH = "execute-user-startup-script"
POST_STARTUP_SCRIPT_VERIFICATION_PATH = "post-startup-script-verification"
PROCESS_LOGGER = logging.getLogger(MWAA_LOGGERS.get(f"{cmd}_startup"))
# For hybrid worker/scheduler containers we publish the startup script logs
# to the worker CloudWatch log group.
PROCESS_LOGGER_PREFIX = "worker" if cmd == "hybrid" else cmd;
PROCESS_LOGGER = logging.getLogger(MWAA_LOGGERS.get(f"{PROCESS_LOGGER_PREFIX}_startup"))

if os.path.isfile(startup_script_path):
logger.info("Executing customer startup script.")
Expand All @@ -345,7 +351,7 @@ def execute_startup_script(cmd: str, environ: Dict[str, str]) -> Dict[str, str]:
conditions=[
TimeoutCondition(STARTUP_SCRIPT_MAX_EXECUTION_TIME),
],
friendly_name=f"{cmd}_startup",
friendly_name=f"{PROCESS_LOGGER_PREFIX}_startup",
sigterm_patience_interval=STARTUP_SCRIPT_SIGTERM_PATIENCE_INTERVAL,
)
startup_script_process.start()
Expand All @@ -361,7 +367,7 @@ def execute_startup_script(cmd: str, environ: Dict[str, str]) -> Dict[str, str]:
conditions=[
TimeoutCondition(STARTUP_SCRIPT_MAX_EXECUTION_TIME),
],
friendly_name=f"{cmd}_startup",
friendly_name=f"{PROCESS_LOGGER_PREFIX}_startup",
)
verification_process.start()

Expand Down
Loading