-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
831a741
commit 346b6f7
Showing
5 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from __future__ import annotations | ||
|
||
from airflow.listeners import hookimpl | ||
from airflow.models.dagrun import DagRun | ||
from airflow.models.taskinstance import TaskInstance | ||
from airflow.utils.log.logging_mixin import LoggingMixin | ||
from airflow.utils.state import TaskInstanceState | ||
|
||
from dagfactory import telemetry | ||
|
||
log = LoggingMixin().log | ||
|
||
|
||
class EventStatus: | ||
SUCCESS = "success" | ||
FAILED = "failed" | ||
|
||
|
||
class EventType: | ||
DAG_RUN = "dag_run" | ||
TASK_INSTANCE = "task_instance" | ||
|
||
|
||
@hookimpl | ||
def on_dag_run_success(dag_run: DagRun, msg: str): | ||
additional_telemetry_metrics = { | ||
"dag_hash": dag_run.dag_hash, | ||
"status": EventStatus.SUCCESS, | ||
} | ||
|
||
telemetry.emit_usage_metrics_if_enabled(EventType.DAG_RUN, additional_telemetry_metrics) | ||
|
||
|
||
@hookimpl | ||
def on_dag_run_failed(dag_run: DagRun, msg: str): | ||
additional_telemetry_metrics = { | ||
"dag_hash": dag_run.dag_hash, | ||
"status": EventStatus.FAILED, | ||
} | ||
|
||
telemetry.emit_usage_metrics_if_enabled(EventType.DAG_RUN, additional_telemetry_metrics) | ||
|
||
|
||
@hookimpl | ||
def on_task_instance_success(previous_state: TaskInstanceState, task_instance: TaskInstance, session): | ||
additional_telemetry_metrics = { | ||
"dag_hash": task_instance.dag_run.dag_hash, | ||
"status": EventStatus.SUCCESS, | ||
"operator": task_instance.operator, | ||
} | ||
|
||
telemetry.emit_usage_metrics_if_enabled(EventType.TASK_INSTANCE, additional_telemetry_metrics) | ||
|
||
|
||
@hookimpl | ||
def on_task_instance_failed( | ||
previous_state: TaskInstanceState, task_instance: TaskInstance, error: None | str | BaseException, session | ||
): | ||
additional_telemetry_metrics = { | ||
"dag_hash": task_instance.dag_run.dag_hash, | ||
"status": EventStatus.FAILED, | ||
"operator": task_instance.operator, | ||
} | ||
|
||
telemetry.emit_usage_metrics_if_enabled(EventType.TASK_INSTANCE, additional_telemetry_metrics) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from airflow.plugins_manager import AirflowPlugin | ||
|
||
from dagfactory.listeners import runtime_event | ||
|
||
|
||
class DagFactoryPlugin(AirflowPlugin): | ||
name = "Listener Plugin" | ||
listeners = [runtime_event] | ||
|
||
|
||
dagfactory_plugin = DagFactoryPlugin() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters