From 1e935ee63189c91892f19ed024f39bf9a9b6b9cd Mon Sep 17 00:00:00 2001 From: Adam Thomason Date: Tue, 20 Sep 2011 23:23:34 -0700 Subject: [PATCH 1/3] Call backend_response_received after reproxy reponse Currently backend_response_received is only called after the primary response (which contains X-Reproxy-URL). --- lib/Perlbal/ClientProxy.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Perlbal/ClientProxy.pm b/lib/Perlbal/ClientProxy.pm index f4fda73..8e10858 100644 --- a/lib/Perlbal/ClientProxy.pm +++ b/lib/Perlbal/ClientProxy.pm @@ -283,6 +283,8 @@ sub backend_response_received { return 1; } + return $self->{service}->run_hook('backend_response_received', $be); + # a response means that we are no longer currently waiting on a reproxy, and # don't want to retry this URI $self->{currently_reproxying} = undef; From 66bb7c4a0de8f6df42c134c1375870deefe2e6e6 Mon Sep 17 00:00:00 2001 From: Adam Thomason Date: Wed, 21 Sep 2011 18:23:54 -0700 Subject: [PATCH 2/3] Rename new hook to backend_response_received --- doc/hacking/hooks.txt | 8 ++++++++ lib/Perlbal/ClientProxy.pm | 2 +- lib/Perlbal/Manual/Hooks.pod | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/hacking/hooks.txt b/doc/hacking/hooks.txt index 835b6c5..9f34eb9 100644 --- a/doc/hacking/hooks.txt +++ b/doc/hacking/hooks.txt @@ -107,6 +107,14 @@ HANDLER backend_response_received Perlbal::BackendHTTP Called as soon as response headers are read from the backend. If you return a true value, will stop all handling at that point. +HANDLER reproxy_response_received Perlbal::ClientProxy +Called as soon as response headers are read from a reproxied backend. If you +return a true value, will stop all handling at that point. + +Called in L. + +Available in role C. + HANDLER make_high_priority Perlbal::ClientProxy Called when a request is received and right before we're about to determine if this request is high priority or not. Return a true value to make the diff --git a/lib/Perlbal/ClientProxy.pm b/lib/Perlbal/ClientProxy.pm index 8e10858..8836085 100644 --- a/lib/Perlbal/ClientProxy.pm +++ b/lib/Perlbal/ClientProxy.pm @@ -283,7 +283,7 @@ sub backend_response_received { return 1; } - return $self->{service}->run_hook('backend_response_received', $be); + return if $self->{service}->run_hook('reproxy_response_received', $be); # a response means that we are no longer currently waiting on a reproxy, and # don't want to retry this URI diff --git a/lib/Perlbal/Manual/Hooks.pod b/lib/Perlbal/Manual/Hooks.pod index dd96783..bc3b6b4 100644 --- a/lib/Perlbal/Manual/Hooks.pod +++ b/lib/Perlbal/Manual/Hooks.pod @@ -161,6 +161,15 @@ Called in L. Available in role C. +=head3 reproxy_response_received + +Called as soon as response headers are read from a reproxied backend. If you return a true value, will stop all handling at that point. + +Called in L. + +Available in role C. + + =head3 return_to_base Called when a request has been finished, and control of the Client* object is about to be transferred back to ownership by a service selector. Return a true value if the perlbal core action in this situation should be bypassed. From fe8a18485eb40bf300cf69ecf8f33bece968868f Mon Sep 17 00:00:00 2001 From: Adam Thomason Date: Sat, 23 Jun 2012 18:18:18 -0700 Subject: [PATCH 3/3] Add dumpconfig support --- lib/Perlbal/Plugin/Throttle.pm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/Perlbal/Plugin/Throttle.pm b/lib/Perlbal/Plugin/Throttle.pm index d75ed1c..c0946ee 100644 --- a/lib/Perlbal/Plugin/Throttle.pm +++ b/lib/Perlbal/Plugin/Throttle.pm @@ -295,6 +295,10 @@ sub register { my %banned; my $store = Perlbal::Plugin::Throttle::Store->new($cfg); + $stash->{throttled} = \%throttled; + $stash->{banned} = \%banned; + $stash->{store} = $store; + my $start_handler = sub { my $retval = eval { my $request_start = Time::HiRes::time; @@ -532,6 +536,27 @@ sub load_cidr_list { return $list; } +sub dumpconfig { + my ($class, $svc) = @_; + + my $cfg = $svc->{extra_config} ||= {}; + my $stash = $cfg->{_throttle_stash}; + + (my $storage = $stash->{store} ? ref $stash->{store} : 'none') =~ s/.*://; + my @whitelisted = $stash->{whitelist} ? $stash->{whitelist}->list() : 'none'; + my @blacklisted = $stash->{blacklist} ? $stash->{blacklist}->list() : 'none'; + my @throttled = keys %{ $stash->{throttled} } ? sort keys %{ $stash->{throttled} } : 'none'; + my @banned = keys %{ $stash->{banned} } ? sort keys %{ $stash->{banned} } : 'none'; + + return + '# -- Throttler state --', + '# Storage: ' . $storage, + '# Whitelisted: ' . join(', ', @whitelisted), + '# Blacklisted: ' . join(', ', @blacklisted), + '# Throttled: ' . join(', ', @throttled), + '# Banned: ' . join(', ', @banned), +} + package Perlbal::Plugin::Throttle::Store; sub new {