From bf92ce765ddd5c090be0b242f8d7a1860694575c Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Wed, 30 Jan 2013 13:25:21 -0700 Subject: [PATCH] Update/fix pt-agent to work with new Service.run_schedule and Service.spool_schedule attribs. --- bin/pt-agent | 4 +++- t/pt-agent/make_new_crontab.t | 8 +++++++- t/pt-agent/run_agent.t | 16 +++++++++++----- t/pt-agent/run_service.t | 16 ++++++++-------- t/pt-agent/samples/crontab004.in | 2 ++ t/pt-agent/samples/crontab004.out | 2 ++ t/pt-agent/samples/service001 | 2 +- t/pt-agent/samples/spool001.txt | 8 ++++---- t/pt-agent/{check_spool.t => send_data.t} | 5 +++-- 9 files changed, 41 insertions(+), 22 deletions(-) create mode 100644 t/pt-agent/samples/crontab004.in create mode 100644 t/pt-agent/samples/crontab004.out rename t/pt-agent/{check_spool.t => send_data.t} (97%) diff --git a/bin/pt-agent b/bin/pt-agent index 68b214a4..ec7daaec 100755 --- a/bin/pt-agent +++ b/bin/pt-agent @@ -4951,8 +4951,9 @@ sub make_new_crontab { : `crontab -l 2>/dev/null`; my @other_lines - = grep { $_ !~ m/pt-agent --run-service/ } + = grep { $_ !~ m/pt-agent (?:--run-service|--send-data)/ } split("\n", $crontab_list); + PTDEBUG && _d('Other crontab lines:', \@other_lines); my @pt_agent_lines; foreach my $service ( @$services ) { @@ -4968,6 +4969,7 @@ sub make_new_crontab { . $service->name; } } + PTDEBUG && _d('pt-agent crontab lines:', \@pt_agent_lines); my $new_crontab = join("\n", @other_lines, @pt_agent_lines) . "\n"; diff --git a/t/pt-agent/make_new_crontab.t b/t/pt-agent/make_new_crontab.t index 113fdf2d..40bd8b03 100644 --- a/t/pt-agent/make_new_crontab.t +++ b/t/pt-agent/make_new_crontab.t @@ -43,7 +43,7 @@ sub test_make_new_crontab { cmd_output => 1, ), $args{name} || $file, - ); + ) or diag($new_crontab); } my $run0 = Percona::WebAPI::Resource::Run->new( @@ -79,6 +79,12 @@ test_make_new_crontab( services => [ $svc0 ], ); +# Crontab has old service, remove it and add only new service. +test_make_new_crontab( + file => "crontab004", + services => [ $svc0 ], +); + # ############################################################################# # Use real crontab. # ############################################################################# diff --git a/t/pt-agent/run_agent.t b/t/pt-agent/run_agent.t index 36a5b8d8..8bab3b98 100644 --- a/t/pt-agent/run_agent.t +++ b/t/pt-agent/run_agent.t @@ -143,10 +143,10 @@ my $run0 = Percona::WebAPI::Resource::Run->new( ); my $svc0 = Percona::WebAPI::Resource::Service->new( - name => 'query-monitor', - alias => 'Query Monitor', - schedule => '* * * * *', - runs => [ $run0 ], + name => 'query-monitor', + run_schedule => '1 * * * *', + spool_schedule => '2 * * * *', + runs => [ $run0 ], ); $ua->{responses}->{get} = [ @@ -245,7 +245,13 @@ $crontab = `crontab -l 2>/dev/null`; like( $crontab, qr/pt-agent --run-service query-monitor$/m, - "Scheduled service with crontab" + "Scheduled --run-service with crontab" +); + +like( + $crontab, + qr/pt-agent --send-data query-monitor$/m, + "Scheduled --send-data with crontab" ); # ############################################################################# diff --git a/t/pt-agent/run_service.t b/t/pt-agent/run_service.t index dd2f4f62..362e7b93 100644 --- a/t/pt-agent/run_service.t +++ b/t/pt-agent/run_service.t @@ -61,10 +61,10 @@ my $run0 = Percona::WebAPI::Resource::Run->new( ); my $svc0 = Percona::WebAPI::Resource::Service->new( - name => 'query-monitor', - alias => 'Query Monitor', - schedule => '* * * * *', - runs => [ $run0 ], + name => 'query-monitor', + run_schedule => '1 * * * *', + spool_schedule => '2 * * * *', + runs => [ $run0 ], ); write_svc_files( @@ -130,10 +130,10 @@ my $run1 = Percona::WebAPI::Resource::Run->new( ); $svc0 = Percona::WebAPI::Resource::Service->new( - name => 'query-monitor', - alias => 'Query Monitor', - schedule => '* * * * *', - runs => [ $run0, $run1 ], + name => 'query-monitor', + run_schedule => '3 * * * *', + spool_schedule => '4 * * * *', + runs => [ $run0, $run1 ], ); write_svc_files( diff --git a/t/pt-agent/samples/crontab004.in b/t/pt-agent/samples/crontab004.in new file mode 100644 index 00000000..5dfa2eff --- /dev/null +++ b/t/pt-agent/samples/crontab004.in @@ -0,0 +1,2 @@ +1 * * * * pt-agent --run-service foo +2 * * * * pt-agent --send-data foo diff --git a/t/pt-agent/samples/crontab004.out b/t/pt-agent/samples/crontab004.out new file mode 100644 index 00000000..1cb21262 --- /dev/null +++ b/t/pt-agent/samples/crontab004.out @@ -0,0 +1,2 @@ +* 8 * * 1,2,3,4,5 pt-agent --run-service query-monitor +* 9 * * 1,2,3,4,5 pt-agent --send-data query-monitor diff --git a/t/pt-agent/samples/service001 b/t/pt-agent/samples/service001 index 69800703..09a96d6f 100644 --- a/t/pt-agent/samples/service001 +++ b/t/pt-agent/samples/service001 @@ -1 +1 @@ -{"runs":[{"number":"0","options":"--output json","output":"spool","program":"pt-query-digest"}],"name":"query-monitor","alias":"Query Monitor","schedule":"* * * * *"} \ No newline at end of file +{"spool_schedule":"2 * * * *","runs":[{"number":"0","options":"--output json","output":"spool","program":"pt-query-digest"}],"run_schedule":"1 * * * *","name":"query-monitor"} \ No newline at end of file diff --git a/t/pt-agent/samples/spool001.txt b/t/pt-agent/samples/spool001.txt index d1492151..0848ec00 100644 --- a/t/pt-agent/samples/spool001.txt +++ b/t/pt-agent/samples/spool001.txt @@ -1,6 +1,6 @@ # Profile -# Rank Query ID Response time Calls R/Call Apdx V/M Item -# ==== ================== ============= ===== ====== ==== ===== ========== -# 1 0xC72BF45D68E35A6E 0.0188 95.4% 1 0.0188 1.00 0.00 SELECT tbl -# MISC 0xMISC 0.0009 4.6% 2 0.0005 NS 0.0 <2 ITEMS> +# Rank Query ID Response time Calls R/Call V/M Item +# ==== ================== ============= ===== ====== ===== ========== +# 1 0xC72BF45D68E35A6E 0.0188 95.4% 1 0.0188 0.00 SELECT tbl +# MISC 0xMISC 0.0009 4.6% 2 0.0005 0.0 <2 ITEMS> diff --git a/t/pt-agent/check_spool.t b/t/pt-agent/send_data.t similarity index 97% rename from t/pt-agent/check_spool.t rename to t/pt-agent/send_data.t index 83c539e0..05576695 100644 --- a/t/pt-agent/check_spool.t +++ b/t/pt-agent/send_data.t @@ -78,7 +78,7 @@ is_deeply( ) or die; # ############################################################################# -# Test check_spool() +# Test send_data() # ############################################################################# my $tmpdir = tempdir("/tmp/pt-agent.$PID.XXXXXX", CLEANUP => 1); @@ -94,10 +94,11 @@ $ua->{responses}->{post} = [ my $output = output( sub { - pt_agent::check_spool( + pt_agent::send_data( client => $client, agent => $agent, spool_dir => $tmpdir, + service => 'query-monitor', ), }, stderr => 1,