From 4171ab4c4fd576c516dc03ba64d1c7945f769af0 Mon Sep 17 00:00:00 2001 From: danbst Date: Fri, 29 Mar 2019 23:46:38 +0200 Subject: [PATCH 01/10] tests: change postgresql socket dir to /tmp In https://github.com/NixOS/nixpkgs/pull/57677 default postgresql socket directory was changed to `/run/postgresql`, which doesn't exist (and can't be created) in Nix build environment. We'll use /tmp as socket dir explicitly then. Fixes build failure https://hydra.nixos.org/build/91221682 Cc @aszlig @edolstra --- .gitignore | 1 + tests/Makefile.am | 1 + tests/set-up.pl | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ab5603e2..e53ae6a8 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ Makefile.in /inst hydra-config.h hydra-config.h.in +result diff --git a/tests/Makefile.am b/tests/Makefile.am index cff12f09..e56e528e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -12,6 +12,7 @@ TESTS_ENVIRONMENT = \ NIX_STORE_DIR="$(abs_builddir)/nix/store" \ NIX_LOG_DIR="$(abs_builddir)/nix/var/log/nix" \ NIX_BUILD_HOOK= \ + PGHOST=/tmp \ PERL5LIB="$(srcdir):$(abs_top_srcdir)/src/lib:$$PERL5LIB" \ PATH=$(abs_top_srcdir)/src/hydra-evaluator:$(abs_top_srcdir)/src/script:$(abs_top_srcdir)/src/hydra-eval-jobs:$(abs_top_srcdir)/src/hydra-queue-runner:$$PATH \ perl -w diff --git a/tests/set-up.pl b/tests/set-up.pl index 63679b63..d7aa35cc 100644 --- a/tests/set-up.pl +++ b/tests/set-up.pl @@ -1,5 +1,5 @@ use strict; system("initdb -D postgres") == 0 or die; -system("pg_ctl -D postgres -o \"-F -p 6433 -h ''\" -w start") == 0 or die; +system("pg_ctl -D postgres -o \"-F -p 6433 -h '' -k /tmp \" -w start") == 0 or die; system("createdb -p 6433 hydra-test-suite") == 0 or die; system("hydra-init") == 0 or die; From 778fc03570431bc75fd2cfc21dc62505d1d66c34 Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Tue, 4 Jun 2019 09:39:04 +0200 Subject: [PATCH 02/10] Allow to search builds by hash Currently, a full store path has to be provided to search in builds. This patch permits to search jobs with a output path or derivation hash. Usecase: we are building Docker images with Hydra. The tag of the Docker image is the hash of the image output path. This patch would allow us to find back the build job from the tag of a running container image. --- src/lib/Hydra/Controller/Root.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index fcc62138..41f6305c 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -422,11 +422,11 @@ sub search :Local Args(0) { # Perform build search in separate queries to prevent seq scan on buildoutputs table. $c->stash->{builds} = [ $c->model('DB::Builds')->search( - { "buildoutputs.path" => trim($query) }, + { "buildoutputs.path" => { ilike => "%$query%" } }, { order_by => ["id desc"], join => ["buildoutputs"] } ) ]; $c->stash->{buildsdrv} = [ $c->model('DB::Builds')->search( - { "drvpath" => trim($query) }, + { "drvpath" => { ilike => "%$query%" } }, { order_by => ["id desc"] } ) ]; $c->stash->{resource} = { projects => $c->stash->{projects}, From 7935cffd6b14a0861489c32ba091cff7f75d818a Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Thu, 6 Jun 2019 11:57:11 +0200 Subject: [PATCH 03/10] Create a pg_trgm index on builds.drvpath The search query uses the LIKE operator which requires a sequential scan (it can't use the already existing B-tree index). This new index (trigram) avoids a sequential scan of the builds table when the LIKE operator is used. Here is the analyze of a request on the builds table with this index: explain analyze select * from builds where drvpath like '%k3r71gz0gv16ld8rhcp2bb8gb5w1xc4b%'; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------- Bitmap Heap Scan on builds (cost=128.00..132.01 rows=1 width=492) (actual time=0.070..0.077 rows=1 loops=1) Recheck Cond: (drvpath ~~ '%k3r71gz0gv16ld8rhcp2bb8gb5w1xc4b%'::text) -> Bitmap Index Scan on indextrgmbuildsondrvpath (cost=0.00..128.00 rows=1 width=0) (actual time=0.047..0.047 rows=3 loops=1) Index Cond: (drvpath ~~ '%k3r71gz0gv16ld8rhcp2bb8gb5w1xc4b%'::text) Total runtime: 0.206 ms (5 rows) --- src/sql/hydra.sql | 6 ++++++ src/sql/upgrade-57.sql | 2 ++ 2 files changed, 8 insertions(+) create mode 100644 src/sql/upgrade-57.sql diff --git a/src/sql/hydra.sql b/src/sql/hydra.sql index 4c8710b8..a39d9aac 100644 --- a/src/sql/hydra.sql +++ b/src/sql/hydra.sql @@ -688,3 +688,9 @@ create index IndexBuildsOnKeep on Builds(keep) where keep = 1; create index IndexJobsetEvalsOnJobsetId on JobsetEvals(project, jobset, id desc) where hasNewBuilds = 1; create index IndexBuildsOnNotificationPendingSince on Builds(notificationPendingSince) where notificationPendingSince is not null; + +#ifdef POSTGRESQL +-- Provide an index used by LIKE operator on builds.drvpath (search query) +CREATE EXTENSION pg_trgm; +CREATE INDEX IndexTrgmBuildsOnDrvpath ON builds USING gin (drvpath gin_trgm_ops); +#endif diff --git a/src/sql/upgrade-57.sql b/src/sql/upgrade-57.sql new file mode 100644 index 00000000..f950a6e0 --- /dev/null +++ b/src/sql/upgrade-57.sql @@ -0,0 +1,2 @@ +CREATE EXTENSION pg_trgm; +CREATE INDEX IndexTrgmBuildsOnDrvpath ON builds USING gin (drvpath gin_trgm_ops); From cb1fce21ba4f8c7926f58f2d4c53047e1396b4e4 Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Wed, 19 Jun 2019 12:27:19 +0200 Subject: [PATCH 04/10] hydra-server: set a limit on builds and buildoutputs search This patch adds a limit statement for Postgresql queries on `builds` and `buildsoutputs` tables. --- src/lib/Hydra/Controller/Root.pm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 41f6305c..796c4b6f 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -423,11 +423,15 @@ sub search :Local Args(0) { # Perform build search in separate queries to prevent seq scan on buildoutputs table. $c->stash->{builds} = [ $c->model('DB::Builds')->search( { "buildoutputs.path" => { ilike => "%$query%" } }, - { order_by => ["id desc"], join => ["buildoutputs"] } ) ]; + { order_by => ["id desc"], join => ["buildoutputs"] + , rows => $c->stash->{limit} + } ) ]; $c->stash->{buildsdrv} = [ $c->model('DB::Builds')->search( { "drvpath" => { ilike => "%$query%" } }, - { order_by => ["id desc"] } ) ]; + { order_by => ["id desc"] + , rows => $c->stash->{limit} + } ) ]; $c->stash->{resource} = { projects => $c->stash->{projects}, jobsets => $c->stash->{jobsets}, From d1e590af1f4cb131e5de0c7cf2fa7d855a2ae15c Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Wed, 19 Jun 2019 12:33:25 +0200 Subject: [PATCH 05/10] hydra-server: add `limit` parameter to the `search` path This allows a client to set a limit to the search results it wants to get: http://hydra.nixos.org/search?query=emacs&limit=1 This returns only 1 results (while the default is 500). --- src/lib/Hydra/Controller/Root.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 796c4b6f..188d73bd 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -391,7 +391,12 @@ sub search :Local Args(0) { error($c, "Invalid character in query.") unless $query =~ /^[a-zA-Z0-9_\-\/.]+$/; - $c->stash->{limit} = 500; + my $limit = trim $c->request->params->{"limit"}; + if ($limit eq "") { + $c->stash->{limit} = 500; + } else { + $c->stash->{limit} = $limit; + } $c->stash->{projects} = [ $c->model('DB::Projects')->search( { -and => From c620bc2be0b257c632db99824a7764491654af35 Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Fri, 21 Jun 2019 16:57:12 +0200 Subject: [PATCH 06/10] test.api: use Hydra perl dependencies to run `api-test.pl` The test was failing with: machine# Can't locate LWP/UserAgent.pm in @INC (you may need to install the LWP::UserAgent module)... --- release.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.nix b/release.nix index dd28cef0..1ee47e96 100644 --- a/release.nix +++ b/release.nix @@ -219,7 +219,7 @@ rec { $machine->waitForOpenPort("3000"); # Run the API tests. - $machine->mustSucceed("su - hydra -c 'perl ${./tests/api-test.pl}' >&2"); + $machine->mustSucceed("su - hydra -c 'perl -I ${build.${system}.perlDeps}/lib/perl5/site_perl ${./tests/api-test.pl}' >&2"); ''; }); From 42784a9053b801c3c62e97dbf18b66043a0ff5af Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Thu, 20 Jun 2019 14:41:44 +0200 Subject: [PATCH 07/10] sql: refactor some sql statements to lowercase --- src/sql/hydra.sql | 4 ++-- src/sql/upgrade-57.sql | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sql/hydra.sql b/src/sql/hydra.sql index a39d9aac..869175d6 100644 --- a/src/sql/hydra.sql +++ b/src/sql/hydra.sql @@ -691,6 +691,6 @@ create index IndexBuildsOnNotificationPendingSince on Builds(notificationPending #ifdef POSTGRESQL -- Provide an index used by LIKE operator on builds.drvpath (search query) -CREATE EXTENSION pg_trgm; -CREATE INDEX IndexTrgmBuildsOnDrvpath ON builds USING gin (drvpath gin_trgm_ops); +create extension pg_trgm; +create index IndexTrgmBuildsOnDrvpath on builds using gin (drvpath gin_trgm_ops); #endif diff --git a/src/sql/upgrade-57.sql b/src/sql/upgrade-57.sql index f950a6e0..04826ab0 100644 --- a/src/sql/upgrade-57.sql +++ b/src/sql/upgrade-57.sql @@ -1,2 +1,2 @@ -CREATE EXTENSION pg_trgm; -CREATE INDEX IndexTrgmBuildsOnDrvpath ON builds USING gin (drvpath gin_trgm_ops); +create extension pg_trgm; +create index IndexTrgmBuildsOnDrvpath on builds using gin (drvpath gin_trgm_ops); From 8a0a5ec3a3200d4f4d4d38f87d0afdb49f092b39 Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Thu, 20 Jun 2019 14:53:43 +0200 Subject: [PATCH 08/10] Create extension pg_trgm in the NixOS module The creation of the `pg_trgm` extension needs superuser power. So, this patch makes the extension creation in the Hydra NixOS module when a local database is used. If it is not possible to create this extension (remote database for instance with nosuperuser), the creation of the `pg_trgm` index is skipped (this index speedup queries on builds.drvpath) and warnings are emitted: initialising the Hydra database schema... WARNING: Can not create extension pg_trgm: permission denied to create extension "pg_trgm" WARNING: HINT: Temporary provide superuser role to your Hydra Postgresql user and run the script src/sql/upgrade-57.sql WARNING: The pg_trgm index on builds.drvpath has been skipped (slower complex queries on builds.drvpath) This allows to keep smooth migrations: the migration process doesn't require a manual step (but this manual step is recommended on big remote databases). --- hydra-module.nix | 3 +++ src/sql/hydra.sql | 19 ++++++++++++++++--- src/sql/upgrade-57.sql | 18 ++++++++++++++++-- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/hydra-module.nix b/hydra-module.nix index ce5dc266..52eccd40 100644 --- a/hydra-module.nix +++ b/hydra-module.nix @@ -273,6 +273,7 @@ in runuser -u ${config.services.postgresql.superUser} -- ${config.services.postgresql.package}/bin/createdb -O hydra hydra touch ${baseDir}/.db-created fi + echo "create extension if not exists pg_trgm" | runuser -u ${config.services.postgresql.superUser} -- ${config.services.postgresql.package}/bin/psql hydra ''} if [ ! -e ${cfg.gcRootsDir} ]; then @@ -415,6 +416,8 @@ in hydra-users hydra-queue-runner hydra hydra-users hydra-www hydra hydra-users root hydra + # The postgres user is used to create the pg_trgm extension for the hydra database + hydra-users postgres postgres ''; services.postgresql.authentication = optionalString haveLocalDB diff --git a/src/sql/hydra.sql b/src/sql/hydra.sql index 869175d6..0c769a7e 100644 --- a/src/sql/hydra.sql +++ b/src/sql/hydra.sql @@ -690,7 +690,20 @@ create index IndexJobsetEvalsOnJobsetId on JobsetEvals(project, jobset, id desc) create index IndexBuildsOnNotificationPendingSince on Builds(notificationPendingSince) where notificationPendingSince is not null; #ifdef POSTGRESQL --- Provide an index used by LIKE operator on builds.drvpath (search query) -create extension pg_trgm; -create index IndexTrgmBuildsOnDrvpath on builds using gin (drvpath gin_trgm_ops); +-- The pg_trgm extension has to be created by a superuser. The NixOS +-- module creates this extension in the systemd prestart script. We +-- then ensure the extension has been created before creating the +-- index. If it is not possible to create the extension, a warning +-- message is emitted to inform the user the index creation is skipped +-- (slower complex queries on builds.drvpath). +do $$ +begin + create extension if not exists pg_trgm; + -- Provide an index used by LIKE operator on builds.drvpath (search query) + create index IndexTrgmBuildsOnDrvpath on builds using gin (drvpath gin_trgm_ops); +exception when others then + raise warning 'Can not create extension pg_trgm: %', SQLERRM; + raise warning 'HINT: Temporary provide superuser role to your Hydra Postgresql user and run the script src/sql/upgrade-57.sql'; + raise warning 'The pg_trgm index on builds.drvpath has been skipped (slower complex queries on builds.drvpath)'; +end$$; #endif diff --git a/src/sql/upgrade-57.sql b/src/sql/upgrade-57.sql index 04826ab0..cae873d4 100644 --- a/src/sql/upgrade-57.sql +++ b/src/sql/upgrade-57.sql @@ -1,2 +1,16 @@ -create extension pg_trgm; -create index IndexTrgmBuildsOnDrvpath on builds using gin (drvpath gin_trgm_ops); +-- The pg_trgm extension has to be created by a superuser. The NixOS +-- module creates this extension in the systemd prestart script. We +-- then ensure the extension has been created before creating the +-- index. If it is not possible to create the extension, a warning +-- message is emitted to inform the user the index creation is skipped +-- (slower complex queries on builds.drvpath). +do $$ +begin + create extension if not exists pg_trgm; + -- Provide an index used by LIKE operator on builds.drvpath (search query) + create index IndexTrgmBuildsOnDrvpath on builds using gin (drvpath gin_trgm_ops); +exception when others then + raise warning 'Can not create extension pg_trgm: %', SQLERRM; + raise warning 'HINT: Temporary provide superuser role to your Hydra Postgresql user and run the script src/sql/upgrade-57.sql'; + raise warning 'The pg_trgm index on builds.drvpath has been skipped (slower complex queries on builds.drvpath)'; +end$$; From 06bdc8f85c60ab29be363e9f7c23e734ec1f2389 Mon Sep 17 00:00:00 2001 From: Nikola Knezevic Date: Thu, 25 Jul 2019 09:43:40 +0200 Subject: [PATCH 09/10] Added the InfluxDBNotification plugin including a NixOS test This adds a `InfluxDBNotification` plugin which is configured as: ``` url = http://127.0.0.1:8086 db = hydra ``` which will write a notification for every finished job to the configured database in InfluxDB looking like: ``` hydra_build_status,cached=false,job=job,jobset=default,project=sample,repo=default,result=success,status=success,system=x86_64-linux build_id="1",build_status=0i,closure_size=584i,duration=0i,main_build_id="1",queued=0i,size=168i 1564156212 ``` --- release.nix | 68 +++++++++ src/lib/Hydra/Plugin/InfluxDBNotification.pm | 137 +++++++++++++++++++ tests/setup-notifications-jobset.pl | 56 ++++++++ 3 files changed, 261 insertions(+) create mode 100644 src/lib/Hydra/Plugin/InfluxDBNotification.pm create mode 100644 tests/setup-notifications-jobset.pl diff --git a/release.nix b/release.nix index 1ee47e96..bdd9dae3 100644 --- a/release.nix +++ b/release.nix @@ -28,6 +28,22 @@ let services.postgresql.package = pkgs.postgresql95; environment.systemPackages = [ pkgs.perlPackages.LWP pkgs.perlPackages.JSON ]; + + # The following is to work around the following error from hydra-server: + # [error] Caught exception in engine "Cannot determine local time zone" + time.timeZone = "UTC"; + + nix = { + # The following is to work around: https://github.com/NixOS/hydra/pull/432 + buildMachines = [ + { hostName = "localhost"; + system = "x86_64-linux"; + } + ]; + # Without this nix tries to fetch packages from the default + # cache.nixos.org which is not reachable from this sandboxed NixOS test. + binaryCaches = []; + }; }; version = builtins.readFile ./version + "." + toString hydraSrc.revCount + "." + hydraSrc.rev; @@ -223,6 +239,58 @@ rec { ''; }); + tests.notifications = genAttrs' (system: + with import (nixpkgs + "/nixos/lib/testing.nix") { inherit system; }; + simpleTest { + machine = { pkgs, ... }: { + imports = [ (hydraServer build.${system}) ]; + services.hydra-dev.extraConfig = '' + + url = http://127.0.0.1:8086 + db = hydra + + ''; + services.influxdb.enable = true; + }; + testScript = '' + $machine->waitForJob("hydra-init"); + + # Create an admin account and some other state. + $machine->succeed + ( "su - hydra -c \"hydra-create-user root --email-address 'alice\@example.org' --password foobar --role admin\"" + , "mkdir /run/jobset" + , "chmod 755 /run/jobset" + , "cp ${./tests/api-test.nix} /run/jobset/default.nix" + , "chmod 644 /run/jobset/default.nix" + , "chown -R hydra /run/jobset" + ); + + # Wait until InfluxDB can receive web requests + $machine->waitForJob("influxdb"); + $machine->waitForOpenPort("8086"); + + # Create an InfluxDB database where hydra will write to + $machine->succeed( + "curl -XPOST 'http://127.0.0.1:8086/query' \\ + --data-urlencode 'q=CREATE DATABASE hydra'"); + + # Wait until hydra-server can receive HTTP requests + $machine->waitForJob("hydra-server"); + $machine->waitForOpenPort("3000"); + + # Setup the project and jobset + $machine->mustSucceed( + "su - hydra -c 'perl -I ${build.${system}.perlDeps}/lib/perl5/site_perl ${./tests/setup-notifications-jobset.pl}' >&2"); + + # Wait until hydra has build the job and + # the InfluxDBNotification plugin uploaded its notification to InfluxDB + $machine->waitUntilSucceeds( + "curl -s -H 'Accept: application/csv' \\ + -G 'http://127.0.0.1:8086/query?db=hydra' \\ + --data-urlencode 'q=SELECT * FROM hydra_build_status' | grep success"); + ''; + }); + /* tests.s3backup = genAttrs' (system: with import (nixpkgs + "/nixos/lib/testing.nix") { inherit system; }; diff --git a/src/lib/Hydra/Plugin/InfluxDBNotification.pm b/src/lib/Hydra/Plugin/InfluxDBNotification.pm new file mode 100644 index 00000000..bef83d1c --- /dev/null +++ b/src/lib/Hydra/Plugin/InfluxDBNotification.pm @@ -0,0 +1,137 @@ +package Hydra::Plugin::InfluxDBNotification; + +use strict; +use parent 'Hydra::Plugin'; +use HTTP::Request; +# use JSON; +use LWP::UserAgent; +# use Hydra::Helper::CatalystUtils; + +sub toBuildStatusDetailed { + my ($buildStatus) = @_; + if ($buildStatus == 0) { + return "success"; + } + elsif ($buildStatus == 1) { + return "failure"; + } + elsif ($buildStatus == 2) { + return "dependency-failed"; + } + elsif ($buildStatus == 4) { + return "cancelled"; + } + elsif ($buildStatus == 6) { + return "failed-with-output"; + } + elsif ($buildStatus == 7) { + return "timed-out"; + } + elsif ($buildStatus == 9) { + return "unsupported-system"; + } + elsif ($buildStatus == 10) { + return "log-limit-exceeded"; + } + elsif ($buildStatus == 11) { + return "output-limit-exceeded"; + } + elsif ($buildStatus == 12) { + return "non-deterministic-build"; + } + else { + return "aborted"; + } +} + +sub toBuildStatusClass { + my ($buildStatus) = @_; + if ($buildStatus == 0) { + return "success"; + } + elsif ($buildStatus == 3 + || $buildStatus == 4 + || $buildStatus == 8 + || $buildStatus == 10 + || $buildStatus == 11) + { + return "canceled"; + } + else { + return "failed"; + } +} + +# Syntax +# build_status,job=my-job status=failed,result=dependency-failed duration=123i +# | -------------------- -------------- | +# | | | | +# | | | | +# +-----------+--------+-+---------+-+---------+ +# |measurement|,tag_set| |field_set| |timestamp| +# +-----------+--------+-+---------+-+---------+ +sub createLine { + my ($measurement, $tagSet, $fieldSet, $timestamp) = @_; + my @tags = (); + foreach my $tag (sort keys %$tagSet) { + push @tags, "$tag=$tagSet->{$tag}"; + } + my @fields = (); + foreach my $field (sort keys %$fieldSet) { + push @fields, "$field=$fieldSet->{$field}"; + } + my $tags = join(",", @tags); + my $fields = join(",", @fields); + return "$measurement,$tags $fields $timestamp"; +} + +sub buildFinished { + my ($self, $build, $dependents) = @_; + my $influxdb = $self->{config}->{influxdb}; + + # skip if we didn't configure + return unless defined $influxdb; + # skip if we didn't set the URL and the DB + return unless ref $influxdb eq 'HASH' and exists $influxdb->{url} and exists $influxdb->{db}; + + my @lines = (); + foreach my $b ($build, @{$dependents}) { + my $tagSet = { + status => toBuildStatusClass($b->buildstatus), + result => toBuildStatusDetailed($b->buildstatus), + project => $b->project->name, + jobset => $b->jobset->name, + repo => ($b->jobset->name =~ /^(.*)\.pr-/) ? $1 : $b->jobset->name, + job => $b->job->name, + system => $b->system, + cached => $b->iscachedbuild ? "true" : "false", + }; + my $fieldSet = { + # this line is needed to be able to query the statuses + build_status => $b->buildstatus . "i", + build_id => '"' . $b->id . '"', + main_build_id => '"' . $build->id . '"', + duration => ($b->stoptime - $b->starttime) . "i", + queued => ($b->starttime - $b->timestamp > 0 ? $b->starttime - $b->timestamp : 0) . "i", + closure_size => ($b->closuresize // 0) . "i", + size => ($b->size // 0) . "i", + }; + my $line = + createLine("hydra_build_status", $tagSet, $fieldSet, $b->stoptime); + push @lines, $line; + } + + my $payload = join("\n", @lines); + print STDERR "sending InfluxDB measurements to server $influxdb->{url}:\n$payload\n"; + + my $ua = LWP::UserAgent->new(); + my $req = HTTP::Request->new('POST', + "$influxdb->{url}/write?db=$influxdb->{db}&precision=s"); + $req->header('Content-Type' => 'application/x-www-form-urlencoded'); + $req->content($payload); + my $res = $ua->request($req); + print STDERR $res->status_line, ": ", $res->decoded_content, "\n" + unless $res->is_success; +} + +1; diff --git a/tests/setup-notifications-jobset.pl b/tests/setup-notifications-jobset.pl new file mode 100644 index 00000000..8eef78e6 --- /dev/null +++ b/tests/setup-notifications-jobset.pl @@ -0,0 +1,56 @@ +use LWP::UserAgent; +use JSON; + +my $ua = LWP::UserAgent->new; +$ua->cookie_jar({}); + +sub request_json { + my ($opts) = @_; + my $req = HTTP::Request->new; + $req->method($opts->{method} or "GET"); + $req->uri("http://localhost:3000$opts->{uri}"); + $req->header(Accept => "application/json"); + $req->header(Referer => "http://localhost:3000/") if $opts->{method} eq "POST"; + $req->content(encode_json($opts->{data})) if defined $opts->{data}; + my $res = $ua->request($req); + print $res->as_string(); + return $res; +} + +my $result = request_json({ + uri => "/login", + method => "POST", + data => { + username => "root", + password => "foobar" + } +}); + +$result = request_json({ + uri => '/project/sample', + method => 'PUT', + data => { + displayname => "Sample", + enabled => "1", + visible => "1", + } +}); + +$result = request_json({ + uri => '/jobset/sample/default', + method => 'PUT', + data => { + nixexprpath => "default.nix", + nixexprinput => "my-src", + inputs => { + "my-src" => { + type => "path", + value => "/run/jobset" + } + }, + enabled => "1", + visible => "1", + checkinterval => "5", + keepnr => 1 + } +}); From bb4f349161083a324784d0d5c5af80fbc9b3b321 Mon Sep 17 00:00:00 2001 From: Craige McWhirter Date: Fri, 9 Aug 2019 13:49:21 +1000 Subject: [PATCH 10/10] Corrected grammer typo Replaced you with look --- doc/manual/projects.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual/projects.xml b/doc/manual/projects.xml index 44b6238f..02b9811d 100644 --- a/doc/manual/projects.xml +++ b/doc/manual/projects.xml @@ -205,7 +205,7 @@ in shows what a release.nix file for GNU Hello - would you like. GNU Hello is representative of many GNU + would look like. GNU Hello is representative of many GNU and non-GNU free software projects: