Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bug 804347 - Adding iprovements to allow for healthy checks on bouncer.

  • Loading branch information...
commit 6327546ff8bbc1d276c6f8614fbe4e6eeb21d2e8 1 parent a053195
@brandonsavage brandonsavage authored
View
1  apps/mirror/models.py
@@ -149,6 +149,7 @@ class LocationMirrorMap(models.Model):
location = models.ForeignKey('Location')
mirror = models.ForeignKey('Mirror')
active = models.BooleanField()
+ healthy = models.BooleanField()
def __unicode__(self):
try:
View
49 bouncer/php/index.php
@@ -273,9 +273,35 @@ function setHttpType($ssl_only) {
geoip_mirror_region_map.region_id = %d AND
mirror_mirrors.active='1' AND
mirror_location_mirror_map.active ='1' AND
+ mirror_location_mirror_map.healthy = '1' AND
mirror_mirrors.baseurl LIKE '$http_type%%'
ORDER BY rating",
array($where_lang, $location['id'], $client_region), MYSQL_ASSOC, 'id');
+
+ if (!$mirrors) {
+ $mirrors = $sdo->get("
+ SELECT
+ mirror_mirrors.id,
+ baseurl,
+ rating
+ FROM
+ mirror_mirrors
+ JOIN
+ mirror_location_mirror_map ON mirror_mirrors.id = mirror_location_mirror_map.mirror_id
+ LEFT JOIN
+ mirror_lmm_lang_exceptions AS lang_exc ON (mirror_location_mirror_map.id = lang_exc.location_mirror_map_id AND NOT lang_exc.language = '%s')
+ INNER JOIN
+ geoip_mirror_region_map ON (geoip_mirror_region_map.mirror_id = mirror_mirrors.id)
+ WHERE
+ mirror_location_mirror_map.location_id = %d AND
+ geoip_mirror_region_map.region_id = %d AND
+ mirror_mirrors.active='1' AND
+ mirror_location_mirror_map.active ='1' AND
+ mirror_location_mirror_map.healthy = '0' AND
+ mirror_mirrors.baseurl LIKE '$http_type%%'
+ ORDER BY rating",
+ array($where_lang, $location['id'], $client_region), MYSQL_ASSOC, 'id');
+ }
}
}
@@ -299,9 +325,32 @@ function setHttpType($ssl_only) {
mirror_location_mirror_map.location_id = %d AND
mirror_mirrors.active='1' AND
mirror_location_mirror_map.active ='1' AND
+ mirror_location_mirror_map.healthy = '1' AND
mirror_mirrors.baseurl LIKE '$http_type%%'
ORDER BY rating",
array($where_lang, $location['id']), MYSQL_ASSOC, 'id');
+
+ if(!$mirrors) {
+ $mirrors = $sdo->get("
+ SELECT
+ mirror_mirrors.id,
+ baseurl,
+ rating
+ FROM
+ mirror_mirrors,
+ mirror_location_mirror_map
+ LEFT JOIN
+ mirror_lmm_lang_exceptions AS lang_exc ON (mirror_location_mirror_map.id = lang_exc.location_mirror_map_id AND NOT lang_exc.language = '%s')
+ WHERE
+ mirror_mirrors.id = mirror_location_mirror_map.mirror_id AND
+ mirror_location_mirror_map.location_id = %d AND
+ mirror_mirrors.active='1' AND
+ mirror_location_mirror_map.active ='1' AND
+ mirror_location_mirror_map.healthy = '0' AND
+ mirror_mirrors.baseurl LIKE '$http_type%%'
+ ORDER BY rating",
+ array($where_lang, $location['id']), MYSQL_ASSOC, 'id');
+ }
}
$mirrors_rand = array();
View
23 sentry/sentry.pl
@@ -72,8 +72,8 @@ sub log_this {
$location_sql = qq{SELECT mirror_locations.* FROM mirror_locations INNER JOIN mirror_products ON mirror_locations.product_id = mirror_products.id WHERE mirror_products.active='1'};
$mirror_sql = qq{SELECT * FROM mirror_mirrors WHERE active='1' ORDER BY name};
}
-$update_sql = qq{INSERT INTO mirror_location_mirror_map (location_id, mirror_id, active) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE active=VALUES(active)};
-$failed_mirror_sql = qq{UPDATE mirror_location_mirror_map SET active='0' WHERE mirror_id=?};
+$update_sql = qq{INSERT INTO mirror_location_mirror_map (location_id, mirror_id, active, healthy) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE active=VALUES(active), healthy=VALUES(healthy)};
+$failed_mirror_sql = qq{UPDATE mirror_location_mirror_map SET healthy='0' WHERE mirror_id=?};
$log_sql = qq{INSERT INTO sentry_log (log_date, mirror_id, mirror_active, mirror_rating, reason) VALUES (FROM_UNIXTIME(?), ?, ?, ?, ?)};
$getlog_sql = qq{SELECT mirror_rating, mirror_active FROM sentry_log WHERE mirror_id = ? ORDER BY log_date DESC LIMIT 4};
$updatelog_sql = qq{UPDATE sentry_log SET reason=? WHERE log_date=FROM_UNIXTIME(?) AND mirror_id=?};
@@ -133,6 +133,8 @@ sub log_this {
#
# we also only want to check the domain if the host is NOT a straight IP address
# since for some reason Net::DNS::query still tries to resolve IP addresses (dumb).
+ #
+ # Unhealthy, not fatal.
if ($domain !~ m($ipregex) && !$netres->query($domain)) {
log_this "DNS resolution for $mirror->{mirror_name} FAILED! Moving on to next mirror.\n";
$failed_mirror_sth->execute($mirror->{id});
@@ -162,6 +164,8 @@ sub log_this {
my $mirrorRes = $ua->request($mirrorReq);
# if the mirror is bad, we should skip to the next mirror and avoid iterating over locations
+ #
+ # Unhealthy, not fatal.
if ( $mirrorRes->{_rc}>=500 ) {
if ( $mirrorRes->{_rc} == 500 ) {
log_this "$mirror->{baseurl} sent no response after " . $ua->timeout() . " seconds! Checking recent history...\n";
@@ -258,22 +262,17 @@ sub log_this {
if (( $res->{_rc} == 200 ) && ( $res->{_headers}->{'content-type'} !~ /text\/html/ )) {
log_this "okay.\n";
- $update_sth->execute($location->{id}, $mirror->{id}, '1');
+ $update_sth->execute($location->{id}, $mirror->{id}, '1', '1');
+ }
+ elsif (( $res->{_rc} == 404 ) || ( $res->{_rc} == 403 )) {
+ $deactivate_sth->execute($location->{id}, $mirror->{id}, '0', '0');
}
else {
log_this "FAILED. rc=" . $res->{_rc} . "\n";
- $update_sth->execute($location->{id}, $mirror->{id}, '0');
+ $update_sth->execute($location->{id}, $mirror->{id}, '1', '0');
}
# content-type == text/plain hack here for Mac dmg's
- if ($res->{_rc} == 200) {
- foreach my $exten (keys %content_type) {
- if ( $location->{path} =~ m/.*\.$exten$/ && $res->{_headers}->{'content-type'} !~ /\Q$content_type{$exten}\E/ ) {
- log_this " -> FAILED due to content-type mis-match, expected '$content_type{$exten}', got '$res->{_headers}->{'content-type'}'\n";
- $update_sth->execute($location->{id}, $mirror->{id}, '0');
- }
- }
- }
}
$log_sth->execute($start_timestamp, $mirror->{id}, '1', $mirror->{rating}, $output);
}
View
2  sql/incremental.sql
@@ -119,3 +119,5 @@ ALTER TABLE geoip_regions ADD COLUMN prevent_global_fallback int(1) NULL;
-- Add SSL only support (bug 796088)
ALTER TABLE mirror_products ADD COLUMN `ssl_only` tinyint(1) NOT NULL DEFAULT 0;
+-- Add healthy column for additional bouncer support (bug 804347)
+ALTER TABLE mirror_location_mirror_map ADD COLUMN healthy tinyint(4) NOT NULL DEFAULT 1;

0 comments on commit 6327546

Please sign in to comment.
Something went wrong with that request. Please try again.