-
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?
Conversation
1918a6e
to
bf04263
Compare
bf04263
to
3a19899
Compare
- Add rate limiting config options. Only the ones that we might want to change have been added as config options for now. - Remove statsd options from watcher middleware. Since the defaults values are being used it's better to use them for both watcher MW as well as rate limiting MW, rather than definining statsd options for each of the middlewares. If in the future we need to set non-default options we can create a dedicated statsd config option group that all middlewares are getting their statsd config from.
3a19899
to
c763099
Compare
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, | ||
) |
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.
ratelimitmiddleware has nothing to do with - and doesn't require audit_middleware
, but watcher_middleware. Therefor, this needs to moved down but above the watcher middleware initialization.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
has nothing to do with this PR
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
has nothing to do with this PR
@@ -14,6 +14,7 @@ | |||
|
|||
import sys | |||
|
|||
import rate_limit as ratelimitmiddleware |
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.
# Any requirements we need for CCloud | ||
git+https://github.com/sapcc/openstack-rate-limit-middleware.git#egg=rate-limit-middleware |
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.
unneded if octavia can startup without the module (see earlier comment)
backend_timeout_seconds=CONF.rate_limiting.backend_timeout_seconds, | ||
) | ||
|
||
# audit middleware |
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.
nothing to do with this PR
Add rate limiting config options. Only the ones that we might want to change have been added as config options for now.
Remove statsd options from watcher middleware. Since the defaults values are being used it's better to use them for both watcher MW as well as rate limiting MW, rather than definining statsd options for each of the middlewares. If in the future we need to set non-default options we can create a dedicated statsd config option group that all middlewares are getting their statsd config from.
This PR is accompanied by sapcc/helm-charts#4046