-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor telemetry to collect events during DAG run and not during DA…
…G parsing (#300) DAG Factory 0.20 started collecting telemetry as part of the PR #250. However, one limitation of this initial implementation is that it emitted telemetry every time DAGs were parsed. This means that the data collected did not represent the actual usage and was proportional to the number of times a DAG was parsed. This PR aims to address this limitation by changing DAG Factory to emit telemetry during DAG runs. This implementation leverages Airflow listeners to only emit events after a Factory-Built DAG is run. Closes: #282 With this data, we can get the following insight - Number of failed DagRuns - Number of successful DagRuns - Total tasks associated to each DagRun - DagRun hash **Airflow Version** <img width="1380" alt="Screenshot 2024-12-03 at 8 00 14 PM" src="https://github.com/user-attachments/assets/b67968a2-171a-4f4b-83cc-e3bba13ef35b"> **DAG Hash** <img width="1386" alt="Screenshot 2024-12-03 at 8 01 28 PM" src="https://github.com/user-attachments/assets/fea64d40-7e71-4714-b0e4-2fdb09331962"> **DAG Factory Version** <img width="1382" alt="Screenshot 2024-12-03 at 8 02 08 PM" src="https://github.com/user-attachments/assets/4b9de161-32f3-4c85-a740-814d86526f60"> **Event Type** <img width="1392" alt="Screenshot 2024-12-03 at 8 02 46 PM" src="https://github.com/user-attachments/assets/e7a5b795-f54a-4d12-9676-274b98584b4a"> **Platform Machine** <img width="1384" alt="Screenshot 2024-12-03 at 8 03 18 PM" src="https://github.com/user-attachments/assets/35ede730-e87a-4d6e-acf9-47e34147e331"> **Platform System** <img width="1380" alt="Screenshot 2024-12-03 at 8 04 23 PM" src="https://github.com/user-attachments/assets/9f59dc92-51ae-4c9d-9958-1cc36c4a9149"> **Python Version** <img width="1389" alt="Screenshot 2024-12-03 at 8 05 05 PM" src="https://github.com/user-attachments/assets/085f51ad-1e0a-4785-9744-a0b713d9a267"> **DAG Run Status** <img width="1408" alt="Screenshot 2024-12-03 at 8 06 45 PM" src="https://github.com/user-attachments/assets/1c47bb61-cfeb-49d9-9d93-5a43240c9b51"> **Task Count in DAG run** <img width="1394" alt="Screenshot 2024-12-03 at 8 07 25 PM" src="https://github.com/user-attachments/assets/22c011de-34b4-48cb-8c09-78571d3b6229"> ** Telemetry Version** <img width="1395" alt="Screenshot 2024-12-03 at 8 07 58 PM" src="https://github.com/user-attachments/assets/4c2d6006-72c1-47a2-9cde-6802923dedba">
- Loading branch information
1 parent
9d2b8f5
commit 72bc85b
Showing
13 changed files
with
100 additions
and
62 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
TELEMETRY_URL = "https://astronomer.gateway.scarf.sh/dag-factory/{telemetry_version}/{dagfactory_version}/{airflow_version}/{python_version}/{platform_system}/{platform_machine}?{query_string}" | ||
TELEMETRY_VERSION = "v1" | ||
TELEMETRY_URL = "https://astronomer.gateway.scarf.sh/dag-factory/{telemetry_version}/{dagfactory_version}/{airflow_version}/{python_version}/{platform_system}/{platform_machine}/{event_type}/{status}/{dag_hash}/{task_count}" | ||
TELEMETRY_VERSION = "v2" | ||
TELEMETRY_TIMEOUT = 5.0 |
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
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,49 @@ | ||
from __future__ import annotations | ||
|
||
from airflow.listeners import hookimpl | ||
from airflow.models.dag import DAG | ||
from airflow.models.dagrun import DagRun | ||
|
||
from dagfactory import telemetry | ||
|
||
|
||
class EventStatus: | ||
SUCCESS = "success" | ||
FAILED = "failed" | ||
|
||
|
||
DAG_RUN = "dag_run" | ||
|
||
|
||
def is_dagfactory_dag(dag: DAG | None = None): | ||
if "dagfactory" in dag.tags: | ||
return True | ||
return False | ||
|
||
|
||
@hookimpl | ||
def on_dag_run_success(dag_run: DagRun, msg: str): | ||
dag = dag_run.get_dag() | ||
if not is_dagfactory_dag(dag): | ||
return | ||
additional_telemetry_metrics = { | ||
"dag_hash": dag_run.dag_hash, | ||
"status": EventStatus.SUCCESS, | ||
"task_count": len(dag.task_ids), | ||
} | ||
|
||
telemetry.emit_usage_metrics_if_enabled(DAG_RUN, additional_telemetry_metrics) | ||
|
||
|
||
@hookimpl | ||
def on_dag_run_failed(dag_run: DagRun, msg: str): | ||
dag = dag_run.get_dag() | ||
if not is_dagfactory_dag(dag): | ||
return | ||
additional_telemetry_metrics = { | ||
"dag_hash": dag_run.dag_hash, | ||
"status": EventStatus.FAILED, | ||
"task_count": len(dag.task_ids), | ||
} | ||
|
||
telemetry.emit_usage_metrics_if_enabled(DAG_RUN, 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 = "Dag Factory 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
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
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