diff --git a/bin/pt-agent b/bin/pt-agent index d5c21342..042c0271 100755 --- a/bin/pt-agent +++ b/bin/pt-agent @@ -5771,8 +5771,10 @@ sub init_agent { # Try to create/update the Agent. my $success = 0; while ( $_oktorun->() && $tries-- ) { - $logger->info($action eq 'put' ? "Updating agent " . $agent->name - : "Creating new agent"); + if ( !$state->{init_action}++ ) { + $logger->info($action eq 'put' ? "Updating agent " . $agent->name + : "Creating new agent"); + } my $agent_uri = eval { $client->$action( link => $link, @@ -5796,10 +5798,12 @@ sub init_agent { } } elsif ( $code && $code == 403 ) { - $logger->error("API reports too many agents. Check " - . "https://cloud.percona.com/agents for the list of " - . "installed agents, delete unused agents, and try again."); - last; + if ( !$state->{too_many_agents}++ ) { + $logger->warning("API reports too many agents. Check " + . "https://cloud.percona.com/agents for the list of " + . "installed agents. Will try again $tries times, " + . "but this warning will not be printed again."); + } } else { $logger->warning($EVAL_ERROR); @@ -5830,6 +5834,9 @@ sub init_agent { } } + delete $state->{init_action}; + delete $state->{too_many_agents}; + if ( $agent && $success ) { $logger->info("Agent " . $agent->name . " (" . $agent->uuid . ") is ready"); } diff --git a/t/pt-agent/init_agent.t b/t/pt-agent/init_agent.t index dc83d885..ce02feac 100644 --- a/t/pt-agent/init_agent.t +++ b/t/pt-agent/init_agent.t @@ -199,7 +199,7 @@ is_deeply( ) or diag(Dumper($ua->{requests})); like( - $log[3], + $log[2], qr{WARNING Failed to POST /agents}, "POST /agents failure logged after error" ) or diag(Dumper($ua->{requests}), Dumper(\@log)); @@ -306,18 +306,26 @@ $output = output( is( scalar @wait, - 0, - "Too many agents (403): no wait" + 2, + "Too many agents (403): waits" ); is_deeply( $ua->{requests}, [ 'POST /agents', + 'POST /agents', ], - "Too many agents (403): no further requests" + "Too many agents (403): tries" ) 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. # #############################################################################