def create_app(settings_override=None): """ Create a Flask application using the app factory pattern. :param settings_override: Override settings :return: Flask app """ app = Flask(__name__, instance_relative_config=True) def disable_varnish(response): response.cache_control.private = True return response app.after_request(disable_varnish) SSLify(app, skips=['healthcheck']) gunicorn_logger = logging.getLogger('gunicorn.error') app.logger.handlers = gunicorn_logger.handlers app.logger.setLevel(gunicorn_logger.level) app.config.from_object('config.settings') if 'GOOGLE_CLIENT_ID' in app.config: setup_authentication(app) app.register_blueprint(page) plugins = {} for plugin in app.config['ENABLED_PLUGINS']: module = importlib.import_module(f'dashboard.plugins.{plugin}') app.register_blueprint(module.plugin, url_prefix=module.base_path) if hasattr(module, 'init'): module.init(app) plugins[plugin] = {'tab_name': module.tab_name} app.airflow_data_provider = AirflowDBDataProvider(app.config, app.logger, MySQLClient(app.config, app.logger)) app.influx_client = InfluxDbService(app.config, app.logger) if app.config.get('INFLUXDB_HOST') else None app.influx_data_provider = InfluxDBData(app.influx_client, app.logger) if app.config.get('INFLUXDB_HOST') else None app.prometheus_data_provider = PrometheusData(app.config, app.logger) if app.config.get('PROMETHEUS_HOST') else None # Reading tables configs, setting variable to `None` if file is not present tables = get_yaml_file_content(TABLES_PATH) app.table_data_provider = TableDataProvider( app.airflow_data_provider, app.influx_data_provider, app.prometheus_data_provider, tables, app.logger, app.config) if tables else None links = get_yaml_file_content(LINKS_PATH) app.links_data_provider = LinksDataProvider(links) app.etl_data_provider = EtlDataProvider( app.config, app.airflow_data_provider, app.table_data_provider) app.async_request_executor = ThreadPoolExecutor(max_workers=3) app.cache = SimpleCache() if app.debug: app.wsgi_app = DebuggedApplication(app.wsgi_app, evalex=True) app.context_processor(lambda: {'now': datetime.now(), 'plugins': plugins}) return app
def index(): reports = get_yaml_file_content(REPORTS_PATH) if not reports: return render_template('no_config.html', filename='reports.yaml') report_data_provider = ReportsDataProvider(app.table_data_provider.list(), reports['reports']) return render_template('reports/index.html', reports=report_data_provider.reports)
def index(): streams_definition = get_yaml_file_content('config/streaming.yaml') if not streams_definition: return render_template('no_config.html', filename='streaming.yaml') alerts = [table['id'] for table in app.table_data_provider.list() if table['active_alerts']] streams = [dict(active_alerts = stream['table'] in alerts, **stream) for stream in streams_definition] return render_template('streaming/index.html', streams=streams)