mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-19 18:34:59 +00:00
Update/fix pt-agent to work with new Service.run_schedule and Service.spool_schedule attribs.
This commit is contained in:
@@ -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";
|
||||
|
||||
|
@@ -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.
|
||||
# #############################################################################
|
||||
|
@@ -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"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
|
@@ -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(
|
||||
|
2
t/pt-agent/samples/crontab004.in
Normal file
2
t/pt-agent/samples/crontab004.in
Normal file
@@ -0,0 +1,2 @@
|
||||
1 * * * * pt-agent --run-service foo
|
||||
2 * * * * pt-agent --send-data foo
|
2
t/pt-agent/samples/crontab004.out
Normal file
2
t/pt-agent/samples/crontab004.out
Normal 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
|
@@ -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"}
|
@@ -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>
|
||||
|
@@ -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,
|
Reference in New Issue
Block a user