Skip to content

Commit

Permalink
Add heartbeat metric for DAG processor (apache#42398)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: kalyanr <[email protected]>
  • Loading branch information
rawwar authored Oct 1, 2024
1 parent b1346ac commit c05dae7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
16 changes: 10 additions & 6 deletions airflow/jobs/dag_processor_job_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

from airflow.jobs.base_job_runner import BaseJobRunner
from airflow.jobs.job import Job, perform_heartbeat
from airflow.stats import Stats
from airflow.utils.log.logging_mixin import LoggingMixin
from airflow.utils.session import NEW_SESSION, provide_session

if TYPE_CHECKING:
from airflow.dag_processing.manager import DagFileProcessorManager

from sqlalchemy.orm import Session

def empty_callback(_: Any) -> None:
pass
from airflow.dag_processing.manager import DagFileProcessorManager


class DagProcessorJobRunner(BaseJobRunner, LoggingMixin):
Expand All @@ -52,7 +52,7 @@ def __init__(
self.processor = processor
self.processor.heartbeat = lambda: perform_heartbeat(
job=self.job,
heartbeat_callback=empty_callback,
heartbeat_callback=self.heartbeat_callback,
only_if_necessary=True,
)

Expand All @@ -67,3 +67,7 @@ def _execute(self) -> int | None:
self.processor.terminate()
self.processor.end()
return None

@provide_session
def heartbeat_callback(self, session: Session = NEW_SESSION) -> None:
Stats.incr("dag_processor_heartbeat", 1, 1)
6 changes: 6 additions & 0 deletions chart/files/statsd-mappings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ mappings:
labels:
type: counter

- match: airflow.dag_processor_heartbeat
match_type: regex
name: "airflow_dag_processor_heartbeat"
labels:
type: counter

- match: airflow.dag.*.*.duration
name: "airflow_task_duration"
labels:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ Name Descripti
``previously_succeeded`` Number of previously succeeded task instances. Metric with dag_id and task_id tagging.
``zombies_killed`` Zombie tasks killed. Metric with dag_id and task_id tagging.
``scheduler_heartbeat`` Scheduler heartbeats
``dag_processor_heartbeat`` Standalone DAG processor heartbeats
``dag_processing.processes`` Relative number of currently running DAG parsing processes (ie this delta
is negative when, since the last metric was sent, processes have completed).
Metric with file_path and action tagging.
Expand Down

0 comments on commit c05dae7

Please sign in to comment.