Skip to content

Commit

Permalink
Add a new config to configure the host of the scheduler health check …
Browse files Browse the repository at this point in the history
…server (apache#35616)

* Add a new config to configure the host of the scheduler healthcheck server

* Add a test
  • Loading branch information
hussein-awala authored Nov 25, 2023
1 parent 177da90 commit 454e63f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions airflow/config_templates/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion airflow/utils/scheduler_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ def do_GET(self):


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()


Expand Down
16 changes: 16 additions & 0 deletions tests/cli/commands/test_scheduler_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ def test_disable_scheduler_health(
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"))
Expand Down

0 comments on commit 454e63f

Please sign in to comment.