From d3fe4ffbf645b8fbc1110a30614a6871a23f0f23 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Fri, 9 Sep 2022 00:38:46 +0200 Subject: [PATCH] Job: expose `closuresize` and `size` (output size in the UI) as prometheus metrics --- src/lib/Hydra/Controller/Job.pm | 22 +++++++++++++++++++++- t/Hydra/Controller/Job/builds.t | 6 ++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/lib/Hydra/Controller/Job.pm b/src/lib/Hydra/Controller/Job.pm index 378887ea..b392e8e1 100644 --- a/src/lib/Hydra/Controller/Job.pm +++ b/src/lib/Hydra/Controller/Job.pm @@ -69,7 +69,7 @@ sub prometheus : Chained('job') PathPart('prometheus') Args(0) { my $lastBuild = $c->stash->{jobset}->builds->find( { job => $c->stash->{job}, finished => 1 }, - { order_by => 'id DESC', rows => 1, columns => [@buildListColumns] } + { order_by => 'id DESC', rows => 1, columns => ["stoptime", "buildstatus", "closuresize", "size"] } ); $prometheus->new_counter( @@ -92,6 +92,26 @@ sub prometheus : Chained('job') PathPart('prometheus') Args(0) { $c->stash->{job}, )->inc($lastBuild->buildstatus > 0); + $prometheus->new_gauge( + name => "hydra_build_closure_size", + help => "Closure size of the last job's build in bytes", + labels => [ "project", "jobset", "job" ] + )->labels( + $c->stash->{project}->name, + $c->stash->{jobset}->name, + $c->stash->{job}, + )->inc($lastBuild->closuresize); + + $prometheus->new_gauge( + name => "hydra_build_output_size", + help => "Output size of the last job's build in bytes", + labels => [ "project", "jobset", "job" ] + )->labels( + $c->stash->{project}->name, + $c->stash->{jobset}->name, + $c->stash->{job}, + )->inc($lastBuild->size); + $c->stash->{'plain'} = { data => $prometheus->render }; $c->forward('Hydra::View::Plain'); } diff --git a/t/Hydra/Controller/Job/builds.t b/t/Hydra/Controller/Job/builds.t index e1097c3e..d933fbb8 100644 --- a/t/Hydra/Controller/Job/builds.t +++ b/t/Hydra/Controller/Job/builds.t @@ -55,6 +55,12 @@ subtest "/job/PROJECT/JOBSET/JOB/shield" => sub { subtest "/job/PROJECT/JOBSET/JOB/prometheus" => sub { my $response = request(GET '/job/' . $project->name . '/' . $jobset->name . '/' . $build->job . '/prometheus'); ok($response->is_success, "The page showing the job's prometheus data returns 200."); + my $metrics = $response->content; + + ok($metrics =~ m/hydra_job_failed\{.*\} 0/); + ok($metrics =~ m/hydra_job_completion_time\{.*\} [\d]+/); + ok($metrics =~ m/hydra_build_closure_size\{.*\} 96/); + ok($metrics =~ m/hydra_build_output_size\{.*\} 96/); }; done_testing;