Merge remote-tracking branch 'origin/master' into flake

This commit is contained in:
Graham Christensen 2019-12-28 20:22:54 -05:00
commit 511c2db8aa
No known key found for this signature in database
GPG key ID: FE918C3A98C1030F
2 changed files with 36 additions and 7 deletions

View file

@ -6,7 +6,7 @@ use warnings;
use base 'Hydra::Base::Controller::ListBuilds'; use base 'Hydra::Base::Controller::ListBuilds';
use Hydra::Helper::Nix; use Hydra::Helper::Nix;
use Hydra::Helper::CatalystUtils; use Hydra::Helper::CatalystUtils;
use Net::Prometheus;
sub job : Chained('/') PathPart('job') CaptureArgs(3) { sub job : Chained('/') PathPart('job') CaptureArgs(3) {
my ($self, $c, $projectName, $jobsetName, $jobName) = @_; my ($self, $c, $projectName, $jobsetName, $jobName) = @_;
@ -29,6 +29,41 @@ sub job : Chained('/') PathPart('job') CaptureArgs(3) {
$c->stash->{project} = $c->stash->{job}->project; $c->stash->{project} = $c->stash->{job}->project;
} }
sub prometheus : Chained('job') PathPart('prometheus') Args(0) {
my ($self, $c) = @_;
my $job = $c->stash->{job};
my $prometheus = Net::Prometheus->new;
my $lastBuild = $job->builds->find(
{ finished => 1 },
{ order_by => 'id DESC', rows => 1, columns => [@buildListColumns] }
);
$prometheus->new_counter(
name => "hydra_job_completion_time",
help => "The most recent job's completion time",
labels => [ "project", "jobset", "job", "nixname" ]
)->labels(
$c->stash->{project}->name,
$c->stash->{jobset}->name,
$c->stash->{job}->name,
$lastBuild->nixname,
)->inc($lastBuild->stoptime);
$prometheus->new_gauge(
name => "hydra_job_failed",
help => "Record if the most recent version of this job failed (1 means failed)",
labels => [ "project", "jobset", "job", "nixname" ]
)->labels(
$c->stash->{project}->name,
$c->stash->{jobset}->name,
$c->stash->{job}->name,
$lastBuild->nixname,
)->inc($lastBuild->stoptime >= 0);
$c->stash->{'plain'} = { data => $prometheus->render };
$c->forward('Hydra::View::Plain');
}
sub overview : Chained('job') PathPart('') Args(0) { sub overview : Chained('job') PathPart('') Args(0) {
my ($self, $c) = @_; my ($self, $c) = @_;

View file

@ -56,12 +56,6 @@ sub sendQueueRunnerStats {
gauge("hydra.queue.machines.total", scalar(grep { $_->{enabled} } (values %{$json->{machines}}))); gauge("hydra.queue.machines.total", scalar(grep { $_->{enabled} } (values %{$json->{machines}})));
gauge("hydra.queue.machines.in_use", scalar(grep { $_->{currentJobs} > 0 } (values %{$json->{machines}}))); gauge("hydra.queue.machines.in_use", scalar(grep { $_->{currentJobs} > 0 } (values %{$json->{machines}})));
gauge("hydra.queue.notification.time_avg_ms", $json->{nrNotificationTimeAvgMs});
gauge("hydra.queue.notification.time_ms", $json->{nrNotificationTimeMs});
gauge("hydra.queue.notification.done", $json->{nrNotificationsDone});
gauge("hydra.queue.notification.failed", $json->{nrNotificationsFailed});
gauge("hydra.queue.notification.in_progress", $json->{nrNotificationsInProgress});
gauge("hydra.queue.notification.pending", $json->{nrNotificationsPending});
} }
while (1) { while (1) {