Skip to content

Commit

Permalink
chore: more rate limiting ignores (#11332)
Browse files Browse the repository at this point in the history
* move rate limiting config to common config
* add more ips to ignore

---------

Co-authored-by: Stéphane Gigandet <stephane@openfoodfacts.org>
  • Loading branch information
alexgarel and stephanegigandet authored Feb 7, 2025
1 parent d1346e7 commit 7b07ad0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
35 changes: 35 additions & 0 deletions lib/ProductOpener/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ if (not defined $flavor) {
die("The PRODUCT_OPENER_FLAVOR_SHORT environment variable must be set.");
}

# %options will be redefined by autoload below
# but we need it to avoid Perl complaining
%ProductOpener::Config:: % options = ();

use Module::Load;

autoload("ProductOpener::Config_$flavor");
Expand Down Expand Up @@ -174,4 +178,35 @@ $ProductOpener::Config::options{other_servers} = {
}
};

=head2 Rate limiting options
=cut

# Number of requests per minutes for the search API
$ProductOpener::Config::options{rate_limit_search} = 10;
# Number of requests per minutes for all facets for anonymous users
$ProductOpener::Config::options{rate_limit_facet_products_unregistered} = 5;
# Number of requests per minutes for facets for registered users
$ProductOpener::Config::options{rate_limit_facet_products_registered} = 10;
# Number of requests per minutes for facets for bots
$ProductOpener::Config::options{rate_limit_facet_products_crawl_bot} = 10;
# Number of requests per minutes for facet tags (list of tags with count) for anonymous users
$ProductOpener::Config::options{rate_limit_facet_tags_unregistered} = 5;
$ProductOpener::Config::options{rate_limit_facet_tags_registered} = 10;
$ProductOpener::Config::options{rate_limit_facet_tags_crawl_bot} = 10;
$ProductOpener::Config::options{rate_limit_product} = 100;

# Rate limit allow list
$ProductOpener::Config::options{rate_limit_allow_list} = {
'146.59.148.140' => 1, # OVH1
'51.210.154.203' => 1, # OVH2
'51.210.32.79' => 1, # OVH3
'46.105.72.120' => 1, # proxy ovh1
'213.36.253.215' => 1, # proxy off1
'213.36.253.214' => 1, # proxy off2
'213.36.253.206' => 1, # off1
'213.36.253.208' => 1, # off2
'45.147.209.254' => 1, # Moji server (actually OSM proxy, Moji only has ipv6)
};

1;
24 changes: 0 additions & 24 deletions lib/ProductOpener/Config_off.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1605,28 +1605,4 @@ $options{sample_product_code} = "093270067481501"; # A good product for you -
#$options{sample_product_code_language_de} = "20884680"; # Waffeln Sondey
#$options{sample_product_code_country_at_language_de} = "5411188119098"; # Natur miss kokosnuss Alpro

## Rate limiting ##

# Number of requests per minutes for the search API
$options{rate_limit_search} = 10;
# Number of requests per minutes for all facets for anonymous users
$options{rate_limit_facet_products_unregistered} = 5;
# Number of requests per minutes for facets for registered users
$options{rate_limit_facet_products_registered} = 10;
# Number of requests per minutes for facets for bots
$options{rate_limit_facet_products_crawl_bot} = 10;
# Number of requests per minutes for facet tags (list of tags with count) for anonymous users
$options{rate_limit_facet_tags_unregistered} = 5;
$options{rate_limit_facet_tags_registered} = 10;
$options{rate_limit_facet_tags_crawl_bot} = 10;
$options{rate_limit_product} = 100;

# Rate limit allow list
$options{rate_limit_allow_list} = {
'146.59.148.140' => 1, # OVH1
'51.210.154.203' => 1, # OVH2
'51.210.32.79' => 1, # OVH3
'45.147.209.254' => 1, # Moji server (actually OSM proxy, Moji only has ipv6)
};

1;

0 comments on commit 7b07ad0

Please sign in to comment.