diff --git a/airflow_exporter/prometheus_exporter.py b/airflow_exporter/prometheus_exporter.py index c55d768..ef96510 100644 --- a/airflow_exporter/prometheus_exporter.py +++ b/airflow_exporter/prometheus_exporter.py @@ -275,7 +275,7 @@ def get_dag_labels(dag_id: str) -> Dict[str, str]: def get_metric_labels_from_tags(dag_id: str) -> Dict[str, str]: - known_tags = ('alert', 'schedule') + known_tags = ('alert', 'schedule', 'postcalc', 'product', 'env') # reuse airflow webserver dagbag dag = current_app.dag_bag.get_dag(dag_id) @@ -417,10 +417,13 @@ def collect(self) -> Generator[Metric, None, None]: dag_duration_metric = GaugeMetricFamily( 'airflow_dag_run_duration', 'Maximum duration of currently running dag_runs for each DAG in seconds', - labels=['dag_id'] + labels=['dag_id', 'postcalc', 'env', 'product'] ) for dag_duration in get_dag_duration_info(): - labels = get_dag_labels(dag_duration.dag_id) + labels = { + **get_dag_labels(dag_duration.dag_id), + **get_metric_labels_from_tags(dag_duration.dag_id) + } _add_gauge_metric( dag_duration_metric, diff --git a/tests/dags/slow_dag.py b/tests/dags/slow_dag.py index 9203d9f..4bd9a9d 100644 --- a/tests/dags/slow_dag.py +++ b/tests/dags/slow_dag.py @@ -20,7 +20,7 @@ schedule_interval=timedelta(hours=5), default_args=default_args, catchup=False, - tags=["tag1", "alert:peak", "schedule:weekly"], + tags=["tag1", "alert:peak", "schedule:weekly", "postcalc:pc1", "env:dev", "product:toonblast"], params={ 'labels': { 'kind': 'slow'