Show queue runner v2 status

This is guarded behind a setting and will overwrite everything that was
learned from the machines file. Also drops `sshKeys` since that wasn't
used anyway.
This commit is contained in:
Janne Heß
2025-07-16 17:05:45 +02:00
committed by ahuston-0
parent 16bb3aad9a
commit dc6fd37e02
3 changed files with 55 additions and 32 deletions

View File

@@ -189,8 +189,10 @@ sub machines :Local Args(0) {
my ($self, $c) = @_; my ($self, $c) = @_;
my $machines = getMachines; my $machines = getMachines;
# Add entry for localhost. # Add entry for localhost. The implicit addition is not needed with queue runner v2
if (not $c->config->{'queue_runner_endpoint'}) {
$machines->{''} //= {}; $machines->{''} //= {};
}
delete $machines->{'localhost'}; delete $machines->{'localhost'};
my $status = $c->model('DB::SystemStatus')->find("queue-runner"); my $status = $c->model('DB::SystemStatus')->find("queue-runner");

View File

@@ -12,6 +12,8 @@ use Nix::Store;
use Encode; use Encode;
use Sys::Hostname::Long; use Sys::Hostname::Long;
use IPC::Run; use IPC::Run;
use LWP::UserAgent;
use JSON::MaybeXS;
use UUID4::Tiny qw(is_uuid4_string); use UUID4::Tiny qw(is_uuid4_string);
our @ISA = qw(Exporter); our @ISA = qw(Exporter);
@@ -340,7 +342,30 @@ sub getEvals {
sub getMachines { sub getMachines {
my %machines = (); my %machines = ();
my $config = getHydraConfig();
if ($config->{'queue_runner_endpoint'}) {
my $ua = LWP::UserAgent->new();
my $resp = $ua->get($config->{'queue_runner_endpoint'} . "/status/machines");
if (not $resp->is_success) {
print STDERR "Unable to ask queue runner for machines\n";
return \%machines;
}
my $data = decode_json($resp->decoded_content) or return \%machines;
my $machinesData = $data->{machines};
foreach my $machineName (keys %$machinesData) {
my $machine = %$machinesData{$machineName};
$machines{$machineName} =
{ systemTypes => $machine->{systems}
, maxJobs => $machine->{maxJobs}
, speedFactor => $machine->{speedFactor}
, supportedFeatures => [ @{$machine->{supportedFeatures}}, @{$machine->{mandatoryFeatures}} ]
, mandatoryFeatures => [ @{$machine->{mandatoryFeatures}} ]
};
}
} else {
my @machinesFiles = split /:/, ($ENV{"NIX_REMOTE_SYSTEMS"} || "/etc/nix/machines"); my @machinesFiles = split /:/, ($ENV{"NIX_REMOTE_SYSTEMS"} || "/etc/nix/machines");
for my $machinesFile (@machinesFiles) { for my $machinesFile (@machinesFiles) {
@@ -363,7 +388,6 @@ sub getMachines {
my @mandatoryFeatures = split(/,/, $tokens[6] || ""); my @mandatoryFeatures = split(/,/, $tokens[6] || "");
$machines{$tokens[0]} = $machines{$tokens[0]} =
{ systemTypes => [ split(/,/, $tokens[1]) ] { systemTypes => [ split(/,/, $tokens[1]) ]
, sshKeys => $tokens[2]
, maxJobs => int($tokens[3]) , maxJobs => int($tokens[3])
, speedFactor => 1.0 * (defined $tokens[4] ? int($tokens[4]) : 1) , speedFactor => 1.0 * (defined $tokens[4] ? int($tokens[4]) : 1)
, supportedFeatures => [ @supportedFeatures, @mandatoryFeatures ] , supportedFeatures => [ @supportedFeatures, @mandatoryFeatures ]
@@ -372,6 +396,7 @@ sub getMachines {
} }
close $conf; close $conf;
} }
}
return \%machines; return \%machines;
} }

View File

@@ -33,7 +33,6 @@ close $fh;
is(Hydra::Helper::Nix::getMachines(), { is(Hydra::Helper::Nix::getMachines(), {
'root@ip' => { 'root@ip' => {
'systemTypes' => ["x86_64-darwin"], 'systemTypes' => ["x86_64-darwin"],
'sshKeys' => '/sshkey',
'maxJobs' => 15, 'maxJobs' => 15,
'speedFactor' => 15, 'speedFactor' => 15,
'supportedFeatures' => ["big-parallel", "kvm", "nixos-test" ], 'supportedFeatures' => ["big-parallel", "kvm", "nixos-test" ],
@@ -41,7 +40,6 @@ is(Hydra::Helper::Nix::getMachines(), {
}, },
'root@baz' => { 'root@baz' => {
'systemTypes' => [ "aarch64-darwin" ], 'systemTypes' => [ "aarch64-darwin" ],
'sshKeys' => '/sshkey',
'maxJobs' => 4, 'maxJobs' => 4,
'speedFactor' => 1, 'speedFactor' => 1,
'supportedFeatures' => ["big-parallel"], 'supportedFeatures' => ["big-parallel"],
@@ -49,7 +47,6 @@ is(Hydra::Helper::Nix::getMachines(), {
}, },
'root@bux' => { 'root@bux' => {
'systemTypes' => [ "i686-linux", "x86_64-linux" ], 'systemTypes' => [ "i686-linux", "x86_64-linux" ],
'sshKeys' => '/var/sshkey',
'maxJobs' => 1, 'maxJobs' => 1,
'speedFactor' => 1, 'speedFactor' => 1,
'supportedFeatures' => [ "kvm", "nixos-test", "benchmark" ], 'supportedFeatures' => [ "kvm", "nixos-test", "benchmark" ],
@@ -57,7 +54,6 @@ is(Hydra::Helper::Nix::getMachines(), {
}, },
'root@lotsofspace' => { 'root@lotsofspace' => {
'systemTypes' => [ "i686-linux", "x86_64-linux" ], 'systemTypes' => [ "i686-linux", "x86_64-linux" ],
'sshKeys' => '/var/sshkey',
'maxJobs' => 1, 'maxJobs' => 1,
'speedFactor' => 1, 'speedFactor' => 1,
'supportedFeatures' => [ "kvm", "nixos-test", "benchmark" ], 'supportedFeatures' => [ "kvm", "nixos-test", "benchmark" ],