mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-03 11:05:48 +00:00
Don't try https and http: use https if possible, else http. Lower timeout from 5 to 3 seconds. Start updating/fixing pt-archiver/version_check.t.
This commit is contained in:
@@ -2836,9 +2836,11 @@ sub version_check_time_limit {
|
||||
|
||||
sub version_check {
|
||||
my (%args) = @_;
|
||||
eval {
|
||||
my $instances = $args{instances} || [];
|
||||
|
||||
my $instances = $args{instances} || [];
|
||||
my $instances_to_check;
|
||||
|
||||
eval {
|
||||
if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
|
||||
PTDEBUG && _d('--version-check disabled by PERCONA_VERSION_CHECK=0');
|
||||
return;
|
||||
@@ -2852,7 +2854,7 @@ sub version_check {
|
||||
|
||||
push @$instances, { name => 'system', id => 0 };
|
||||
|
||||
my $instances_to_check = get_instances_to_check(
|
||||
$instances_to_check = get_instances_to_check(
|
||||
instances => $instances,
|
||||
vc_file => $args{vc_file}, # testing
|
||||
now => $args{now}, # testing
|
||||
@@ -2860,22 +2862,21 @@ sub version_check {
|
||||
PTDEBUG && _d(scalar @$instances_to_check, 'instances to check');
|
||||
return unless @$instances_to_check;
|
||||
|
||||
my $advice;
|
||||
PROTOCOL:
|
||||
foreach my $protocol ( qw(https http) ) {
|
||||
$advice = eval {
|
||||
pingback(
|
||||
instances => $instances_to_check,
|
||||
protocol => $protocol,
|
||||
url => $args{url} # testing
|
||||
|| $ENV{PERCONA_VERSION_CHECK_URL} # testing
|
||||
|| "$protocol://v.percona.com",
|
||||
);
|
||||
};
|
||||
last PROTOCOL unless $EVAL_ERROR;
|
||||
PTDEBUG && _d('--version-check error:', $EVAL_ERROR);
|
||||
my $protocol = 'https'; # optimistic, but...
|
||||
eval { require IO::Socket::SSL; };
|
||||
if ( $EVAL_ERROR ) {
|
||||
PTDEBUG && _d($EVAL_ERROR);
|
||||
$protocol = 'http';
|
||||
}
|
||||
PTDEBUG && _d('Using', $protocol);
|
||||
|
||||
my $advice = pingback(
|
||||
instances => $instances_to_check,
|
||||
protocol => $protocol,
|
||||
url => $args{url} # testing
|
||||
|| $ENV{PERCONA_VERSION_CHECK_URL} # testing
|
||||
|| "$protocol://v.percona.com",
|
||||
);
|
||||
if ( $advice ) {
|
||||
PTDEBUG && _d('Advice:', Dumper($advice));
|
||||
if ( scalar @$advice > 1) {
|
||||
@@ -2887,7 +2888,12 @@ sub version_check {
|
||||
}
|
||||
print join("\n", map { "# * $_" } @$advice), "\n\n";
|
||||
}
|
||||
};
|
||||
if ( $EVAL_ERROR ) {
|
||||
PTDEBUG && _d('Version check failed:', $EVAL_ERROR);
|
||||
}
|
||||
|
||||
eval {
|
||||
update_check_times(
|
||||
instances => $instances_to_check,
|
||||
vc_file => $args{vc_file}, # testing
|
||||
@@ -2895,7 +2901,7 @@ sub version_check {
|
||||
);
|
||||
};
|
||||
if ( $EVAL_ERROR ) {
|
||||
PTDEBUG && _d('--version-check failed:', $EVAL_ERROR);
|
||||
PTDEBUG && _d('Error updating version check file:', $EVAL_ERROR);
|
||||
}
|
||||
|
||||
if ( $ENV{PTDEBUG_VERSION_CHECK} ) {
|
||||
@@ -2915,13 +2921,14 @@ sub get_instances_to_check {
|
||||
my $vc_file = $args{vc_file} || version_check_file();
|
||||
|
||||
if ( !-f $vc_file ) {
|
||||
PTDEBUG && _d($vc_file, 'does not exist; version checking all instances');
|
||||
PTDEBUG && _d('Version check file', $vc_file, 'does not exist;',
|
||||
'version checking all instances');
|
||||
return $instances;
|
||||
}
|
||||
|
||||
open my $fh, '<', $vc_file or die "Cannot open $vc_file: $OS_ERROR";
|
||||
chomp(my $file_contents = do { local $/ = undef; <$fh> });
|
||||
PTDEBUG && _d($vc_file, 'contents:', $file_contents);
|
||||
PTDEBUG && _d('Version check file', $vc_file, 'contents:', $file_contents);
|
||||
close $fh;
|
||||
my %last_check_time_for = $file_contents =~ /^([^,]+),(.+)$/mg;
|
||||
|
||||
@@ -2953,7 +2960,7 @@ sub update_check_times {
|
||||
PTDEBUG && _d('Updating last check time:', $now);
|
||||
|
||||
open my $fh, '>', $vc_file or die "Cannot write to $vc_file: $OS_ERROR";
|
||||
foreach my $instance ( sort { $a->{id} <=> $b->{id} } @$instances ) {
|
||||
foreach my $instance ( sort { $a->{id} cmp $b->{id} } @$instances ) {
|
||||
PTDEBUG && _d('Updated:', Dumper($instance));
|
||||
print { $fh } $instance->{id} . ',' . $now . "\n";
|
||||
}
|
||||
@@ -2990,7 +2997,7 @@ sub get_instance_id {
|
||||
}
|
||||
my $id = md5_hex($name);
|
||||
|
||||
PTDEBUG && _d('MySQL instance', $name, 'is', $id);
|
||||
PTDEBUG && _d('MySQL instance:', $id, $name, $dsn);
|
||||
|
||||
return $name, $id;
|
||||
}
|
||||
@@ -3005,7 +3012,7 @@ sub pingback {
|
||||
my $url = $args{url};
|
||||
my $instances = $args{instances};
|
||||
|
||||
my $ua = $args{ua} || HTTPMicro->new( timeout => 5 );
|
||||
my $ua = $args{ua} || HTTPMicro->new( timeout => 3 );
|
||||
|
||||
my $response = $ua->request('GET', $url);
|
||||
PTDEBUG && _d('Server response:', Dumper($response));
|
||||
@@ -3296,7 +3303,6 @@ sub get_from_mysql {
|
||||
'on', $instance->{name});
|
||||
push @versions, $version;
|
||||
}
|
||||
|
||||
$version_for{ $instance->{id} } = join(' ', @versions);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user