flask-dashboard / Flask-MonitoringDashboard

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

Blueprint name collision #330

Open tarik56 opened 4 years ago

tarik56 commented 4 years ago

Hello,

I'm getting a blueprint name collision error.

AssertionError: A blueprint's name collision occurred between <flask.blueprints.Blueprint object at 0x0000021E18B91E48> and <flask.blueprints.Blueprint object at 0x0000021E16FA4940>.  Both share the same name "dashboard".  Blueprints that are created on the fly need unique names.

That's true because I have a route called "dashboard" already, but I changed the custom route link as described in the documentation as:

[dashboard]
APP_VERSION=1.0
CUSTOM_LINK=monitoring
MONITOR_LEVEL=3
OUTLIER_DETECTION_CONSTANT=2.5
SAMPLING_PERIOD=20
ENABLE_LOGGING=True

[authentication]
USERNAME=admin
PASSWORD=admin
GUEST_USERNAME=guest
GUEST_PASSWORD=['dashboardguest!', 'second_pw!']
SECURITY_TOKEN=cc83733cb0af8b884ff6577086b87909

[visualization]
TIMEZONE=Europe/Amsterdam
COLORS={'main':'[0,97,255]',
        'static':'[255,153,0]'}

my init looks as follows:

import flask_monitoringdashboard as monitoring_dashboard
app_service = Flask(__name__, )
monitoring_dashboard.config.init_from(file="../../monitoring_config.cfg")
monitoring_dashboard.bind(app_service)
app_service.config['JSON_SORT_KEYS'] = False
app_service.register_blueprint(routes.register.api, url_prefix='/register')
app_service.register_blueprint(routes.login.api, url_prefix='/login')
app_service.register_blueprint(routes.dashboard.api, url_prefix='/dashboard')
app_service.register_blueprint(routes.payment.api, url_prefix='/payment')
..
.
.

When I try to change the blueprint names myself like:

monitoring_dashboard.config.link = "monitoring"
monitoring_dashboard.blueprint.name = "monitoring"

it seems to be working but when I call localhost/monitoring/ I'm getting a:

werkzeug.routing.BuildError: Could not build url for endpoint 'dashboard.index'. Did you mean 'dashboard.get_users_increase' instead?

Edit: I just realized the custom link gets appended behind the dashboard url. That doesn't change the blueprints name though since it is hardcoded. So a Blueprint name collision is inevitable unless I decide to change my blueprint name etc.....

Edit2: I run into other issues when forcing a different blueprint name. I guess that's because the name "dashboard" is deeply reserved in its roots within the module code?? Is there a solution without having to change my already existing dashboard blueprint?

bogdanp05 commented 4 years ago

Hi @tarik56, thanks for pointing out the issue. I was able to reproduce it. You are right about the config link, it only changes the path prefix, not the name of the actual blueprint. At the moment, there's no way around this, but as far as I can tell, the problem is caused by hardcoding "dashboard" in the templates. This should be made configurable.