Retry 403 in init_agent(), warning just once.

This commit is contained in:
Daniel Nichter
2013-09-23 12:06:05 -07:00
parent f6f121ca82
commit ec2343f379
2 changed files with 25 additions and 10 deletions

View File

@@ -5771,8 +5771,10 @@ sub init_agent {
# Try to create/update the Agent. # Try to create/update the Agent.
my $success = 0; my $success = 0;
while ( $_oktorun->() && $tries-- ) { while ( $_oktorun->() && $tries-- ) {
$logger->info($action eq 'put' ? "Updating agent " . $agent->name if ( !$state->{init_action}++ ) {
: "Creating new agent"); $logger->info($action eq 'put' ? "Updating agent " . $agent->name
: "Creating new agent");
}
my $agent_uri = eval { my $agent_uri = eval {
$client->$action( $client->$action(
link => $link, link => $link,
@@ -5796,10 +5798,12 @@ sub init_agent {
} }
} }
elsif ( $code && $code == 403 ) { elsif ( $code && $code == 403 ) {
$logger->error("API reports too many agents. Check " if ( !$state->{too_many_agents}++ ) {
. "https://cloud.percona.com/agents for the list of " $logger->warning("API reports too many agents. Check "
. "installed agents, delete unused agents, and try again."); . "https://cloud.percona.com/agents for the list of "
last; . "installed agents. Will try again $tries times, "
. "but this warning will not be printed again.");
}
} }
else { else {
$logger->warning($EVAL_ERROR); $logger->warning($EVAL_ERROR);
@@ -5830,6 +5834,9 @@ sub init_agent {
} }
} }
delete $state->{init_action};
delete $state->{too_many_agents};
if ( $agent && $success ) { if ( $agent && $success ) {
$logger->info("Agent " . $agent->name . " (" . $agent->uuid . ") is ready"); $logger->info("Agent " . $agent->name . " (" . $agent->uuid . ") is ready");
} }

View File

@@ -199,7 +199,7 @@ is_deeply(
) or diag(Dumper($ua->{requests})); ) or diag(Dumper($ua->{requests}));
like( like(
$log[3], $log[2],
qr{WARNING Failed to POST /agents}, qr{WARNING Failed to POST /agents},
"POST /agents failure logged after error" "POST /agents failure logged after error"
) or diag(Dumper($ua->{requests}), Dumper(\@log)); ) or diag(Dumper($ua->{requests}), Dumper(\@log));
@@ -306,18 +306,26 @@ $output = output(
is( is(
scalar @wait, scalar @wait,
0, 2,
"Too many agents (403): no wait" "Too many agents (403): waits"
); );
is_deeply( is_deeply(
$ua->{requests}, $ua->{requests},
[ [
'POST /agents', 'POST /agents',
'POST /agents',
], ],
"Too many agents (403): no further requests" "Too many agents (403): tries"
) or diag(Dumper($ua->{requests})); ) or diag(Dumper($ua->{requests}));
my $n = grep { $_ =~ m/too many agents/ } @log;
is(
$n,
1,
"Too many agents (403): does not repeat warning"
) or diag(Dumper(\@log));
# ############################################################################# # #############################################################################
# Done. # Done.
# ############################################################################# # #############################################################################