Skip to content

Commit 3016026

Browse files
authored
Merge pull request #1 from clearpathrobotics/CORE-21733-get-info-buildsteps
Provide build step information
2 parents e275604 + b2c79e0 commit 3016026

File tree

3 files changed

+240
-17
lines changed

3 files changed

+240
-17
lines changed

hydra-api.yaml

Lines changed: 197 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,33 @@ paths:
507507
schema:
508508
$ref: '#/components/schemas/Error'
509509

510+
/build/{build-id}/api/get-info:
511+
get:
512+
summary: Retrieves info about this build id, providing information about the steps in it.
513+
parameters:
514+
- name: build-id
515+
in: path
516+
description: build identifier
517+
required: true
518+
schema:
519+
type: integer
520+
responses:
521+
'200':
522+
description: build
523+
content:
524+
application/json:
525+
schema:
526+
$ref: '#/components/schemas/BuildInfo'
527+
examples:
528+
build-success:
529+
$ref: '#/components/examples/build-get-info-success'
530+
'404':
531+
description: build couldn't be found
532+
content:
533+
application/json:
534+
schema:
535+
$ref: '#/components/schemas/Error'
536+
510537
/build/{build-id}/constituents:
511538
get:
512539
summary: Retrieves a build's constituent jobs
@@ -673,7 +700,7 @@ components:
673700
nullable: true
674701
description: the path to the file to evaluate
675702
type: string
676-
errormsg:
703+
errormsg: &schema_errormsg
677704
nullable: true
678705
description: contains the stderr output of the nix-instantiate command
679706
type: string
@@ -813,7 +840,7 @@ components:
813840
checkinterval:
814841
description: interval in seconds at which to check the jobset inputs
815842
type: integer
816-
haserrormsg:
843+
haserrormsg: &schema_haserrormsg
817844
description: true if the evaluation had errors
818845
type: boolean
819846
nrscheduled:
@@ -896,66 +923,68 @@ components:
896923
description: The nix store path
897924
type: string
898925

899-
Build:
926+
Build:
900927
type: object
901928
properties:
902929
id:
903930
type: integer
904-
starttime:
931+
starttime: &schema_starttime
905932
description: time when build started
906933
type: integer
907-
stoptime:
934+
stoptime: &schema_stoptime
908935
description: time when build ended
909936
type: integer
910-
timestamp:
937+
timestamp: &schema_timestamp
911938
description: time when the build was first created
912939
type: integer
913940
jobsetevals:
914941
description: list of evaluations this build is part of
915942
type: array
916943
items:
917944
type: integer
918-
finished:
945+
finished: &schema_finished
919946
description: true when the build is finished
920947
type: boolean
921-
nixname:
948+
nixname: &schema_nixname
922949
description: name from the build's derivation
923950
type: string
924-
buildstatus:
951+
buildstatus: &schema_status
925952
nullable: true # should only be null if finished is false
926953
description: |
927954
Indicates the build status:</br>
928955
<ul>
929956
<li>0 : succeeded</li>
930957
<li>1 : failed</li>
931-
<li>2 : dependency failed</li>
958+
<li>2 : dependency failed (builds only)</li>
932959
<li>3 : aborted</li>
933960
<li>4 : canceled by the user</li>
934-
<li>6 : failed with output</li>
961+
<li>6 : failed with output (builds only)</li>
935962
<li>7 : timed out</li>
963+
<li>8 : cached failure (steps only)</li>
936964
<li>9 : aborted</li>
937965
<li>10 : log size limit exceeded</li>
938966
<li>11 : output size limit exceeded</li>
967+
<li>12 : not deterministic</li>
939968
<li>* : failed</li>
940969
</ul>
941970
<strong>Note:</strong>buildstatus should only be `null` if `finished` is false.
942971
type: integer
943-
jobset:
972+
jobset: &schema_jobset
944973
description: jobset this build belongs to
945974
type: string
946975
priority:
947976
description: determines the priority with which this build will be executed (higher value means higher priority)
948977
type: integer
949-
job:
978+
job: &schema_job
950979
description: nix attribute from the nixexprpath
951980
type: string
952-
drvpath:
981+
drvpath: &schema_drvpath
953982
description: filename of the drv
954983
type: string
955-
system:
984+
system: &schema_system
956985
description: system this build was done for
957986
type: string
958-
project:
987+
project: &schema_project
959988
description: project this build belongs to
960989
type: string
961990
buildproducts:
@@ -986,6 +1015,99 @@ components:
9861015
unit:
9871016
type: string
9881017
description: unit of the measured build metric
1018+
BuildInfo:
1019+
properties:
1020+
id:
1021+
description: The build id.
1022+
type: integer
1023+
buildId:
1024+
description: Same as id, exists for backwards compatibility.
1025+
type: integer
1026+
finished:
1027+
<<: *schema_finished
1028+
steps:
1029+
description: List of steps that make up this build.
1030+
type: array
1031+
items:
1032+
type: object
1033+
additionalProperties:
1034+
$ref: '#/components/schemas/BuildStep'
1035+
job:
1036+
<<: *schema_job
1037+
system:
1038+
<<: *schema_system
1039+
buildstatus:
1040+
<<: *schema_status
1041+
jobset:
1042+
<<: *schema_jobset
1043+
project:
1044+
<<: *schema_project
1045+
timestamp:
1046+
<<: *schema_timestamp
1047+
nixname:
1048+
<<: *schema_nixname
1049+
drvPath:
1050+
description: Same as drvpath, exists for backwards compatibility.
1051+
type: string
1052+
outPath:
1053+
description: The nix store path for the output of this build.
1054+
type: string
1055+
1056+
BuildStep:
1057+
type: object
1058+
properties:
1059+
stepnr:
1060+
description: The step number, this number can be used when retrieving logs for a particular step.
1061+
type: integer
1062+
starttime:
1063+
<<: *schema_starttime
1064+
stoptime:
1065+
<<: *schema_stoptime
1066+
status:
1067+
<<: *schema_status
1068+
system:
1069+
<<: *schema_system
1070+
propagatedfrom:
1071+
description: Null if the result was not propagated.
1072+
nullable: true
1073+
type: object
1074+
additionalProperties:
1075+
$ref: '#/components/schemas/Build'
1076+
errormsg:
1077+
<<: *schema_errormsg
1078+
haserrormsg:
1079+
<<: *schema_haserrormsg
1080+
machine:
1081+
description: Machine on which this step was executed.
1082+
type: string
1083+
busy:
1084+
description: |
1085+
Indicates the current stage this build step is in:</br>
1086+
<ul>
1087+
<li>0 : not being worked on (status populated)</li>
1088+
<li>1 : preparing</li>
1089+
<li>10 : connecting</li>
1090+
<li>20 : sending inputs</li>
1091+
<li>30 : building</li>
1092+
<li>40 : receiving outputs</li>
1093+
<li>50 : post processing</li>
1094+
<li>* : unknown</li>
1095+
</ul>
1096+
type: integer
1097+
drvpath:
1098+
<<: *schema_drvpath
1099+
build:
1100+
description: Id of the build this step is a part of.
1101+
type: integer
1102+
timesbuilt:
1103+
nullable: true
1104+
type: integer
1105+
type:
1106+
nullable: true
1107+
overhead:
1108+
nullable: true
1109+
isnondeterministic:
1110+
nullable: true
9891111

9901112
examples:
9911113
projects-success:
@@ -1110,3 +1232,62 @@ components:
11101232
project: example-hello
11111233
starttime: 1588365711
11121234
timestamp: 1588365711
1235+
1236+
build-get-info-success:
1237+
value:
1238+
id: 5
1239+
buildstatus: 2 # actually a failed build, to show the propagated error.
1240+
nixname: hello-2.10
1241+
finished: 1
1242+
timestamp: 1588365711
1243+
system: x86_64-linux
1244+
job: hello
1245+
jobset: hello
1246+
project: example-hello
1247+
steps:
1248+
-
1249+
timesbuilt: null
1250+
errormsg: null
1251+
haserrormsg: false
1252+
overhead: null
1253+
type: 0
1254+
drvpath: /nix/store/ab9zv2y5gm8hr6g318p0s6kaclwj4slr-hello-2.10.drv
1255+
build: 1
1256+
machine: localhost
1257+
busy: 1
1258+
status: 4
1259+
isnondeterministic: null
1260+
starttime: 1649950241
1261+
propagatedfrom: null
1262+
system: x86_64-linux
1263+
stepnr: 1
1264+
stoptime: 1649950294
1265+
-
1266+
timesbuilt: null
1267+
errormsg: null
1268+
haserrormsg: false
1269+
overhead: null
1270+
type: 0
1271+
drvpath: /nix/store/hhl1dql437h1glbqv43629f1pmnlcfoo-package.drv
1272+
build: 1
1273+
machine: localhost
1274+
busy: 0
1275+
status: 8 # Cached failure, will have propagated result.
1276+
isnondeterministic: null
1277+
starttime: 1649950241
1278+
propagatedfrom:
1279+
jobset: hello
1280+
nixname: hello
1281+
system: x86_64-linux
1282+
job: sdk.x86_64-linux
1283+
project: hello
1284+
id: 3 # since this is a build, this denotes the build id the propagation result came from.
1285+
timestamp: 1649456722
1286+
finished: 1
1287+
1288+
system: x86_64-linux
1289+
stepnr: 2
1290+
stoptime: 1649950294
1291+
buildId: 5
1292+
drvPath: /nix/store/ab9zv2y5gm8hr6g318p0s6kaclwj4slr-hello-2.10.drv
1293+
outPath: /nix/store/y26qxcq1gg2hrqpxdc58b2fghv2bhxjg-hello-2.10

src/lib/Hydra/Controller/API.pm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ sub buildToHash {
3030
system => $build->system,
3131
nixname => $build->nixname,
3232
finished => $build->finished,
33-
timestamp => $build->timestamp
33+
timestamp => $build->timestamp,
34+
buildstatus => undef,
35+
priority => undef
3436
};
3537

3638
if($build->finished) {

src/lib/Hydra/Controller/Build.pm

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use warnings;
66
use base 'Hydra::Base::Controller::NixChannel';
77
use Hydra::Helper::Nix;
88
use Hydra::Helper::CatalystUtils;
9+
use Hydra::Controller::API;
910
use File::Basename;
1011
use File::stat;
1112
use Data::Dump qw(dump);
@@ -569,13 +570,52 @@ sub bump : Chained('buildChain') PathPart('bump') {
569570
}
570571

571572

573+
sub buildStepToHash {
574+
my ($buildstep) = @_;
575+
return {
576+
build => $buildstep->get_column('build'),
577+
busy => $buildstep->busy,
578+
drvpath => $buildstep->drvpath,
579+
errormsg => $buildstep->errormsg,
580+
isnondeterministic => $buildstep->isnondeterministic,
581+
machine => $buildstep->machine,
582+
overhead => $buildstep->overhead,
583+
# The propagated from field will hold a Build type if it was propagated, we'd like to display that info, so we
584+
# convert the that record to a hash here and inline it, we already have the data on hand and it saves clients a
585+
# request to obtain the actual reason why something happened.
586+
propagatedfrom => defined($buildstep->propagatedfrom) ? Hydra::Controller::API::buildToHash($buildstep->propagatedfrom) : undef,
587+
starttime => $buildstep->starttime,
588+
status => $buildstep->status,
589+
stepnr => $buildstep->stepnr,
590+
stoptime => $buildstep->stoptime,
591+
system => $buildstep->system,
592+
timesbuilt => $buildstep->timesbuilt,
593+
type => $buildstep->type,
594+
haserrormsg => defined($buildstep->errormsg) && $buildstep->errormsg ne "" ? JSON::MaybeXS::true : JSON::MaybeXS::false
595+
};
596+
}
597+
598+
572599
sub get_info : Chained('buildChain') PathPart('api/get-info') Args(0) {
573600
my ($self, $c) = @_;
574601
my $build = $c->stash->{build};
602+
603+
# Since this is the detailed info of the build, lets start with populating it with
604+
# the info we can obtain form the build.
605+
$c->stash->{json} = Hydra::Controller::API::buildToHash($build);
606+
607+
# Provide the original get-info endpoint attributes.
575608
$c->stash->{json}->{buildId} = $build->id;
576609
$c->stash->{json}->{drvPath} = $build->drvpath;
577610
my $out = getMainOutput($build);
578611
$c->stash->{json}->{outPath} = $out->path if defined $out;
612+
613+
# Finally, provide information about all the buildsteps that made up this build.
614+
my @buildsteps = $build->buildsteps->search({}, {order_by => "stepnr asc"});
615+
my @buildsteplist;
616+
push @buildsteplist, buildStepToHash($_) foreach @buildsteps;
617+
$c->stash->{json}->{steps} = \@buildsteplist;
618+
579619
$c->forward('View::JSON');
580620
}
581621

0 commit comments

Comments
 (0)