You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2022/12/03 16:12:02 UTC
[airflow] branch main updated: Updates health check endpoint to include `triggerer` status (#27755)
This is an automated email from the ASF dual-hosted git repository.
potiuk 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 144f88b995 Updates health check endpoint to include `triggerer` status (#27755)
144f88b995 is described below
commit 144f88b995061369e428d4fe7d6d436c9641379d
Author: Daniel Anya <49...@users.noreply.github.com>
AuthorDate: Sat Dec 3 10:11:54 2022 -0600
Updates health check endpoint to include `triggerer` status (#27755)
---
airflow/api_connexion/endpoints/health_endpoint.py | 18 ++++++++++++++++++
airflow/api_connexion/schemas/health_schema.py | 9 ++++++++-
.../apache-airflow/logging-monitoring/check-health.rst | 8 ++++++++
3 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/airflow/api_connexion/endpoints/health_endpoint.py b/airflow/api_connexion/endpoints/health_endpoint.py
index f833a5d728..7fa7f21cd9 100644
--- a/airflow/api_connexion/endpoints/health_endpoint.py
+++ b/airflow/api_connexion/endpoints/health_endpoint.py
@@ -19,6 +19,7 @@ from __future__ import annotations
from airflow.api_connexion.schemas.health_schema import health_schema
from airflow.api_connexion.types import APIResponse
from airflow.jobs.scheduler_job import SchedulerJob
+from airflow.jobs.triggerer_job import TriggererJob
HEALTHY = "healthy"
UNHEALTHY = "unhealthy"
@@ -28,7 +29,9 @@ def get_health() -> APIResponse:
"""Return the health of the airflow scheduler and metadatabase."""
metadatabase_status = HEALTHY
latest_scheduler_heartbeat = None
+ latest_triggerer_heartbeat = None
scheduler_status = UNHEALTHY
+ triggerer_status: str | None = UNHEALTHY
try:
scheduler_job = SchedulerJob.most_recent_job()
@@ -38,6 +41,17 @@ def get_health() -> APIResponse:
scheduler_status = HEALTHY
except Exception:
metadatabase_status = UNHEALTHY
+ try:
+ triggerer_job = TriggererJob.most_recent_job()
+
+ if triggerer_job:
+ latest_triggerer_heartbeat = triggerer_job.latest_heartbeat.isoformat()
+ if triggerer_job.is_alive():
+ triggerer_status = HEALTHY
+ else:
+ triggerer_status = None
+ except Exception:
+ metadatabase_status = UNHEALTHY
payload = {
"metadatabase": {"status": metadatabase_status},
@@ -45,6 +59,10 @@ def get_health() -> APIResponse:
"status": scheduler_status,
"latest_scheduler_heartbeat": latest_scheduler_heartbeat,
},
+ "triggerer": {
+ "status": triggerer_status,
+ "latest_triggerer_heartbeat": latest_triggerer_heartbeat,
+ },
}
return health_schema.dump(payload)
diff --git a/airflow/api_connexion/schemas/health_schema.py b/airflow/api_connexion/schemas/health_schema.py
index 67155406c1..5391ce5ae2 100644
--- a/airflow/api_connexion/schemas/health_schema.py
+++ b/airflow/api_connexion/schemas/health_schema.py
@@ -30,16 +30,23 @@ class MetaDatabaseInfoSchema(BaseInfoSchema):
class SchedulerInfoSchema(BaseInfoSchema):
- """Schema for Metadatabase info."""
+ """Schema for Scheduler info."""
latest_scheduler_heartbeat = fields.String(dump_only=True)
+class TriggererInfoSchema(BaseInfoSchema):
+ """Schema for Triggerer info."""
+
+ latest_triggerer_heartbeat = fields.String(dump_only=True)
+
+
class HealthInfoSchema(Schema):
"""Schema for the Health endpoint."""
metadatabase = fields.Nested(MetaDatabaseInfoSchema)
scheduler = fields.Nested(SchedulerInfoSchema)
+ triggerer = fields.Nested(TriggererInfoSchema)
health_schema = HealthInfoSchema()
diff --git a/docs/apache-airflow/logging-monitoring/check-health.rst b/docs/apache-airflow/logging-monitoring/check-health.rst
index 4e0777eccb..2aa4386df5 100644
--- a/docs/apache-airflow/logging-monitoring/check-health.rst
+++ b/docs/apache-airflow/logging-monitoring/check-health.rst
@@ -47,6 +47,10 @@ To check the health status of your Airflow instance, you can simply access the e
"scheduler":{
"status":"healthy",
"latest_scheduler_heartbeat":"2018-12-26 17:15:11+00:00"
+ },
+ "triggerer":{
+ "status":"healthy",
+ "latest_triggerer_heartbeat":"2018-12-26 17:16:12+00:00"
}
}
@@ -63,6 +67,10 @@ To check the health status of your Airflow instance, you can simply access the e
* If you run more than one scheduler, only the state of one scheduler will be reported, i.e. only one working scheduler is enough
for the scheduler state to be considered healthy
+ * The status of the ``triggerer`` behaves exactly like that of the ``scheduler`` as described above.
+ Note that the ``status`` and ``latest_triggerer_heartbeat`` fields in the health check response will be null for
+ deployments that do not include a ``triggerer`` component.
+
Please keep in mind that the HTTP response code of ``/health`` endpoint **should not** be used to determine the health
status of the application. The return code is only indicative of the state of the rest call (200 for success).