Skip to content

Commit

Permalink
ui: Show health on mirror card (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-suse authored Dec 5, 2023
1 parent 337b5c2 commit ebaf61d
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 6 deletions.
23 changes: 23 additions & 0 deletions lib/MirrorCache/Schema/ResultSet/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,27 @@ sub check_sync {
return 3;
}

sub find_with_stability {
my ($self, $hostname) = @_;

my $rsource = $self->result_source;
my $schema = $rsource->schema;
my $dbh = $schema->storage->dbh;

my $sql;

$sql = <<'END_SQL';
select s.id, s.hostname, s.public_notes, shttp.rating as rating_http, shttps.rating as rating_https, sipv4.rating as rating_ipv4, sipv6.rating as rating_ipv6
from server s
left join server_stability shttp on s.id = shttp.server_id and shttp.capability = 'http'
left join server_stability shttps on s.id = shttps.server_id and shttps.capability = 'https'
left join server_stability sipv4 on s.id = sipv4.server_id and sipv4.capability = 'ipv4'
left join server_stability sipv6 on s.id = sipv6.server_id and sipv6.capability = 'ipv6'
where s.hostname = ?
END_SQL
my $prep = $dbh->prepare($sql);
$prep->execute($hostname);
return $dbh->selectrow_hashref($prep);
}

1;
16 changes: 10 additions & 6 deletions lib/MirrorCache/WebAPI/Controller/App/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ sub show {
my $self = shift;
my $hostname = $self->param('hostname');

my $f = $self->schema->resultset('Server')->find({hostname => $hostname})
my $f = $self->schema->resultset('Server')->find_with_stability($hostname)
or return $self->reply->not_found;

my $admin_email = '';
Expand All @@ -61,8 +61,8 @@ sub show {
}
my $subsidiary;
if (my $regions = $self->mcconfig->regions) {
if ($f->region && -1 == CORE::index($regions, $f->region)) {
$subsidiary = $self->subsidiary->url($f->region);
if ($f->{region} && -1 == CORE::index($regions, $f->{region})) {
$subsidiary = $self->subsidiary->url($f->{region});
}
}
my $provider;
Expand All @@ -73,12 +73,16 @@ sub show {
}

my $server = {
id => $f->id,
hostname => $f->hostname,
public_notes => $f->public_notes,
id => $f->{id},
hostname => $f->{hostname},
public_notes => $f->{public_notes},
admin_email => $admin_email,
subsidiary => $subsidiary,
provider => $provider,
rating_http => $f->{rating_http},
rating_https => $f->{rating_https},
rating_ipv4 => $f->{rating_ipv4},
rating_ipv6 => $f->{rating_ipv6},
};

return $self->render('app/server/show', server => $server);
Expand Down
6 changes: 6 additions & 0 deletions t/environ/09-stability-01-probe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,10 @@ $mc/backstage/shoot
$mc/sql_test 1000 == "select rating from server_stability where (server_id, capability) = (1, 'http')"
$mc/sql_test -1 == "select rating from server_stability where (server_id, capability) = (2, 'http')"

$mc/curl /app/server/$($ap8/print_address) | grep -A4 Health \
| grep -A3 -F '<span class="ratingdisabled">http</span>' \
| grep -A2 -F '<span class="ratingbad">https</span>' \
| grep -A1 -F '<span class="ratinggood">ipv4</span>' \
| grep -F '<span class="ratingbad">ipv6</span>'

echo success
46 changes: 46 additions & 0 deletions templates/app/server/show.html.ep
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
% layout 'bootstrap';
% title "Server " . $server->{hostname};

% content_for 'head' => begin

<style type='text/css'>
span.ratinggood {
color: green
}

span.ratingquestinable {
color: olive
}

span.ratingpoor {
color: red
}

span.ratingbad {
color: red
}

span.ratingdisabled {
color: thistle;
text-decoration: line-through;
}

span.ratingunknown {
color: grey
}

</style>
% end

% content_for 'ready_function' => begin
is_operator = <%= (is_operator) ? 'true' : 'false' %>;
server_id = <%= $server->{id} %>;
Expand Down Expand Up @@ -34,6 +65,21 @@
% if ($server->{admin_email}) {
<div><span>Email: </span><%= $server->{admin_email} %></div>
% }

% $server->{rating_http};
<div>
<span>Health:</span>
% for my $capability (qw/http https ipv4 ipv6/) {
% my $style = 'ratinggood';
% my $rating = int($server->{ 'rating_' . $capability } // -2);
% $style = 'ratingquestionable' if $rating < 1000;
% $style = 'ratingpoor' if $rating < 10;
% $style = 'ratingbad' if $rating < 1;
% $style = 'ratingdisabled' if $rating < 0;
% $style = 'ratingunknown' if $rating < -1;
<span class="<%=$style%>"><%= $capability %></span>
% }
</div>
</div>
</div>

Expand Down

0 comments on commit ebaf61d

Please sign in to comment.