Update/fix pt-agent to work with new Service.run_schedule and Service.spool_schedule attribs.

This commit is contained in:
Daniel Nichter
2013-01-30 13:25:21 -07:00
parent 57722889cb
commit bf92ce765d
9 changed files with 41 additions and 22 deletions

View File

@@ -4951,8 +4951,9 @@ sub make_new_crontab {
: `crontab -l 2>/dev/null`; : `crontab -l 2>/dev/null`;
my @other_lines my @other_lines
= grep { $_ !~ m/pt-agent --run-service/ } = grep { $_ !~ m/pt-agent (?:--run-service|--send-data)/ }
split("\n", $crontab_list); split("\n", $crontab_list);
PTDEBUG && _d('Other crontab lines:', \@other_lines);
my @pt_agent_lines; my @pt_agent_lines;
foreach my $service ( @$services ) { foreach my $service ( @$services ) {
@@ -4968,6 +4969,7 @@ sub make_new_crontab {
. $service->name; . $service->name;
} }
} }
PTDEBUG && _d('pt-agent crontab lines:', \@pt_agent_lines);
my $new_crontab = join("\n", @other_lines, @pt_agent_lines) . "\n"; my $new_crontab = join("\n", @other_lines, @pt_agent_lines) . "\n";

View File

@@ -43,7 +43,7 @@ sub test_make_new_crontab {
cmd_output => 1, cmd_output => 1,
), ),
$args{name} || $file, $args{name} || $file,
); ) or diag($new_crontab);
} }
my $run0 = Percona::WebAPI::Resource::Run->new( my $run0 = Percona::WebAPI::Resource::Run->new(
@@ -79,6 +79,12 @@ test_make_new_crontab(
services => [ $svc0 ], services => [ $svc0 ],
); );
# Crontab has old service, remove it and add only new service.
test_make_new_crontab(
file => "crontab004",
services => [ $svc0 ],
);
# ############################################################################# # #############################################################################
# Use real crontab. # Use real crontab.
# ############################################################################# # #############################################################################

View File

@@ -144,8 +144,8 @@ my $run0 = Percona::WebAPI::Resource::Run->new(
my $svc0 = Percona::WebAPI::Resource::Service->new( my $svc0 = Percona::WebAPI::Resource::Service->new(
name => 'query-monitor', name => 'query-monitor',
alias => 'Query Monitor', run_schedule => '1 * * * *',
schedule => '* * * * *', spool_schedule => '2 * * * *',
runs => [ $run0 ], runs => [ $run0 ],
); );
@@ -245,7 +245,13 @@ $crontab = `crontab -l 2>/dev/null`;
like( like(
$crontab, $crontab,
qr/pt-agent --run-service query-monitor$/m, 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"
); );
# ############################################################################# # #############################################################################

View File

@@ -62,8 +62,8 @@ my $run0 = Percona::WebAPI::Resource::Run->new(
my $svc0 = Percona::WebAPI::Resource::Service->new( my $svc0 = Percona::WebAPI::Resource::Service->new(
name => 'query-monitor', name => 'query-monitor',
alias => 'Query Monitor', run_schedule => '1 * * * *',
schedule => '* * * * *', spool_schedule => '2 * * * *',
runs => [ $run0 ], runs => [ $run0 ],
); );
@@ -131,8 +131,8 @@ my $run1 = Percona::WebAPI::Resource::Run->new(
$svc0 = Percona::WebAPI::Resource::Service->new( $svc0 = Percona::WebAPI::Resource::Service->new(
name => 'query-monitor', name => 'query-monitor',
alias => 'Query Monitor', run_schedule => '3 * * * *',
schedule => '* * * * *', spool_schedule => '4 * * * *',
runs => [ $run0, $run1 ], runs => [ $run0, $run1 ],
); );

View File

@@ -0,0 +1,2 @@
1 * * * * pt-agent --run-service foo
2 * * * * pt-agent --send-data foo

View File

@@ -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

View File

@@ -1 +1 @@
{"runs":[{"number":"0","options":"--output json","output":"spool","program":"pt-query-digest"}],"name":"query-monitor","alias":"Query Monitor","schedule":"* * * * *"} {"spool_schedule":"2 * * * *","runs":[{"number":"0","options":"--output json","output":"spool","program":"pt-query-digest"}],"run_schedule":"1 * * * *","name":"query-monitor"}

View File

@@ -1,6 +1,6 @@
# Profile # Profile
# Rank Query ID Response time Calls R/Call Apdx V/M Item # Rank Query ID Response time Calls R/Call V/M Item
# ==== ================== ============= ===== ====== ==== ===== ========== # ==== ================== ============= ===== ====== ===== ==========
# 1 0xC72BF45D68E35A6E 0.0188 95.4% 1 0.0188 1.00 0.00 SELECT tbl # 1 0xC72BF45D68E35A6E 0.0188 95.4% 1 0.0188 0.00 SELECT tbl
# MISC 0xMISC 0.0009 4.6% 2 0.0005 NS 0.0 <2 ITEMS> # MISC 0xMISC 0.0009 4.6% 2 0.0005 0.0 <2 ITEMS>

View File

@@ -78,7 +78,7 @@ is_deeply(
) or die; ) or die;
# ############################################################################# # #############################################################################
# Test check_spool() # Test send_data()
# ############################################################################# # #############################################################################
my $tmpdir = tempdir("/tmp/pt-agent.$PID.XXXXXX", CLEANUP => 1); my $tmpdir = tempdir("/tmp/pt-agent.$PID.XXXXXX", CLEANUP => 1);
@@ -94,10 +94,11 @@ $ua->{responses}->{post} = [
my $output = output( my $output = output(
sub { sub {
pt_agent::check_spool( pt_agent::send_data(
client => $client, client => $client,
agent => $agent, agent => $agent,
spool_dir => $tmpdir, spool_dir => $tmpdir,
service => 'query-monitor',
), ),
}, },
stderr => 1, stderr => 1,