-
Notifications
You must be signed in to change notification settings - Fork 3k
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
feat(ingest/airflow): Add way to disable Airflow plugin without a restart #12098
Changes from 10 commits
267e96a
1511833
7d0b511
2d62bff
cf78fa5
b64bb22
f5f47e3
d5279ee
27791f4
5423fa3
3073213
f49152d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
import airflow | ||
import datahub.emitter.mce_builder as builder | ||
from airflow.models import Variable | ||
from airflow.models.serialized_dag import SerializedDagModel | ||
from datahub.api.entities.datajob import DataJob | ||
from datahub.api.entities.dataprocess.dataprocess_instance import InstanceRunResult | ||
|
@@ -78,6 +79,8 @@ def hookimpl(f: _F) -> _F: # type: ignore[misc] # noqa: F811 | |
) | ||
_DATAHUB_CLEANUP_DAG = "Datahub_Cleanup" | ||
|
||
KILL_SWITCH_VARIABLE_NAME = "datahub_airflow_plugin_disable_listener" | ||
|
||
|
||
def get_airflow_plugin_listener() -> Optional["DataHubListener"]: | ||
# Using globals instead of functools.lru_cache to make testing easier. | ||
|
@@ -364,6 +367,15 @@ def _extract_lineage( | |
redact_with_exclusions(v) | ||
) | ||
|
||
def check_kill_switch(self): | ||
try: | ||
if Variable.get(KILL_SWITCH_VARIABLE_NAME, "false").lower() == "true": | ||
logger.info("DataHub listener disabled by kill switch") | ||
return True | ||
except Exception as e: | ||
raise e | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the point of this try catch? |
||
return False | ||
|
||
@hookimpl | ||
@run_in_thread | ||
def on_task_instance_running( | ||
|
@@ -372,6 +384,8 @@ def on_task_instance_running( | |
task_instance: "TaskInstance", | ||
session: "Session", # This will always be QUEUED | ||
) -> None: | ||
if self.check_kill_switch(): | ||
return | ||
self._set_log_level() | ||
|
||
# This if statement mirrors the logic in https://github.com/OpenLineage/OpenLineage/pull/508. | ||
|
@@ -482,6 +496,10 @@ def on_task_instance_running( | |
def on_task_instance_finish( | ||
self, task_instance: "TaskInstance", status: InstanceRunResult | ||
) -> None: | ||
if self.check_kill_switch(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this method is called by the success and failure hooks - so it doesn't need this |
||
return | ||
self._set_log_level() | ||
|
||
dagrun: "DagRun" = task_instance.dag_run # type: ignore[attr-defined] | ||
|
||
if self.config.render_templates: | ||
|
@@ -541,6 +559,9 @@ def on_task_instance_finish( | |
def on_task_instance_success( | ||
self, previous_state: None, task_instance: "TaskInstance", session: "Session" | ||
) -> None: | ||
if self.check_kill_switch(): | ||
return | ||
|
||
self._set_log_level() | ||
|
||
logger.debug( | ||
|
@@ -556,6 +577,9 @@ def on_task_instance_success( | |
def on_task_instance_failed( | ||
self, previous_state: None, task_instance: "TaskInstance", session: "Session" | ||
) -> None: | ||
if self.check_kill_switch(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we also need to add these to the |
||
return | ||
|
||
self._set_log_level() | ||
|
||
logger.debug( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's move these docs down to the "Debugging" section