Change --check-spool to --send-data, and Run->schedule to Run->run_schedule. Add Run->spool_schedule and Run->queries. Remove Service->alias.

This commit is contained in:
Daniel Nichter
2013-01-14 15:02:07 -07:00
parent 526437632c
commit 8f59c9f357
8 changed files with 90 additions and 60 deletions

View File

@@ -1214,24 +1214,24 @@ has 'name' => (
required => 1, required => 1,
); );
has 'alias' => (
is => 'ro',
isa => 'Str',
required => 1,
);
has 'schedule' => (
is => 'ro',
isa => 'Str',
required => 1,
);
has 'runs' => ( has 'runs' => (
is => 'ro', is => 'ro',
isa => 'ArrayRef[Percona::WebAPI::Resource::Run]', isa => 'ArrayRef[Percona::WebAPI::Resource::Run]',
required => 1, required => 1,
); );
has 'run_schedule' => (
is => 'ro',
isa => 'Str',
required => 1,
);
has 'spool_schedule' => (
is => 'ro',
isa => 'Str',
required => 0,
);
sub BUILDARGS { sub BUILDARGS {
my ($class, %args) = @_; my ($class, %args) = @_;
if ( ref $args{runs} eq 'ARRAY' ) { if ( ref $args{runs} eq 'ARRAY' ) {
@@ -1283,6 +1283,13 @@ has 'options' => (
required => 0, required => 0,
); );
has 'queries' => (
is => 'ro',
isa => 'Maybe[ArrayRef]',
required => 0,
default => undef,
);
has 'output' => ( has 'output' => (
is => 'ro', is => 'ro',
isa => 'Str', isa => 'Str',
@@ -4425,9 +4432,9 @@ sub main {
} }
my $agent_id = $o->get('agent-id'); my $agent_id = $o->get('agent-id');
if ( ($o->get('check-spool') || $o->get('run-service')) && !$agent_id ) { if ( ($o->get('run-service') || $o->get('send-data')) && !$agent_id ) {
_err("No agent ID was found or specified. --check-spool and " _err("No agent ID was found or specified. --run-service and "
. "--run-service require an agent ID. Run pt-agent without these " . "--send-data require an agent ID. Run pt-agent without these "
. "options to create and configure the agent, then try again."); . "options to create and configure the agent, then try again.");
} }
@@ -4454,14 +4461,15 @@ sub main {
); );
# ######################################################################## # ########################################################################
# --check-spool # --send-data
# ######################################################################## # ########################################################################
if ( $o->get('check-spool') ) { if ( my $service = $o->get('send-data') ) {
# TODO: rewrite Daemon to have args passed in so we can do # TODO: rewrite Daemon to have args passed in so we can do
# a PID file check for spool procs. Or implement file locking. # a PID file check for spool procs. Or implement file locking.
check_spool( send_data(
client => $client, client => $client,
agent => $agent, agent => $agent,
service => $service,
spool_dir => $o->get('spool'), spool_dir => $o->get('spool'),
); );
_info("Done checking spool, exit $exit_status"); _info("Done checking spool, exit $exit_status");
@@ -4543,7 +4551,7 @@ sub main {
# Percona Web API subs for agent and spool processes # # Percona Web API subs for agent and spool processes #
# ################################################## # # ################################################## #
# Wrapper for code common to main agent and --check-spool process: # Wrapper for code common to main agent and --send-data processes:
# connect to the Percona web API by getting a client and an Agent. # connect to the Percona web API by getting a client and an Agent.
sub connect_to_percona { sub connect_to_percona {
my (%args) = @_; my (%args) = @_;
@@ -4752,8 +4760,6 @@ sub run_agent {
_warn($EVAL_ERROR); _warn($EVAL_ERROR);
} }
# TODO: need to schedule a pt-agent --check-spool process.
# Get services only if there's a current, running config. # Get services only if there's a current, running config.
# Without one, we won't know how to implement services. # Without one, we won't know how to implement services.
if ( $config ) { if ( $config ) {
@@ -4782,8 +4788,7 @@ sub run_agent {
$services = $new_services; $services = $new_services;
_info('Services updated successfully: ' _info('Services updated successfully: '
. join(', ', map { $_->alias . ' (' . $_->name . ')' } . join(', ', map { $_->name } @$services));
@$services));
} }
else { else {
_info('Services have not changed'); _info('Services have not changed');
@@ -4893,8 +4898,8 @@ sub write_services {
return; return;
} }
# Write Service->schedule lines to crontab, along with any other # Write Service->run_schedule and (optionally) Service->spool_schedule
# non-pt-agent lines, and load. # lines to crontab, along with any other non-pt-agent lines, and load.
sub schedule_services { sub schedule_services {
my (%args) = @_; my (%args) = @_;
@@ -4928,8 +4933,9 @@ sub schedule_services {
return; return;
} }
# Combine Service->schedule lines with non-pt-agent lines, # Combine Service->run_schedule and (optionally) Service->spool_schedule
# i.e. don't clobber the user's other crontab lines. # lines with non-pt-agent lines, i.e. don't clobber the user's other
# crontab lines.
sub make_new_crontab { sub make_new_crontab {
my (%args) = @_; my (%args) = @_;
@@ -4949,7 +4955,15 @@ sub make_new_crontab {
my @pt_agent_lines; my @pt_agent_lines;
foreach my $service ( @$services ) { foreach my $service ( @$services ) {
push @pt_agent_lines, push @pt_agent_lines,
$service->schedule . " pt-agent --run-service " . $service->name; $service->run_schedule
. " pt-agent --run-service "
. $service->name;
if ( $service->spool_schedule ) {
push @pt_agent_lines,
$service->spool_schedule
. " pt-agent --send-data "
. $service->name;
}
} }
my $new_crontab = join("\n", @other_lines, @pt_agent_lines) . "\n"; my $new_crontab = join("\n", @other_lines, @pt_agent_lines) . "\n";
@@ -5105,16 +5119,18 @@ sub replace_special_vars {
# Send every file or directory in each service's directory in --spool/. # Send every file or directory in each service's directory in --spool/.
# E.g. --spool/query-monitor should contain files with pt-query-digest # E.g. --spool/query-monitor should contain files with pt-query-digest
# output. The per-service dirs are created in run_service(). # output. The per-service dirs are created in run_service().
sub check_spool { sub send_data {
my (%args) = @_; my (%args) = @_;
have_required_args(\%args, qw( have_required_args(\%args, qw(
client client
agent agent
service
spool_dir spool_dir
)) or die; )) or die;
my $client = $args{client}; my $client = $args{client};
my $agent = $args{agent}; my $agent = $args{agent};
my $service = $args{service};
my $spool_dir = $args{spool_dir}; my $spool_dir = $args{spool_dir};
# Iterate through the service dirs in --spool/. # Iterate through the service dirs in --spool/.
@@ -5374,7 +5390,7 @@ TODO
=head1 OPTIONS =head1 OPTIONS
L<"--check-spool"> and L<"--run-service"> are mutually exclusive. L<"--run-service"> and L<"--send-data"> are mutually exclusive.
=over =over
@@ -5398,14 +5414,10 @@ Prompt for a password when connecting to MySQL.
=item --check-interval =item --check-interval
type: time; default: 5m type: time; default: 10m
Sleep time between checks. Sleep time between checks.
=item --check-spool
Check for new L<"--spool"> data to send.
=item --config =item --config
type: Array type: Array
@@ -5478,7 +5490,13 @@ Port number to use for connection.
type: string type: string
Run a Percona Web Service. Run the given Percona Web Service.
=item --send-data
type: string
Send data for the given Percona Web Service.
=item --set-vars =item --set-vars

View File

@@ -40,6 +40,13 @@ has 'options' => (
required => 0, required => 0,
); );
has 'queries' => (
is => 'ro',
isa => 'Maybe[ArrayRef]',
required => 0,
default => undef,
);
has 'output' => ( has 'output' => (
is => 'ro', is => 'ro',
isa => 'Str', isa => 'Str',

View File

@@ -28,24 +28,24 @@ has 'name' => (
required => 1, required => 1,
); );
has 'alias' => (
is => 'ro',
isa => 'Str',
required => 1,
);
has 'schedule' => (
is => 'ro',
isa => 'Str',
required => 1,
);
has 'runs' => ( has 'runs' => (
is => 'ro', is => 'ro',
isa => 'ArrayRef[Percona::WebAPI::Resource::Run]', isa => 'ArrayRef[Percona::WebAPI::Resource::Run]',
required => 1, required => 1,
); );
has 'run_schedule' => (
is => 'ro',
isa => 'Str',
required => 1,
);
has 'spool_schedule' => (
is => 'ro',
isa => 'Str',
required => 0,
);
sub BUILDARGS { sub BUILDARGS {
my ($class, %args) = @_; my ($class, %args) = @_;
if ( ref $args{runs} eq 'ARRAY' ) { if ( ref $args{runs} eq 'ARRAY' ) {

View File

@@ -54,10 +54,10 @@ 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 => '* 8 * * 1,2,3,4,5',
schedule => '* 8 * * 1,2,3,4,5', spool_schedule => '* 9 * * 1,2,3,4,5',
runs => [ $run0 ], runs => [ $run0 ],
); );
# Empty crontab, add the service. # Empty crontab, add the service.
@@ -116,6 +116,7 @@ SKIP: {
$new_crontab, $new_crontab,
"* 0 * * * date > /dev/null "* 0 * * * date > /dev/null
* 8 * * 1,2,3,4,5 pt-agent --run-service query-monitor * 8 * * 1,2,3,4,5 pt-agent --run-service query-monitor
* 9 * * 1,2,3,4,5 pt-agent --send-data query-monitor
", ",
"Runs crontab -l by default" "Runs crontab -l by default"
); );

View File

@@ -1 +1,2 @@
* 8 * * 1,2,3,4,5 pt-agent --run-service query-monitor * 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,2 +1,3 @@
17 3 * * 1 cmd 17 3 * * 1 cmd
* 8 * * 1,2,3,4,5 pt-agent --run-service query-monitor * 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,2 +1,3 @@
17 3 * * 1 cmd 17 3 * * 1 cmd
* 8 * * 1,2,3,4,5 pt-agent --run-service query-monitor * 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

@@ -38,10 +38,10 @@ 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 => '* 8 * * 1,2,3,4,5',
schedule => '* 8 * * 1,2,3,4,5', spool_schedule => '* 9 * * 1,2,3,4,5',
runs => [ $run0 ], runs => [ $run0 ],
); );
# First add a fake line so we can know that the real, existing # First add a fake line so we can know that the real, existing
@@ -84,6 +84,7 @@ is(
$crontab, $crontab,
"* 0 * * * date > /dev/null "* 0 * * * date > /dev/null
* 8 * * 1,2,3,4,5 pt-agent --run-service query-monitor * 8 * * 1,2,3,4,5 pt-agent --run-service query-monitor
* 9 * * 1,2,3,4,5 pt-agent --send-data query-monitor
", ",
"schedule_services()" "schedule_services()"
); );
@@ -118,10 +119,10 @@ is(
# ############################################################################# # #############################################################################
$svc0 = Percona::WebAPI::Resource::Service->new( $svc0 = Percona::WebAPI::Resource::Service->new(
name => 'query-monitor', name => 'query-monitor',
alias => 'Query Monitor', run_schedule => '* * * * Foo', # "foo":0: bad day-of-week
schedule => '* * * * Foo', # "foo":0: bad day-of-week spool_schedule => '* 8 * * Mon',
runs => [ $run0 ], runs => [ $run0 ],
); );
eval { eval {