Skip to content

Commit

Permalink
Merge pull request #14 from ayush-san/master
Browse files Browse the repository at this point in the history
adding rbac support for metrics export
  • Loading branch information
Abhishek Ray authored Jan 22, 2020
2 parents 5a0d7b7 + 15d8a50 commit be9467b
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions airflow_prometheus_exporter/prometheus_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from airflow.configuration import conf
from airflow.models import DagModel, DagRun, TaskInstance, TaskFail, XCom
from airflow.plugins_manager import AirflowPlugin
from airflow.settings import Session
from airflow.settings import RBAC, Session
from airflow.utils.state import State
from airflow.utils.log.logging_mixin import LoggingMixin
from flask import Response
Expand Down Expand Up @@ -476,26 +476,45 @@ def collect(self):

REGISTRY.register(MetricsCollector())

if RBAC:
from flask_appbuilder import BaseView as FABBaseView, expose as FABexpose

class Metrics(BaseView):
@expose("/")
def index(self):
return Response(generate_latest(), mimetype="text/plain")

class RBACMetrics(FABBaseView):
route_base = "/admin/metrics/"

ADMIN_VIEW = Metrics(category="Prometheus exporter", name="metrics")
@FABexpose('/')
def list(self):
return Response(generate_latest(), mimetype='text')

# Metrics View for Flask app builder used in airflow with rbac enabled
RBACmetricsView = {
"view": RBACMetrics(),
"name": "Metrics",
"category": "Public"
}
ADMIN_VIEW = []
RBAC_VIEW = [RBACmetricsView]
else:
class Metrics(BaseView):
@expose("/")
def index(self):
return Response(generate_latest(), mimetype="text/plain")

ADMIN_VIEW = [Metrics(category="Prometheus exporter", name="Metrics")]
RBAC_VIEW = []


class AirflowPrometheusPlugin(AirflowPlugin):
"""Airflow Pluging for collecting metrics."""
"""Airflow Plugin for collecting metrics."""

name = "airflow_prometheus_plugin"
operators = []
hooks = []
executors = []
macros = []
admin_views = [ADMIN_VIEW]
admin_views = ADMIN_VIEW
flask_blueprints = []
menu_links = []
appbuilder_views = []
appbuilder_views = RBAC_VIEW
appbuilder_menu_items = []

0 comments on commit be9467b

Please sign in to comment.