-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rate limiting middleware #38
base: stable/yoga-m3
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
|
||
import sys | ||
|
||
import rate_limit as ratelimitmiddleware | ||
# Try using custom auditmiddleware | ||
try: | ||
import auditmiddleware as audit_middleware | ||
|
@@ -86,16 +87,33 @@ def setup_app(pecan_config=None, debug=False, argv=None): | |
def _wrap_app(app): | ||
"""Wraps wsgi app with additional middlewares.""" | ||
|
||
# This needs to be the first middleware (and the last in the chain) | ||
# UWSGI needs to be the first middleware (and the last in the chain) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. has nothing to do with this PR |
||
try: | ||
from uwsgi_middleware import uwsgi | ||
app = uwsgi.Uwsgi(app) | ||
except (EnvironmentError, OSError, ImportError) as e: | ||
LOG.debug("Could not load uwsgi middleware: %s", e) | ||
|
||
# Inject Request ID | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. has nothing to do with this PR |
||
app = request_id.RequestId(app) | ||
|
||
if CONF.audit.enabled: | ||
|
||
# rate limiting - depends on audit middleware, therefore must stand | ||
# before it in order to appear after it in the chain | ||
app = ratelimitmiddleware.OpenStackRateLimitMiddleware( | ||
app, | ||
config_file=CONF.rate_limiting.config_file, | ||
service_type=CONF.rate_limiting.service_type, | ||
rate_limit_by=CONF.rate_limiting.rate_limit_by, | ||
max_sleep_time_seconds=CONF.rate_limiting.max_sleep_time_seconds, | ||
backend_host=CONF.rate_limiting.backend_host, | ||
backend_port=CONF.rate_limiting.backend_port, | ||
backend_max_connections=CONF.rate_limiting.backend_max_connections, | ||
backend_timeout_seconds=CONF.rate_limiting.backend_timeout_seconds, | ||
) | ||
Comment on lines
100
to
+114
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ratelimitmiddleware has nothing to do with - and doesn't require |
||
|
||
# audit middleware | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nothing to do with this PR |
||
try: | ||
app = audit_middleware.AuditMiddleware( | ||
app, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,6 @@ tempest>=23.0.0 # Apache-2.0 | |
# Required for pep8 - doc8 tests | ||
sphinx>=2.0.0,!=2.1.0 # BSD | ||
bashate>=0.5.1 # Apache-2.0 | ||
|
||
# Any requirements we need for CCloud | ||
git+https://github.com/sapcc/openstack-rate-limit-middleware.git#egg=rate-limit-middleware | ||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unneded if octavia can startup without the module (see earlier comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be wiser to try the import and check later if the import succeeded. This way the test-requirements.txt don't need the rate limit middleware - there is no tests anyway in octavia.