Merge lp:~percona-toolkit-dev/percona-toolkit/pt-slave-find-add-resolve-address-option-1418446 into lp:~percona-toolkit-dev/percona-toolkit/release-2.2.14

Proposed by Frank Cizmich
Status: Merged
Approved by: Daniel Nichter
Approved revision: 614
Merged at revision: 621
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/pt-slave-find-add-resolve-address-option-1418446
Merge into: lp:~percona-toolkit-dev/percona-toolkit/release-2.2.14
Diff against target: 134 lines (+52/-6)
2 files modified
bin/pt-slave-find (+39/-5)
t/pt-slave-find/pt-slave-find.t (+13/-1)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/pt-slave-find-add-resolve-address-option-1418446
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+253576@code.launchpad.net

Description of the change

In response to feature request:

Adds option --resolve-address to pt-slave-find.
This makes the tool resolve the IP address of the server to a hostname and print it out within parenthesis alongside the IP.

Example:

127.0.0.1:12345 (db1.sample.net)
+- 127.0.0.1:12346 (db2.sample.net)
   +- 127.0.0.1:12347 (db3.sample.net)

Off by default

To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

Just one spelling suggestion, otherwise code is fine.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/pt-slave-find'
--- bin/pt-slave-find 2015-01-23 10:19:56 +0000
+++ bin/pt-slave-find 2015-03-19 20:58:57 +0000
@@ -3778,6 +3778,7 @@
3778 node => $root,3778 node => $root,
3779 print_node => $print_node,3779 print_node => $print_node,
3780 MasterSlave => $ms,3780 MasterSlave => $ms,
3781 resolve_address => $o->get('resolve-address'),
3781 );3782 );
37823783
3783 return 0;3784 return 0;
@@ -3823,7 +3824,7 @@
38233824
3824sub print_node_hostname {3825sub print_node_hostname {
3825 my ( %args ) = @_;3826 my ( %args ) = @_;
3826 my ($ms, $node, $level) = @args{qw(MasterSlave node level)};3827 my ($ms, $node, $level, $resolve_address) = @args{qw(MasterSlave node level resolve_address)};
3827 die "I need a node" unless $node;3828 die "I need a node" unless $node;
3828 $level ||= 0;3829 $level ||= 0;
38293830
@@ -3833,15 +3834,16 @@
3833 my $prefix = $level ? (' ' x (($level-1)*3) . '+- ') : '';3834 my $prefix = $level ? (' ' x (($level-1)*3) . '+- ') : '';
38343835
3835 PTDEBUG && _d('level', $level, 'host', $host);3836 PTDEBUG && _d('level', $level, 'host', $host);
3836 print "$prefix$host\n";3837
3838 print_host($prefix, $host, $resolve_address);
38373839
3838 return;3840 return;
3839}3841}
38403842
3841sub print_node_summary {3843sub print_node_summary {
3842 my ( %args ) = @_;3844 my ( %args ) = @_;
3843 my ($ms, $node, $level)3845 my ($ms, $node, $level, $resolve_address)
3844 = @args{qw(MasterSlave node level)};3846 = @args{qw(MasterSlave node level resolve_address)};
3845 die "I need a node" unless $node;3847 die "I need a node" unless $node;
3846 $level ||= 0;3848 $level ||= 0;
38473849
@@ -3851,7 +3853,7 @@
38513853
3852 PTDEBUG && _d('level', $level, 'host', $host);3854 PTDEBUG && _d('level', $level, 'host', $host);
38533855
3854 print "$prefix$host\n";3856 print_host($prefix, $host, $resolve_address);
38553857
3856 my $dbh = $node->{dbh};3858 my $dbh = $node->{dbh};
3857 if ( !$dbh ) {3859 if ( !$dbh ) {
@@ -3923,6 +3925,28 @@
3923 return;3925 return;
3924}3926}
39253927
3928sub print_host {
3929 my ($prefix, $host, $resolve_address) = @_;
3930
3931 my $hostname;
3932 # resolve address to hostname if user requested it
3933 if($resolve_address) {
3934 use Socket;
3935 my $without_port = $host;
3936 $without_port =~ s/:\d*$//; # strip port from ip address
3937 my $packed = inet_aton($without_port);
3938 if ($packed) {
3939 $hostname = gethostbyaddr($packed, AF_INET);
3940 }
3941 }
3942 if ($hostname) {
3943 print "$prefix$host ($hostname)\n";
3944 }
3945 else {
3946 print "$prefix$host\n";
3947 }
3948}
3949
3926sub _d {3950sub _d {
3927 my ($package, undef, $line) = caller 0;3951 my ($package, undef, $line) = caller 0;
3928 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }3952 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -4155,6 +4179,16 @@
41554179
4156=back4180=back
41574181
4182=item --resolve-address
4183
4184Resolve ip-address to hostname. Report will print both IP and hostname.
4185
4186Example:
4187
4188 10.10.7.14 (dbase1.sample.net)
4189
4190Might delay runtime a few seconds.
4191
4158=item --set-vars4192=item --set-vars
41594193
4160type: Array4194type: Array
41614195
=== modified file 't/pt-slave-find/pt-slave-find.t'
--- t/pt-slave-find/pt-slave-find.t 2012-08-14 23:08:06 +0000
+++ t/pt-slave-find/pt-slave-find.t 2015-03-19 20:58:57 +0000
@@ -43,7 +43,7 @@
43 plan skip_all => 'Cannot connect to second sandbox slave';43 plan skip_all => 'Cannot connect to second sandbox slave';
44}44}
45else {45else {
46 plan tests => 9;46 plan tests => 10;
47}47}
4848
49my @args = ('h=127.0.0.1,P=12345,u=msandbox,p=msandbox');49my @args = ('h=127.0.0.1,P=12345,u=msandbox,p=msandbox');
@@ -67,6 +67,17 @@
67EOF67EOF
68is($output, $expected, 'Master with slave and slave of slave');68is($output, $expected, 'Master with slave and slave of slave');
6969
70###############################################################################
71# Test --resolve-hostname option (we don't know the hostname of the test
72# machine so we settle for any non null string)
73###############################################################################
74$output = `$trunk/bin/pt-slave-find -h 127.0.0.1 -P 12345 -u msandbox -p msandbox --report-format hostname --resolve-address`;
75like (
76 $output,
77 qr/127\.0\.0\.1:12345\s+\(\w+\)/s,
78 "--resolve-address option"
79) or diag($output);
80
70# #############################################################################81# #############################################################################
71# Until MasterSlave::find_slave_hosts() is improved to overcome the problems82# Until MasterSlave::find_slave_hosts() is improved to overcome the problems
72# with SHOW SLAVE HOSTS, this test won't work.83# with SHOW SLAVE HOSTS, this test won't work.
@@ -146,6 +157,7 @@
146 "Summary report format",157 "Summary report format",
147);158);
148159
160
149# #############################################################################161# #############################################################################
150# Done.162# Done.
151# #############################################################################163# #############################################################################

Subscribers

People subscribed via source and target branches

to all changes: