Skip to content
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

Open
wants to merge 1 commit into
base: stable/yoga-m3
Choose a base branch
from

Conversation

BenjaminLudwigSAP
Copy link
Collaborator

@BenjaminLudwigSAP BenjaminLudwigSAP commented Jan 26, 2024

  • 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

- 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.
Comment on lines 100 to +114
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,
)
Copy link
Collaborator

@notandy notandy Oct 2, 2024

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
Copy link
Collaborator

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)
Copy link
Collaborator

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
Copy link
Collaborator

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.

Comment on lines +23 to +24
# Any requirements we need for CCloud
git+https://github.com/sapcc/openstack-rate-limit-middleware.git#egg=rate-limit-middleware
Copy link
Collaborator

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants