From 2003e63da36a737c53a3a0a6f269c7fabbc0486e Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Wed, 16 Feb 2011 12:54:54 -0500 Subject: [PATCH] Whitespace cleanups. --- check_postgres.pl | 212 +++++++++++++++++++++--------------------- t/00_release.t | 57 +++++++++++- t/02_fsm_pages.t | 2 +- t/02_listener.t | 2 +- t/02_new_version_cp.t | 10 +- t/02_replicate_row.t | 70 +++++++------- 6 files changed, 204 insertions(+), 149 deletions(-) diff --git a/check_postgres.pl b/check_postgres.pl index 57a6f9155..f232025d8 100755 --- a/check_postgres.pl +++ b/check_postgres.pl @@ -714,7 +714,7 @@ die $USAGE unless \%opt, 'version|V', 'verbose|v+', - 'vv', + 'vv', 'help|h', 'quiet|q', 'man', @@ -2633,18 +2633,18 @@ sub validate_integer_for_time { sub perfname { - ## Return a safe label name for Nagios performance data - my $name = shift; + ## Return a safe label name for Nagios performance data + my $name = shift; - my $escape = 0; + my $escape = 0; - $name =~ s/'/''/g and $escape++; + $name =~ s/'/''/g and $escape++; - if ($escape or index($name, ' ') >=0) { - $name = qq{'$name'}; - } + if ($escape or index($name, ' ') >=0) { + $name = qq{'$name'}; + } - return $name; + return $name; } ## end of perfname; @@ -3027,92 +3027,92 @@ FROM ( my %seenit; - ## Store the perf data for sorting at the end - my %perf; + ## Store the perf data for sorting at the end + my %perf; - $db = $info->{db}[0]; + $db = $info->{db}[0]; - if ($db->{slurp} !~ /\w+/o) { - add_ok msg('bloat-nomin') unless $MRTG; - return; - } - ## Not a 'regex' to run_command as we need to check the above first. - if ($db->{slurp} !~ /\d+/) { - add_unknown msg('invalid-query', $db->{slurp}) unless $MRTG; - return; - } + if ($db->{slurp} !~ /\w+/o) { + add_ok msg('bloat-nomin') unless $MRTG; + return; + } + ## Not a 'regex' to run_command as we need to check the above first. + if ($db->{slurp} !~ /\d+/) { + add_unknown msg('invalid-query', $db->{slurp}) unless $MRTG; + return; + } - my $max = -1; - my $maxmsg = '?'; + my $max = -1; + my $maxmsg = '?'; ## The perf must be added before the add_x, so we defer the settings: my (@addwarn, @addcrit); - for my $r (@{ $db->{slurp} }) { + for my $r (@{ $db->{slurp} }) { - for my $v (values %$r) { - $v =~ s/(\d+) bytes/pretty_size($1,1)/ge; - } + for my $v (values %$r) { + $v =~ s/(\d+) bytes/pretty_size($1,1)/ge; + } - my ($dbname,$schema,$table,$tups,$pages,$otta,$bloat,$wp,$wb,$ws) = @$r{ - qw/ db schemaname tablename tups pages otta tbloat wastedpages wastedbytes wastedsize/}; + my ($dbname,$schema,$table,$tups,$pages,$otta,$bloat,$wp,$wb,$ws) = @$r{ + qw/ db schemaname tablename tups pages otta tbloat wastedpages wastedbytes wastedsize/}; - next if skip_item($table, $schema); + next if skip_item($table, $schema); - my ($index,$irows,$ipages,$iotta,$ibloat,$iwp,$iwb,$iws) = @$r{ - qw/ iname irows ipages iotta ibloat wastedipgaes wastedibytes wastedisize/}; + my ($index,$irows,$ipages,$iotta,$ibloat,$iwp,$iwb,$iws) = @$r{ + qw/ iname irows ipages iotta ibloat wastedipgaes wastedibytes wastedisize/}; - ## Made it past the exclusions - $max = -2 if $max == -1; + ## Made it past the exclusions + $max = -2 if $max == -1; - ## Do the table first if we haven't seen it - if (! $seenit{"$dbname.$schema.$table"}++) { - my $nicename = perfname("$schema.$table"); - $perf{$wb}{$nicename}++; - my $msg = msg('bloat-table', $dbname, $schema, $table, $tups, $pages, $otta, $bloat, $wb, $ws); - my $ok = 1; - my $perbloat = $bloat * 100; + ## Do the table first if we haven't seen it + if (! $seenit{"$dbname.$schema.$table"}++) { + my $nicename = perfname("$schema.$table"); + $perf{$wb}{$nicename}++; + my $msg = msg('bloat-table', $dbname, $schema, $table, $tups, $pages, $otta, $bloat, $wb, $ws); + my $ok = 1; + my $perbloat = $bloat * 100; - if ($MRTG) { - $stats{table}{"DB=$dbname TABLE=$schema.$table"} = [$wb, $bloat]; - next; - } - if ($critical->($wb, $perbloat)) { + if ($MRTG) { + $stats{table}{"DB=$dbname TABLE=$schema.$table"} = [$wb, $bloat]; + next; + } + if ($critical->($wb, $perbloat)) { push @addcrit => $msg; - $ok = 0; - } + $ok = 0; + } - if ($ok and $warning->($wb, $perbloat)) { + if ($ok and $warning->($wb, $perbloat)) { push @addwarn => $msg; - $ok = 0; - } - ($max = $wb, $maxmsg = $msg) if $wb > $max and $ok; - } - - ## Now the index, if it exists - if ($index ne '?') { - my $nicename = perfname($index); - $perf{$iwb}{$nicename}++; - my $msg = msg('bloat-index', $dbname, $index, $irows, $ipages, $iotta, $ibloat, $iwb, $iws); - my $ok = 1; - my $iperbloat = $ibloat * 100; - - if ($MRTG) { - $stats{index}{"DB=$dbname INDEX=$index"} = [$iwb, $ibloat]; - next; - } - if ($critical->($iwb, $iperbloat)) { + $ok = 0; + } + ($max = $wb, $maxmsg = $msg) if $wb > $max and $ok; + } + + ## Now the index, if it exists + if ($index ne '?') { + my $nicename = perfname($index); + $perf{$iwb}{$nicename}++; + my $msg = msg('bloat-index', $dbname, $index, $irows, $ipages, $iotta, $ibloat, $iwb, $iws); + my $ok = 1; + my $iperbloat = $ibloat * 100; + + if ($MRTG) { + $stats{index}{"DB=$dbname INDEX=$index"} = [$iwb, $ibloat]; + next; + } + if ($critical->($iwb, $iperbloat)) { push @addcrit => $msg; - $ok = 0; - } + $ok = 0; + } - if ($ok and $warning->($iwb, $iperbloat)) { + if ($ok and $warning->($iwb, $iperbloat)) { push @addwarn => $msg; - $ok = 0; - } - ($max = $iwb, $maxmsg = $msg) if $iwb > $max and $ok; - } - } + $ok = 0; + } + ($max = $iwb, $maxmsg = $msg) if $iwb > $max and $ok; + } + } ## Set a sorted limited perf $db->{perf} = ''; @@ -3134,12 +3134,12 @@ FROM ( $db->{perf} = ''; } - if ($max == -1) { - add_unknown msg('no-match-rel'); - } - elsif ($max != -1) { - add_ok $maxmsg; - } + if ($max == -1) { + add_unknown msg('no-match-rel'); + } + elsif ($max != -1) { + add_ok $maxmsg; + } if ($MRTG) { keys %stats or bad_mrtg(msg('unknown-error')); @@ -4964,11 +4964,11 @@ FROM pg_class c, pg_namespace n WHERE (relkind = %s) AND n.oid = c.relnamespace next ROW if skip_item($name, $schema); - my $nicename = $kind eq 'r' ? "$schema.$name" : $name; + my $nicename = $kind eq 'r' ? "$schema.$name" : $name; $db->{perf} .= sprintf "%s%s=%sB;%s;%s", $VERBOSE==1 ? "\n" : ' ', - perfname($nicename), $size, $warning, $critical; + perfname($nicename), $size, $warning, $critical; ($max=$size, $pmax=$psize, $kmax=$kind, $nmax=$name, $smax=$schema) if $size > $max; } if ($max < 0) { @@ -6745,7 +6745,7 @@ FROM $seqname) foo ndie msg('seq-die', $seqname); } my $msg = msg('seq-msg', $seqname, $percent, $left); - my $nicename = perfname("$multidb$seqname"); + my $nicename = perfname("$multidb$seqname"); $seqperf{$percent}{$seqname} = [$left, " $nicename=$percent%;$w%;$c%"]; if ($percent >= $maxp) { $maxp = $percent; @@ -7037,24 +7037,24 @@ sub check_txn_idle { ## Skip if we don't care about this database next if skip_item($r->{datname}); - ## Detect cases where pg_stat_activity is not fully populated - if (length $r->{xact_start} and $r->{xact_start} !~ /\d/o) { - ## Perhaps this is a non-superuser? - if ($r->{current_query} =~ /insufficient/) { - add_unknown msg('psa-nosuper'); - return; - } - - ## Perhaps stats_command_string / track_activities is off? - if ($r->{current_query} =~ /disabled/) { - add_unknown msg('psa-disabled'); - return; - } - - ## Something else is going on - add_unknown msg('psa-noexact'); - return; - } + ## Detect cases where pg_stat_activity is not fully populated + if (length $r->{xact_start} and $r->{xact_start} !~ /\d/o) { + ## Perhaps this is a non-superuser? + if ($r->{current_query} =~ /insufficient/) { + add_unknown msg('psa-nosuper'); + return; + } + + ## Perhaps stats_command_string / track_activities is off? + if ($r->{current_query} =~ /disabled/) { + add_unknown msg('psa-disabled'); + return; + } + + ## Something else is going on + add_unknown msg('psa-noexact'); + return; + } ## Keep track of the longest overall time $maxr = $r if $r->{seconds} >= $maxr->{seconds}; @@ -7066,7 +7066,7 @@ sub check_txn_idle { ## We don't care which at the moment, and return the same message if (! $count) { $MRTG and do_mrtg({one => 0, msg => $whodunit}); - $db->{perf} = "$perf=0;$wtime;$ctime"; + $db->{perf} = "$perf=0;$wtime;$ctime"; add_ok msg("$type-none"); return; @@ -7078,7 +7078,7 @@ sub check_txn_idle { ## See if we have a minimum number of matches my $base_count = $wcount || $ccount; if ($base_count and $count < $base_count) { - $db->{perf} = "$perf=$count;$wcount;$ccount"; + $db->{perf} = "$perf=$count;$wcount;$ccount"; add_ok msg("$type-count-none", $base_count); return; } @@ -7103,8 +7103,8 @@ sub check_txn_idle { my $ptime = $max > 300 ? ' (' . pretty_time($max) . ')' : ''; ## Show the maximum number of seconds in the perf section - $db->{perf} .= sprintf q{%s=%ss;%s;%s}, - $perf, + $db->{perf} .= sprintf q{%s=%ss;%s;%s}, + $perf, $max, $wtime, $ctime; diff --git a/t/00_release.t b/t/00_release.t index 8dd0eb943..4192ad773 100644 --- a/t/00_release.t +++ b/t/00_release.t @@ -15,7 +15,17 @@ if (!$ENV{RELEASE_TESTING}) { plan (skip_all => 'Test skipped unless environment variable RELEASE_TESTING is set'); } -plan tests => 2; +## Grab all files from the MANIFEST to generate a test count +my $file = 'MANIFEST'; +my @mfiles; +open my $mfh, '<', $file or die qq{Could not open "$file": $!\n}; +while (<$mfh>) { + next if /^#/; + push @mfiles => $1 if /(\S.+)/o; +} +close $mfh or warn qq{Could not close "$file": $!\n}; + +plan tests => 2 + @mfiles; my %v; my $vre = qr{(\d+\.\d+\.\d+)}; @@ -95,4 +105,49 @@ else { fail 'Cannot check git tag until we have a single version number!'; } +## Make sure all files in the MANIFEST are "clean": no tabs, no unusual characters + +for my $mfile (@mfiles) { + file_is_clean($mfile); +} + +exit; + +sub file_is_clean { + + my $file = shift or die; + + if (!open $fh, '<', $file) { + fail qq{Could not open "$file": $!\n}; + return; + } + $good = 1; + my $inside_copy = 0; + while (<$fh>) { + if (/^COPY .+ FROM stdin/i) { + $inside_copy = 1; + } + if (/^\\./ and $inside_copy) { + $inside_copy = 0; + } + if (/\t/ and $file ne 'Makefile.PL' and $file !~ /\.html$/ and ! $inside_copy) { + diag "Found a tab at line $. of $file\n"; + $good = 0; + } + if (! /^[\S ]*/) { + diag "Invalid character at line $. of $file: $_\n"; + $good = 0; die; + } + } + close $fh or warn qq{Could not close "$file": $!\n}; + + if ($good) { + pass "The $file file has no tabs or unusual characters"; + } + else { + fail "The $file file did not pass inspection!"; + } + +} + exit; diff --git a/t/02_fsm_pages.t b/t/02_fsm_pages.t index 542afbb50..b67331171 100644 --- a/t/02_fsm_pages.t +++ b/t/02_fsm_pages.t @@ -65,7 +65,7 @@ if ($ver >= 80400) { $t=qq{$S gives an unknown when running against a 8.4 or higher version}; like ($cp->run('--warning=10%'), qr{^$label UNKNOWN.*Cannot check fsm_pages}, $t); - exit; + exit; } diff --git a/t/02_listener.t b/t/02_listener.t index 5a8f74c8d..f6dc154c5 100644 --- a/t/02_listener.t +++ b/t/02_listener.t @@ -30,7 +30,7 @@ if ($ver >= 90000) { skip 'Cannot test listener on Postgres 9.0 or higher', 8; } - exit; + exit; } diff --git a/t/02_new_version_cp.t b/t/02_new_version_cp.t index 53dd86335..3a2c100b2 100644 --- a/t/02_new_version_cp.t +++ b/t/02_new_version_cp.t @@ -36,13 +36,13 @@ like ($cp->run(''), qr{$label OK: Version $current_version is the latest for ch $t=qq{$S returns critical for mismatched revision}; my $warncrit; if ($crev==0) { - $crev = 99; - $cmaj--; - $warncrit = 'WARNING'; + $crev = 99; + $cmaj--; + $warncrit = 'WARNING'; } else { - $crev--; - $warncrit = 'CRITICAL'; + $crev--; + $warncrit = 'CRITICAL'; } $cp->fake_self_version("$cmaj.$crev"); like ($cp->run(''), qr{$label $warncrit: Please upgrade to version \d+\.\d+\.\d+ of check_postgres. You are running \d+\.\d+\.\d+}, $t); diff --git a/t/02_replicate_row.t b/t/02_replicate_row.t index 5004d0726..0fec72f7c 100644 --- a/t/02_replicate_row.t +++ b/t/02_replicate_row.t @@ -22,10 +22,10 @@ my $label = 'POSTGRES_REPLICATE_ROW'; $SQL = q{CREATE TABLE reptest(id INT, foo TEXT)}; if (! $cp->table_exists($dbh, 'reptest')) { - $dbh->do($SQL); + $dbh->do($SQL); } if (! $cp->table_exists($dbh2, 'reptest')) { - $dbh2->do($SQL); + $dbh2->do($SQL); } $SQL = q{TRUNCATE TABLE reptest}; $dbh->do($SQL); @@ -109,62 +109,62 @@ $dbh->{InactiveDestroy} = 1; $dbh2->{InactiveDestroy} = 1; ## Use fork to 'replicate' behind the back of the other process if (fork) { - like ($cp->run('DB2replicate-row', '-c 5 -repinfo=reptest,id,1,foo,yin,yang'), - qr{^$label OK:.+Row was replicated}, $t); + like ($cp->run('DB2replicate-row', '-c 5 -repinfo=reptest,id,1,foo,yin,yang'), + qr{^$label OK:.+Row was replicated}, $t); } else { - sleep 1; - $SQL = q{UPDATE reptest SET foo = 'yin' WHERE id = 1}; - $dbh2->do($SQL); - $dbh2->commit(); - exit; + sleep 1; + $SQL = q{UPDATE reptest SET foo = 'yin' WHERE id = 1}; + $dbh2->do($SQL); + $dbh2->commit(); + exit; } $t=qq{$S works when rows match, reports proper delay}; $dbh->commit(); if (fork) { - $result = $cp->run('DB2replicate-row', '-c 10 -repinfo=reptest,id,1,foo,yin,yang'); - like ($result, qr{^$label OK:.+Row was replicated}, $t); - $result =~ /time=(\d+)/ or die 'No time?'; - my $time = $1; - cmp_ok ($time, '>=', 3, $t); + $result = $cp->run('DB2replicate-row', '-c 10 -repinfo=reptest,id,1,foo,yin,yang'); + like ($result, qr{^$label OK:.+Row was replicated}, $t); + $result =~ /time=(\d+)/ or die 'No time?'; + my $time = $1; + cmp_ok ($time, '>=', 3, $t); } else { - sleep 3; - $SQL = q{UPDATE reptest SET foo = 'yang' WHERE id = 1}; - $dbh2->do($SQL); - $dbh2->commit(); - exit; + sleep 3; + $SQL = q{UPDATE reptest SET foo = 'yang' WHERE id = 1}; + $dbh2->do($SQL); + $dbh2->commit(); + exit; } $t=qq{$S works when rows match, with MRTG output}; $dbh->commit(); if (fork) { - is ($cp->run('DB2replicate-row', '-c 20 --output=MRTG -repinfo=reptest,id,1,foo,yin,yang'), - qq{1\n0\n\n\n}, $t); + is ($cp->run('DB2replicate-row', '-c 20 --output=MRTG -repinfo=reptest,id,1,foo,yin,yang'), + qq{1\n0\n\n\n}, $t); } else { - sleep 1; - $SQL = q{UPDATE reptest SET foo = 'yin' WHERE id = 1}; - $dbh2->do($SQL); - $dbh2->commit(); - exit; + sleep 1; + $SQL = q{UPDATE reptest SET foo = 'yin' WHERE id = 1}; + $dbh2->do($SQL); + $dbh2->commit(); + exit; } $t=qq{$S works when rows match, with simple output}; $dbh->commit(); if (fork) { - $result = $cp->run('DB2replicate-row', '-c 20 --output=simple -repinfo=reptest,id,1,foo,yin,yang'); - $result =~ /^(\d+)/ or die 'No time?'; - my $time = $1; - cmp_ok ($time, '>=', 3, $t); + $result = $cp->run('DB2replicate-row', '-c 20 --output=simple -repinfo=reptest,id,1,foo,yin,yang'); + $result =~ /^(\d+)/ or die 'No time?'; + my $time = $1; + cmp_ok ($time, '>=', 3, $t); } else { - sleep 3; - $SQL = q{UPDATE reptest SET foo = 'yang' WHERE id = 1}; - $dbh2->do($SQL); - $dbh2->commit(); - exit; + sleep 3; + $SQL = q{UPDATE reptest SET foo = 'yang' WHERE id = 1}; + $dbh2->do($SQL); + $dbh2->commit(); + exit; } $dbh2->disconnect(); -- 2.30.2