This is an automated email from the ASF dual-hosted git repository. husseinawala pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push: new 454e63fd66 Add a new config to configure the host of the scheduler health check server (#35616) 454e63fd66 is described below commit 454e63fd6684d31e5a662aa48d82e2bba8896cac Author: Hussein Awala <huss...@awala.fr> AuthorDate: Sat Nov 25 22:20:18 2023 +0200 Add a new config to configure the host of the scheduler health check server (#35616) * Add a new config to configure the host of the scheduler healthcheck server * Add a test --- airflow/config_templates/config.yml | 8 ++++++++ airflow/utils/scheduler_health.py | 4 +++- tests/cli/commands/test_scheduler_command.py | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/airflow/config_templates/config.yml b/airflow/config_templates/config.yml index 224674b360..a25adc7206 100644 --- a/airflow/config_templates/config.yml +++ b/airflow/config_templates/config.yml @@ -2142,6 +2142,14 @@ scheduler: type: boolean example: ~ default: "False" + scheduler_health_check_server_host: + description: | + When you start a scheduler, airflow starts a tiny web server + subprocess to serve a health check on this host + version_added: 2.8.0 + type: string + example: ~ + default: "0.0.0.0" scheduler_health_check_server_port: description: | When you start a scheduler, airflow starts a tiny web server diff --git a/airflow/utils/scheduler_health.py b/airflow/utils/scheduler_health.py index 0a068d7f72..05c8162042 100644 --- a/airflow/utils/scheduler_health.py +++ b/airflow/utils/scheduler_health.py @@ -57,8 +57,10 @@ class HealthServer(BaseHTTPRequestHandler): def serve_health_check(): + """Start a http server to serve scheduler health check.""" + health_check_host = conf.get("scheduler", "SCHEDULER_HEALTH_CHECK_SERVER_HOST") health_check_port = conf.getint("scheduler", "SCHEDULER_HEALTH_CHECK_SERVER_PORT") - httpd = HTTPServer(("0.0.0.0", health_check_port), HealthServer) + httpd = HTTPServer((health_check_host, health_check_port), HealthServer) httpd.serve_forever() diff --git a/tests/cli/commands/test_scheduler_command.py b/tests/cli/commands/test_scheduler_command.py index 9d67e4d512..570a84fb66 100644 --- a/tests/cli/commands/test_scheduler_command.py +++ b/tests/cli/commands/test_scheduler_command.py @@ -141,6 +141,22 @@ class TestSchedulerCommand: with pytest.raises(AssertionError): mock_process.assert_has_calls([mock.call(target=serve_health_check)]) + @mock.patch("airflow.utils.scheduler_health.HTTPServer") + def test_scheduler_health_host( + self, + http_server_mock, + ): + health_check_host = "192.168.0.0" + health_check_port = 1111 + with conf_vars( + { + ("scheduler", "SCHEDULER_HEALTH_CHECK_SERVER_HOST"): health_check_host, + ("scheduler", "SCHEDULER_HEALTH_CHECK_SERVER_PORT"): str(health_check_port), + } + ): + serve_health_check() + assert http_server_mock.call_args.args[0] == (health_check_host, health_check_port) + @mock.patch("airflow.cli.commands.scheduler_command.SchedulerJobRunner") @mock.patch("airflow.cli.commands.scheduler_command.Process") @mock.patch("airflow.cli.commands.scheduler_command.run_job", side_effect=Exception("run_job failed"))