Skip to content

Commit 38559b6

Browse files
author
Abhishek Ray
committedJan 2, 2020
Fix broken build due to XCOM config
1 parent 9335fa1 commit 38559b6

File tree

6 files changed

+29
-15
lines changed

6 files changed

+29
-15
lines changed
 

‎MANIFEST.in

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
include README.md
2+
include MANIFEST.in
3+
include setup.cfg
4+
include setup.py
5+
recursive-include airflow_prometheus_exporter/ *
6+
7+
recursive-exclude * __pycache__
8+
recursive-exclude * *.py[co]
9+
recursive-exclude * .*.sw[a-z]

‎README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ value of configurable parameter in xcom table
5151

5252
xcom fields is deserialized as a dictionary and if key is found for a paticular task-id, the value is reported as a guage
5353

54-
add task / key combinations in config.yaml:
55-
```
54+
Add task / key combinations in config.yaml:
55+
56+
```bash
5657
xcom_params:
5758
-
5859
task_id: abc
File renamed without changes.

‎airflow_prometheus_exporter/prometheus_exporter.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Prometheus exporter for Airflow."""
2-
2+
import json
3+
import pickle
34
from contextlib import contextmanager
45

56
from airflow.configuration import conf
@@ -8,15 +9,13 @@
89
from airflow.settings import Session
910
from airflow.utils.state import State
1011
from airflow.utils.log.logging_mixin import LoggingMixin
11-
from airflow_prometheus_exporter.xcom_config import xcom_config
1212
from flask import Response
1313
from flask_admin import BaseView, expose
14-
import json
15-
import pickle
1614
from prometheus_client import generate_latest, REGISTRY
1715
from prometheus_client.core import GaugeMetricFamily
1816
from sqlalchemy import and_, func
1917

18+
from airflow_prometheus_exporter.xcom_config import load_xcom_config
2019

2120
CANARY_DAG = "canary_dag"
2221

@@ -439,7 +438,8 @@ def collect(self):
439438
labels=["dag_id", "task_id"],
440439
)
441440

442-
for tasks in xcom_config["xcom_params"]:
441+
xcom_config = load_xcom_config()
442+
for tasks in xcom_config.get("xcom_params", []):
443443
for param in get_xcom_params(tasks["task_id"]):
444444
xcom_value = extract_xcom_parameter(param.value)
445445

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import yaml
2-
import os
2+
from pathlib import Path
33

4-
dir = os.path.dirname(__file__)
5-
filename = os.path.join(dir, "../config.yaml")
4+
CONFIG_FILE = Path.cwd() / "config.yaml"
65

76

8-
xcom_config = {}
9-
with open(filename) as file:
10-
# The FullLoader parameter handles the conversion from YAML
11-
# scalar values to Python the dictionary format
12-
xcom_config = yaml.load(file, Loader=yaml.FullLoader)
7+
def load_xcom_config():
8+
"""Loads the XCom config if present."""
9+
try:
10+
with open(CONFIG_FILE) as file:
11+
# The FullLoader parameter handles the conversion from YAML
12+
# scalar values to Python the dictionary format
13+
return yaml.load(file, Loader=yaml.FullLoader)
14+
except FileNotFoundError:
15+
return {}

‎setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
keywords='airflow_prometheus_exporter',
4242
name='airflow_prometheus_exporter',
4343
packages=find_packages(include=['airflow_prometheus_exporter']),
44+
include_package_data=True,
4445
url='https://github.com/robinhood/airflow_prometheus_exporter',
4546
version='1.0.5',
4647
entry_points={

0 commit comments

Comments
 (0)
Please sign in to comment.