# Mapping StatsD → Prometheus для Airflow
# См. документацию: https://github.com/prometheus/statsd_exporter#metric-mapping-and-configuration

mappings:
  # DAG processing metrics
  - match: "airflow.dag_processing.total_parse_time"
    name: "airflow_dag_processing_total_parse_time"
    help: "Total time to parse all DAGs"
    type: gauge

  - match: "airflow.dagbag_size"
    name: "airflow_dagbag_size"
    help: "DAGs in the DagBag"
    type: gauge

  # Executor metrics
  - match: "airflow.executor.open_slots"
    name: "airflow_executor_open_slots"
    help: "Open slots on executor"
    type: gauge

  - match: "airflow.executor.queued_tasks"
    name: "airflow_executor_queued_tasks"
    help: "Queued tasks on executor"
    type: gauge

  - match: "airflow.executor.running_tasks"
    name: "airflow_executor_running_tasks"
    help: "Running tasks on executor"
    type: gauge

  # Scheduler metrics (counter → _total суффикс по Prometheus convention)
  - match: "airflow.scheduler_heartbeat"
    name: "airflow_scheduler_heartbeat_total"
    help: "Scheduler heartbeats"
    type: counter

  - match: "airflow.scheduler.critical_section_busy"
    name: "airflow_scheduler_critical_section_busy"
    help: "Scheduler critical section busy"
    type: gauge

  # Task duration (timer → _seconds суффикс)
  # Проверено для Airflow 2.10.5: metric key = dag.<dag_id>.<task_id>.duration
  - match: "airflow.dag.*.*.duration"
    name: "airflow_task_duration_seconds"
    help: "Task duration"
    type: timer
    labels:
      dag_id: "$1"
      task_id: "$2"

  # Task failures/success (counter → _total суффикс)
  # Проверено для Airflow 2.10.5: metric key = ti.finish.<dag_id>.<task_id>.<state>
  - match: "airflow.ti.finish.*.*.failed"
    name: "airflow_task_failures_total"
    help: "Task failures by dag_id and task_id"
    type: counter
    labels:
      dag_id: "$1"
      task_id: "$2"

  - match: "airflow.ti.finish.*.*.success"
    name: "airflow_task_success_total"
    help: "Task successes by dag_id and task_id"
    type: counter
    labels:
      dag_id: "$1"
      task_id: "$2"
