all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] Support returning build information by output.
@ 2020-01-04  9:51 Christopher Baines
  2020-01-08 21:21 ` Ludovic Courtès
  0 siblings, 1 reply; 3+ messages in thread
From: Christopher Baines @ 2020-01-04  9:51 UTC (permalink / raw)
  To: guix-devel

Being able to take a derivation and query the build information is useful, but
in cases where there are multiple derivations that produce the same outputs,
the probability of getting the data back from Cuirass is reduced.

This is because Cuirass might not have build the exact derivation you have,
but a different derivation that produces the same outputs (this can commonly
happen when a related fixed output derivation changes).

Cuirass doesn't store derivations if they produce the same outputs as a
derivation it already knows about, so it can't determine if this is the
case. Therefore, provide a way of querying build results by output, rather
than derivation.

The motivation behind this is to make it easier to import build information in
to the Guix Data Service.

* src/cuirass/database.scm (db-get-output): New procedure.
* src/cuirass/http.scm (respond-output-not-found): New procedure.
(request-path-components): Handle /output/… requests.
* doc/cuirass.texi (Build information): Mention that you can get build
information by output.
---
 doc/cuirass.texi         |  4 ++++
 src/cuirass/database.scm | 15 +++++++++++++++
 src/cuirass/http.scm     | 15 +++++++++++++++
 3 files changed, 34 insertions(+)

diff --git a/doc/cuirass.texi b/doc/cuirass.texi
index ebb1fa5..e652e8d 100644
--- a/doc/cuirass.texi
+++ b/doc/cuirass.texi
@@ -477,6 +477,10 @@ It is possible to query Cuirass web server for build informations. The
 dedicated API is "/build/@var{build-id}" where @var{build-id} is the
 unique id associated to the build in database.
 
+The build information can also be queried by output. For example,
+@samp{/output/kg9mirg6xbvzcp0a98v7326n1nvvwgsj-hello-2.10} will return
+the details of the output, along with the build if available.
+
 For instance, querying a local Cuirass web server can be done with
 @code{curl} and @code{jq} to format the JSON response :
 
diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index 523165d..66e93e2 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -47,6 +47,7 @@
             build-status
             db-add-build
             db-update-build-status!
+            db-get-output
             db-get-build
             db-get-builds
             db-get-builds-by-search
@@ -539,6 +540,20 @@ log file for DRV."
                          "WHERE derivation=" drv " AND status != " status
                          ";")))))
 
+(define (db-get-output path)
+  "Retrieve the OUTPUT for PATH."
+  (with-db-critical-section db
+    ;; There isn't a unique index on path, but because Cuirass avoids adding
+    ;; derivations which introduce the same outputs, there should only be one
+    ;; result.
+    (match (sqlite-exec db "SELECT derivation, name FROM Outputs
+WHERE path =" path "
+LIMIT 1;")
+      (() #f)
+      ((#(derivation name))
+       `((#:derivation . ,derivation)
+         (#:name . ,name))))))
+
 (define (db-get-outputs derivation)
   "Retrieve the OUTPUTS of the build identified by DERIVATION in the
 database."
diff --git a/src/cuirass/http.scm b/src/cuirass/http.scm
index 7579e1a..bf436c5 100644
--- a/src/cuirass/http.scm
+++ b/src/cuirass/http.scm
@@ -226,6 +226,11 @@ Hydra format."
      404
      (format #f "Build with ID ~a doesn't exist." build-id)))
 
+  (define (respond-output-not-found output-id)
+    (respond-json-with-error
+     404
+     (format #f "Output with ID ~a doesn't exist." output-id)))
+
   (define (respond-html-eval-not-found eval-id)
     (respond-html
      (html-page "Page not found"
@@ -331,6 +336,16 @@ Hydra format."
              (#f
               (respond-build-not-found build-id)))
            (respond-build-not-found build-id))))
+    (('GET "output" id)
+     (let ((output (db-get-output
+                    (string-append (%store-prefix) "/" id))))
+       (if output
+           (let ((build (db-get-build (assq-ref output #:derivation))))
+             (respond-json
+              (object->json-string
+               (append output
+                       `((#:build . ,(or build #nil)))))))
+           (respond-output-not-found id))))
     (('GET "api" "evaluations")
      (let* ((params (request-parameters request))
             ;; 'nr parameter is mandatory to limit query size.
-- 
2.24.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Support returning build information by output.
  2020-01-04  9:51 [PATCH] Support returning build information by output Christopher Baines
@ 2020-01-08 21:21 ` Ludovic Courtès
  2020-01-16  8:36   ` Christopher Baines
  0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Courtès @ 2020-01-08 21:21 UTC (permalink / raw)
  To: Christopher Baines; +Cc: guix-devel

Hi,

Christopher Baines <mail@cbaines.net> skribis:

> Being able to take a derivation and query the build information is useful, but
> in cases where there are multiple derivations that produce the same outputs,
> the probability of getting the data back from Cuirass is reduced.
>
> This is because Cuirass might not have build the exact derivation you have,
> but a different derivation that produces the same outputs (this can commonly
> happen when a related fixed output derivation changes).
>
> Cuirass doesn't store derivations if they produce the same outputs as a
> derivation it already knows about, so it can't determine if this is the
> case. Therefore, provide a way of querying build results by output, rather
> than derivation.
>
> The motivation behind this is to make it easier to import build information in
> to the Guix Data Service.
>
> * src/cuirass/database.scm (db-get-output): New procedure.
> * src/cuirass/http.scm (respond-output-not-found): New procedure.
> (request-path-components): Handle /output/… requests.
> * doc/cuirass.texi (Build information): Mention that you can get build
> information by output.

LGTM, thanks!

Ludo’.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Support returning build information by output.
  2020-01-08 21:21 ` Ludovic Courtès
@ 2020-01-16  8:36   ` Christopher Baines
  0 siblings, 0 replies; 3+ messages in thread
From: Christopher Baines @ 2020-01-16  8:36 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 1283 bytes --]


Ludovic Courtès <ludo@gnu.org> writes:

> Christopher Baines <mail@cbaines.net> skribis:
>
>> Being able to take a derivation and query the build information is useful, but
>> in cases where there are multiple derivations that produce the same outputs,
>> the probability of getting the data back from Cuirass is reduced.
>>
>> This is because Cuirass might not have build the exact derivation you have,
>> but a different derivation that produces the same outputs (this can commonly
>> happen when a related fixed output derivation changes).
>>
>> Cuirass doesn't store derivations if they produce the same outputs as a
>> derivation it already knows about, so it can't determine if this is the
>> case. Therefore, provide a way of querying build results by output, rather
>> than derivation.
>>
>> The motivation behind this is to make it easier to import build information in
>> to the Guix Data Service.
>>
>> * src/cuirass/database.scm (db-get-output): New procedure.
>> * src/cuirass/http.scm (respond-output-not-found): New procedure.
>> (request-path-components): Handle /output/… requests.
>> * doc/cuirass.texi (Build information): Mention that you can get build
>> information by output.
>
> LGTM, thanks!

Great, I've pushed this now :)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 962 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-01-16  8:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-04  9:51 [PATCH] Support returning build information by output Christopher Baines
2020-01-08 21:21 ` Ludovic Courtès
2020-01-16  8:36   ` Christopher Baines

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.