flask-dashboard / Flask-MonitoringDashboard

Automatically monitor the evolving performance of Flask/Python web services.
http://flask-monitoringdashboard.readthedocs.io/
MIT License
781 stars 160 forks source link

Feature Request: Config at Runtime with Env Vars #197

Open DivisionMax opened 6 years ago

DivisionMax commented 6 years ago

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.

FlyingBird95 commented 6 years ago

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 commented 5 years ago

Implemented in #216

noslenkwah commented 4 years ago

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

mircealungu commented 4 years ago

@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.

noslenkwah commented 4 years ago

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.