Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/hydra
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c7d1d3454705
Choose a base ref
...
head repository: NixOS/hydra
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1784c362ed00
Choose a head ref
  • 10 commits
  • 7 files changed
  • 4 contributors

Commits on Sep 24, 2019

  1. export a /prometheus endpoint

    Currently only shows per-machine build times
    grahamc committed Sep 24, 2019

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    grahamc Graham Christensen
    Copy the full SHA
    937e165 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    grahamc Graham Christensen
    Copy the full SHA
    3a04f28 View commit details

Commits on Sep 25, 2019

  1. Merge pull request #680 from grahamc/prometheus

    export a /prometheus endpoint
    edolstra authored Sep 25, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    037f648 View commit details

Commits on Nov 5, 2019

  1. Copy the full SHA
    840e99f View commit details
  2. Merge pull request #686 from basvandijk/remove-unused-firstOutput

    hydra-eval-jobset: $firstOutput is not used so can be removed
    edolstra authored Nov 5, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    45f8a0e View commit details
  3. Add bump-to-front role

    andir committed Nov 5, 2019

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    andir Andreas Rammhold
    Copy the full SHA
    ce1e10c View commit details
  4. Add cancel-build role

    andir committed Nov 5, 2019

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    andir Andreas Rammhold
    Copy the full SHA
    841a47c View commit details

Commits on Nov 7, 2019

  1. Merge pull request #687 from andir/more-roles

    Add `cancel-build` & `bump-to-front` roles
    grahamc authored Nov 7, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e89ea73 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    edolstra Eelco Dolstra
    Copy the full SHA
    55b0afa View commit details
  3. Simplify flake.nix

    edolstra committed Nov 7, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    edolstra Eelco Dolstra
    Copy the full SHA
    1784c36 View commit details
6 changes: 4 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -77,6 +77,7 @@
LWP
LWPProtocolHttps
NetAmazonS3
NetPrometheus
NetStatsd
PadWalker
Readonly
@@ -324,8 +325,9 @@
nixosConfigurations.container = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules =
[ { imports = [ self.nixosModules.hydraTest self.nixosModules.hydraProxy ];
system.configurationRevision = self.rev;
[ self.nixosModules.hydraTest
self.nixosModules.hydraProxy
{ system.configurationRevision = self.rev;

boot.isContainer = true;
networking.useDHCP = false;
4 changes: 2 additions & 2 deletions src/lib/Hydra/Controller/Build.pm
Original file line number Diff line number Diff line change
@@ -504,7 +504,7 @@ sub restart : Chained('buildChain') PathPart Args(0) {
sub cancel : Chained('buildChain') PathPart Args(0) {
my ($self, $c) = @_;
my $build = $c->stash->{build};
requireProjectOwner($c, $build->project);
requireCancelBuildPrivileges($c, $build->project);
my $n = cancelBuilds($c->model('DB')->schema, $c->model('DB::Builds')->search({ id => $build->id }));
error($c, "This build cannot be cancelled.") if $n != 1;
$c->flash->{successMsg} = "Build has been cancelled.";
@@ -540,7 +540,7 @@ sub bump : Chained('buildChain') PathPart('bump') {

my $build = $c->stash->{build};

requireProjectOwner($c, $build->project); # FIXME: require admin?
requireBumpPrivileges($c, $build->project);

$c->model('DB')->schema->txn_do(sub {
$build->update({globalpriority => time()});
4 changes: 2 additions & 2 deletions src/lib/Hydra/Controller/JobsetEval.pm
Original file line number Diff line number Diff line change
@@ -179,7 +179,7 @@ sub create_jobset : Chained('evalChain') PathPart('create-jobset') Args(0) {

sub cancel : Chained('evalChain') PathPart('cancel') Args(0) {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{eval}->project);
requireCancelBuildPrivileges($c, $c->stash->{eval}->project);
my $n = cancelBuilds($c->model('DB')->schema, $c->stash->{eval}->builds);
$c->flash->{successMsg} = "$n builds have been cancelled.";
$c->res->redirect($c->uri_for($c->controller('JobsetEval')->action_for('view'), $c->req->captures));
@@ -210,7 +210,7 @@ sub restart_failed : Chained('evalChain') PathPart('restart-failed') Args(0) {

sub bump : Chained('evalChain') PathPart('bump') Args(0) {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{eval}->project); # FIXME: require admin?
requireBumpPrivileges($c, $c->stash->{eval}->project); # FIXME: require admin?
my $builds = $c->stash->{eval}->builds->search({ finished => 0 });
my $n = $builds->count();
$c->model('DB')->schema->txn_do(sub {
45 changes: 45 additions & 0 deletions src/lib/Hydra/Controller/Root.pm
Original file line number Diff line number Diff line change
@@ -6,13 +6,15 @@ use warnings;
use base 'Hydra::Base::Controller::ListBuilds';
use Hydra::Helper::Nix;
use Hydra::Helper::CatalystUtils;
use Hydra::View::TT;
use Digest::SHA1 qw(sha1_hex);
use Nix::Store;
use Nix::Config;
use Encode;
use File::Basename;
use JSON;
use List::MoreUtils qw{any};
use Net::Prometheus;

# Put this controller at top-level.
__PACKAGE__->config->{namespace} = '';
@@ -200,6 +202,49 @@ sub machines :Local Args(0) {
$self->status_ok($c, entity => $c->stash->{machines});
}

sub prometheus :Local Args(0) {
my ($self, $c) = @_;
my $machines = getMachines;

my $client = Net::Prometheus->new;
my $duration = $client->new_histogram(
name => "hydra_machine_build_duration",
help => "How long builds are taking per server. Note: counts are gauges, NOT counters.",
labels => [ "machine" ],
buckets => [
60,
600,
1800,
3600,
7200,
21600,
43200,
86400,
172800,
259200,
345600,
518400,
604800,
691200
]
);

my $steps = dbh($c)->selectall_arrayref(
"select machine, s.starttime as starttime " .
"from BuildSteps s join Builds b on s.build = b.id " .
"where busy != 0 order by machine, stepnr",
{ Slice => {} });

foreach my $step (@$steps) {
my $name = $step->{machine} ? Hydra::View::TT->stripSSHUser(undef, $step->{machine}) : "";
$name = "localhost" unless $name;
$duration->labels($name)->observe(time - $step->{starttime});
}

$c->stash->{'plain'} = { data => $client->render };
$c->forward('Hydra::View::Plain');
}


# Hydra::Base::Controller::ListBuilds needs this.
sub get_builds : Chained('/') PathPart('') CaptureArgs(0) {
44 changes: 44 additions & 0 deletions src/lib/Hydra/Helper/CatalystUtils.pm
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ our @EXPORT = qw(
searchBuildsAndEvalsForJobset
error notFound gone accessDenied
forceLogin requireUser requireProjectOwner requireRestartPrivileges requireAdmin requirePost isAdmin isProjectOwner
requireBumpPrivileges
requireCancelBuildPrivileges
trim
getLatestFinishedEval getFirstEval
paramToList
@@ -181,6 +183,48 @@ sub isProjectOwner {
defined $c->model('DB::ProjectMembers')->find({ project => $project, userName => $c->user->username }));
}

sub hasCancelBuildRole {
my ($c) = @_;
return $c->user_exists && $c->check_user_roles('cancel-build');
}

sub mayCancelBuild {
my ($c, $project) = @_;
return
$c->user_exists &&
(isAdmin($c) ||
hasCancelBuildRole($c) ||
isProjectOwner($c, $project));
}

sub requireCancelBuildPrivileges {
my ($c, $project) = @_;
requireUser($c);
accessDenied($c, "Only the project members, administrators, and accounts with cancel-build privileges can perform this operation.")
unless mayCancelBuild($c, $project);
}

sub hasBumpJobsRole {
my ($c) = @_;
return $c->user_exists && $c->check_user_roles('bump-to-front');
}

sub mayBumpJobs {
my ($c, $project) = @_;
return
$c->user_exists &&
(isAdmin($c) ||
hasBumpJobsRole($c) ||
isProjectOwner($c, $project));
}

sub requireBumpPrivileges {
my ($c, $project) = @_;
requireUser($c);
accessDenied($c, "Only the project members, administrators, and accounts with bump-to-front privileges can perform this operation.")
unless mayBumpJobs($c, $project);
}

sub hasRestartJobsRole {
my ($c) = @_;
return $c->user_exists && $c->check_user_roles('restart-jobs');
2 changes: 2 additions & 0 deletions src/root/user.tt
Original file line number Diff line number Diff line change
@@ -81,6 +81,8 @@
[% INCLUDE roleoption role="admin" %]
[% INCLUDE roleoption role="create-projects" %]
[% INCLUDE roleoption role="restart-jobs" %]
[% INCLUDE roleoption role="bump-to-front" %]
[% INCLUDE roleoption role="cancel-build" %]
</select>
</div>
</div>
2 changes: 0 additions & 2 deletions src/script/hydra-eval-jobset
Original file line number Diff line number Diff line change
@@ -440,8 +440,6 @@ sub checkBuild {
# new build to be scheduled if the meta.maintainers field is
# changed?
if (defined $prevEval) {
# Only check one output: if it's the same, the other will be as well.
my $firstOutput = $outputNames[0];
my ($prevBuild) = $prevEval->builds->search(
# The "project" and "jobset" constraints are
# semantically unnecessary (because they're implied by