Flask-MonitoringDashboard icon indicating copy to clipboard operation
Flask-MonitoringDashboard copied to clipboard

Feature Request: Config at Runtime with Env Vars

Open DivisionMax opened this issue 7 years ago • 5 comments

I could be mistaken but there does not appear any way to set individual configuration options at runtime and thus be able to set them with environment variables e.g. setting the database url which I would not want to commit as it contains authentication. I could just not commit config file, but for example the [dashboard] and [visualization] config is safe and would apply between multiple deployment types (dev vs. production) and it becomes messy for different deployments between I'd need two separate files.

Would this something be seen as useful? I'd be happy to look at doing the work.

DivisionMax avatar Oct 03 '18 20:10 DivisionMax

Hi DivisionMax,

Thanks for your feature request. I think that this is indeed a nice feature for the FMD. Therefore, you're granted permission to implement this and send a PR to our development branch.

In order to help you with the required functionality, take a look at this object: https://github.com/flask-dashboard/Flask-MonitoringDashboard/blob/4961030dc3eb4a805a06c75276248fef15a0b580/flask_monitoringdashboard/core/config/init.py#L12

Moreover, this object uses the following 4 functions: parse_version, parse_literal, parse_bool and parse_string in https://github.com/flask-dashboard/Flask-MonitoringDashboard/blob/master/flask_monitoringdashboard/core/config/parser.py

If those 4 functions read from the ENV-vars, than it won't be a lot of work to implement.

Thanks again for your contribution to the Flask-MonitoringDashboard.

Looking forward to your PR,

Patrick

FlyingBird95 avatar Oct 08 '18 16:10 FlyingBird95

Implemented in #216

FlyingBird95 avatar Mar 04 '19 19:03 FlyingBird95

Is this feature documented somewhere? I'd like to use it.

noslenkwah avatar Sep 03 '20 15:09 noslenkwah

@noslenkwah If you look at code in the linked PR (https://github.com/flask-dashboard/Flask-MonitoringDashboard/pull/216/files) you'll see that all you have to do is to export as envvars the keys that you'd normally set in the config file.

mircealungu avatar Sep 03 '20 19:09 mircealungu

Thanks @mircealungu. I seem to be doing something incorrectly.

For example, I export my ENVVAR:

export MONITOR_LEVEL=3

Then when I run the app and inspect the config I still get the following:

{'app': <Flask 'app'>,
 'colors': {},
 'database_name': 'sqlite:///dashboard.db',
 'enable_logging': False,
 'group_by': None,
 'guest_password': ['guest_password'],
 'guest_username': ['guest'],
 'link': 'dashboard',
 'monitor_level': 1,
 'outlier_detection_constant': 2.5,
 'password': '-------',
 'sampling_period': 0.005,
 'security_token': '-------',
 'table_prefix': '',
 'timezone': <DstTzInfo 'America/Los_Angeles' LMT-1 day, 16:07:00 STD>,
 'username': 'admin',
 'version': '1.0'}

I've tried variations of the variable name such as FLASK_MONITORING_MONITOR_LEVEL.

noslenkwah avatar Sep 03 '20 20:09 noslenkwah