From 06abfd6b2f03dbdfbb170bbf937dda29e881f3ce Mon Sep 17 00:00:00 2001 From: Nikola Knezevic Date: Wed, 13 Nov 2019 11:42:55 +0100 Subject: [PATCH 1/2] hydra-send-stats: Cleanup removed metrics In 29468995040ae21e0e1c14c1bdbb16ccb514caa8 these metrics got removed due to refactoring of how notifications work. --- src/script/hydra-send-stats | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/script/hydra-send-stats b/src/script/hydra-send-stats index 50872c1a..2b8c550b 100755 --- a/src/script/hydra-send-stats +++ b/src/script/hydra-send-stats @@ -56,12 +56,6 @@ sub sendQueueRunnerStats { 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.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) { From d5445bfc1d25067da7a5773b8f7f57f6d5541037 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sat, 28 Dec 2019 21:39:20 +0000 Subject: [PATCH 2/2] job: create a prometheus endpoint Export the most recent stop time and exit status in a prometheus-friendly format. --- src/lib/Hydra/Controller/Job.pm | 37 ++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/lib/Hydra/Controller/Job.pm b/src/lib/Hydra/Controller/Job.pm index 1147bc76..ba51616d 100644 --- a/src/lib/Hydra/Controller/Job.pm +++ b/src/lib/Hydra/Controller/Job.pm @@ -6,7 +6,7 @@ use warnings; use base 'Hydra::Base::Controller::ListBuilds'; use Hydra::Helper::Nix; use Hydra::Helper::CatalystUtils; - +use Net::Prometheus; sub job : Chained('/') PathPart('job') CaptureArgs(3) { my ($self, $c, $projectName, $jobsetName, $jobName) = @_; @@ -29,6 +29,41 @@ sub job : Chained('/') PathPart('job') CaptureArgs(3) { $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) { my ($self, $c) = @_;