Update Lmo in pt-agent. Start fixing pt-agent tests.

This commit is contained in:
Daniel Nichter
2013-03-19 12:10:22 -06:00
7 changed files with 82 additions and 16 deletions

View File

@@ -101,6 +101,65 @@ sub _d {
# End Percona::Toolkit package
# ###########################################################################
# ###########################################################################
# Lmo::Utils package
# ###########################################################################
package Lmo::Utils;
use strict;
use warnings qw( FATAL all );
require Exporter;
our (@ISA, @EXPORT, @EXPORT_OK);
BEGIN {
@ISA = qw(Exporter);
@EXPORT = @EXPORT_OK = qw(
_install_coderef
_unimport_coderefs
_glob_for
_stash_for
);
}
{
# Gets the glob from a given string.
no strict 'refs';
sub _glob_for {
return \*{shift()}
}
# Gets the stash from a given string.
# A stash is a symbol table hash; rough explanation on
# http://perldoc.perl.org/perlguts.html#Stashes-and-Globs
# But the gist of it is that we can use a hash-like thing to
# refer to a class and modify it.
sub _stash_for {
return \%{ shift() . "::" };
}
}
sub _install_coderef {
my ($to, $code) = @_;
return *{ _glob_for $to } = $code;
}
sub _unimport_coderefs {
my ($target, @names) = @_;
return unless @names;
my $stash = _stash_for($target);
foreach my $name (@names) {
if ($stash->{$name} and defined(&{$stash->{$name}})) {
delete $stash->{$name};
}
}
}
1;
# ###########################################################################
# End Lmo::Utils package
# ###########################################################################
# ###########################################################################
# Lmo::Meta package
# This package is a copy without comments from the original. The original

View File

@@ -15,7 +15,7 @@
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
# ###########################################################################
# Lmo::Types package
# Lmo::Utils package
# ###########################################################################
package Lmo::Utils;

View File

@@ -46,7 +46,8 @@ sub test_make_new_crontab {
) or diag($new_crontab);
}
my $run0 = Percona::WebAPI::Resource::Run->new(
my $run0 = Percona::WebAPI::Resource::Task->new(
name => 'query-history',
number => '0',
program => 'pt-query-digest',
options => '--output json',
@@ -57,7 +58,7 @@ my $svc0 = Percona::WebAPI::Resource::Service->new(
name => 'query-monitor',
run_schedule => '* 8 * * 1,2,3,4,5',
spool_schedule => '* 9 * * 1,2,3,4,5',
runs => [ $run0 ],
tasks => [ $run0 ],
);
# Empty crontab, add the service.

View File

@@ -86,7 +86,7 @@ my $interval = sub {
# same config.
my $config = Percona::WebAPI::Resource::Config->new(
id => '1',
ts => 1363720060,
name => 'Default',
options => {
'check-interval' => "60",
@@ -97,7 +97,8 @@ my $config = Percona::WebAPI::Resource::Config->new(
},
);
my $run0 = Percona::WebAPI::Resource::Run->new(
my $run0 = Percona::WebAPI::Resource::Task->new(
name => 'query-history',
number => '0',
program => 'pt-query-digest',
options => '--output json',
@@ -108,7 +109,7 @@ my $svc0 = Percona::WebAPI::Resource::Service->new(
name => 'query-monitor',
run_schedule => '1 * * * *',
spool_schedule => '2 * * * *',
runs => [ $run0 ],
tasks => [ $run0 ],
links => {
send_data => '/query-monitor',
},

View File

@@ -53,7 +53,8 @@ sub write_svc_files {
# Simple single run service
# #############################################################################
my $run0 = Percona::WebAPI::Resource::Run->new(
my $run0 = Percona::WebAPI::Resource::Task->new(
name => 'query-history',
number => '0',
program => "$trunk/bin/pt-query-digest",
options => "--report-format profile $trunk/t/lib/samples/slowlogs/slow008.txt",
@@ -64,7 +65,7 @@ my $svc0 = Percona::WebAPI::Resource::Service->new(
name => 'query-monitor',
run_schedule => '1 * * * *',
spool_schedule => '2 * * * *',
runs => [ $run0 ],
tasks => [ $run0 ],
);
write_svc_files(
@@ -115,14 +116,16 @@ diag(`rm -rf $tmpdir/spool/* $tmpdir/services/*`);
# log to a tmp file which pt-agent should auto-create. Then pqd in run1
# references this tmp file.
$run0 = Percona::WebAPI::Resource::Run->new(
$run0 = Percona::WebAPI::Resource::Task->new(
name => 'cat-slow-log',
number => '0',
program => "cat",
options => "$trunk/t/lib/samples/slowlogs/slow008.txt",
output => 'tmp',
);
my $run1 = Percona::WebAPI::Resource::Run->new(
my $run1 = Percona::WebAPI::Resource::Task->new(
name => 'query-history',
number => '1',
program => "$trunk/bin/pt-query-digest",
options => "--report-format profile __RUN_0_OUTPUT__",
@@ -133,7 +136,7 @@ $svc0 = Percona::WebAPI::Resource::Service->new(
name => 'query-monitor',
run_schedule => '3 * * * *',
spool_schedule => '4 * * * *',
runs => [ $run0, $run1 ],
tasks => [ $run0, $run1 ],
);
write_svc_files(

View File

@@ -30,7 +30,8 @@ my $tmpdir = tempdir("/tmp/pt-agent.$PID.XXXXXX", CLEANUP => 1);
# Schedule a good crontab.
# #############################################################################
my $run0 = Percona::WebAPI::Resource::Run->new(
my $run0 = Percona::WebAPI::Resource::Task->new(
name => 'query-history',
number => '0',
program => 'pt-query-digest',
options => '--output json',
@@ -41,7 +42,7 @@ my $svc0 = Percona::WebAPI::Resource::Service->new(
name => 'query-monitor',
run_schedule => '* 8 * * 1,2,3,4,5',
spool_schedule => '* 9 * * 1,2,3,4,5',
runs => [ $run0 ],
tasks => [ $run0 ],
);
# First add a fake line so we can know that the real, existing
@@ -122,7 +123,7 @@ $svc0 = Percona::WebAPI::Resource::Service->new(
name => 'query-monitor',
run_schedule => '* * * * Foo', # "foo":0: bad day-of-week
spool_schedule => '* 8 * * Mon',
runs => [ $run0 ],
tasks => [ $run0 ],
);
eval {

View File

@@ -63,7 +63,8 @@ sub test_write_services {
diag(`rm -rf $tmpdir/*`);
}
my $run0 = Percona::WebAPI::Resource::Run->new(
my $run0 = Percona::WebAPI::Resource::Task->new(
name => 'query-history',
number => '0',
program => "pt-query-digest",
options => "--report-format profile slow008.txt",
@@ -74,7 +75,7 @@ my $svc0 = Percona::WebAPI::Resource::Service->new(
name => 'query-monitor',
run_schedule => '1 * * * *',
spool_schedule => '2 * * * *',
runs => [ $run0 ],
tasks => [ $run0 ],
links => { send_data => '/query-monitor' },
);