From 541c11f23e9ba37edb4652f9afc317c3b2ee89b3 Mon Sep 17 00:00:00 2001 From: Adam Thomason Date: Tue, 1 Feb 2011 18:41:55 -0800 Subject: [PATCH] Group tunables --- lib/Perlbal/Plugin/Throttle.pm | 97 +++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 44 deletions(-) diff --git a/lib/Perlbal/Plugin/Throttle.pm b/lib/Perlbal/Plugin/Throttle.pm index 7c7f71f..6d4a1c3 100644 --- a/lib/Perlbal/Plugin/Throttle.pm +++ b/lib/Perlbal/Plugin/Throttle.pm @@ -16,14 +16,7 @@ use Time::HiRes (); use constant VERBOSE => $ENV{THROTTLE_VERBOSE} || 0; sub load { - Perlbal::Service::add_tunable( - default_action => { - check_role => '*', - des => "Whether to throttle or allow new connections from clients on neither the whitelist nor blacklist.", - check_type => [enum => qw( allow throttle )], - default => 'throttle', - } - ); + # behavior Perlbal::Service::add_tunable( whitelist_file => { check_role => '*', @@ -40,6 +33,14 @@ sub load { default => undef, } ); + Perlbal::Service::add_tunable( + default_action => { + check_role => '*', + des => "Whether to throttle or allow new connections from clients on neither the whitelist nor blacklist.", + check_type => [enum => qw( allow throttle )], + default => 'throttle', + } + ); Perlbal::Service::add_tunable( blacklist_action => { check_role => '*', @@ -48,6 +49,40 @@ sub load { default => 'deny', } ); + + # filters + Perlbal::Service::add_tunable( + path_regex => { + check_role => '*', + des => "Regex which path portion of URI must match for throttling to be in effect.", + } + ); + Perlbal::Service::add_tunable( + method_regex => { + check_role => '*', + des => "Regex which HTTP method must match for throttling to be in effect.", + } + ); + + # logging + Perlbal::Service::add_tunable( + log_events => { + check_role => '*', + des => q{Comma-separated list of events to log (ban, unban, whitelisted, blacklisted, concurrent, throttled, banned; all; none). If this is changed after the plugin is registered, the "throttle reload config" command must be issued.}, + check_type => [regexp => qr/^(ban|unban|whitelisted|blacklisted|concurrent|throttled|banned| |,)+$/, "log_events is a comma-separated list of loggable events"], + default => 'all', + } + ); + Perlbal::Service::add_tunable( + log_only => { + check_role => '*', + des => "Perform the full throttling calculation, but don't actually throttle or deny connections.", + check_type => 'bool', + default => 0, + } + ); + + # throttler parameters Perlbal::Service::add_tunable( throttle_threshold_seconds => { check_role => '*', @@ -81,25 +116,23 @@ sub load { } ); Perlbal::Service::add_tunable( - path_regex => { - check_role => '*', - des => "Regex which path portion of URI must match for throttling to be in effect.", - } - ); - Perlbal::Service::add_tunable( - method_regex => { + ban_threshold => { check_role => '*', - des => "Regex which HTTP method must match for throttling to be in effect.", + des => "Number of accumulated violations required to temporarily ban the source IP.", + check_type => 'int', + default => 0, } ); Perlbal::Service::add_tunable( - log_only => { + ban_expiration => { check_role => '*', - des => "Perform the full throttling calculation, but don't actually throttle.", - check_type => 'bool', - default => 0, + des => "Number of seconds after which banned IP is unbanned.", + check_type => 'int', + default => 60, } ); + + # memcached Perlbal::Service::add_tunable( memcached_servers => { check_role => '*', @@ -121,30 +154,6 @@ sub load { default => 'Throttle', } ); - Perlbal::Service::add_tunable( - ban_threshold => { - check_role => '*', - des => "Number of accumulated violations required to temporarily ban the source IP.", - check_type => 'int', - default => 0, - } - ); - Perlbal::Service::add_tunable( - ban_expiration => { - check_role => '*', - des => "Number of seconds after which banned IP is unbanned.", - check_type => 'int', - default => 60, - } - ); - Perlbal::Service::add_tunable( - log_events => { - check_role => '*', - des => q{Comma-separated list of events to log (ban, unban, whitelisted, blacklisted, concurrent, throttled, banned; all; none). If this is changed after the plugin is registered, the "throttle reload config" command must be issued.}, - check_type => [regexp => qr/^(ban|unban|whitelisted|blacklisted|concurrent|throttled|banned| |,)+$/, "log_events is a comma-separated list of loggable events"], - default => 'all', - } - ); Perlbal::register_global_hook('manage_command.throttle', sub { my $mc = shift->parse(qr/^