Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor deck to use /prowjobs.js #7301

Closed

Conversation

kpatticha
Copy link
Contributor

@kpatticha kpatticha commented Mar 15, 2018

The PR is mainly refactoring of script.js in order to use /prowjobs.js .

The only addition is the calculation of the job's duration which it is not included in the new response.

Ref #5216

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 15, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: katerinapat
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approver: cjwagner

Assign the PR to them by writing /assign @cjwagner in a comment when ready.

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@stevekuznetsov
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Mar 15, 2018
@stevekuznetsov
Copy link
Contributor

/cc @BenTheElder @qhuynh96

completionMoment = new moment(completionTime),
d = moment.duration(completionMoment.diff(startMoment));

return d.hours() + "h" + d.minutes() + "m" + d.seconds() + "s";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d.format() ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duration object seems not to have format().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, see moment/moment#1048.

This is wrong for jobs that take too long, and it will look weird to have a bunch of 0h jobs.

var out = d.seconds() + 's';    
if (d.asHours() >= 1) 
    out = Math.floor(d.asHours()) + 'h' + d.minutes() + 'm' + out;
else if (d.minutes() >= 1) 
    out = d.minutes() + 'm' + out;
return out;

function createTimeCell(id, time) {
var momentTime = moment.unix(time);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not immediately obvious why this was wrong?

if (!repo || repo === build.spec.refs.repo) {
opts.jobs[build.spec.job] = true;
if (build.spec.type === "presubmit") {
opts.authors[build.spec.refs.pulls[0]['author']] = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to not squash the list of pulls for batches?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any case that build.spec.refs.pulls can be null or undefined?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in periodic and postsubmit jobs there will be no pulls

if (!repo || repo === build.spec.refs.repo) {
opts.jobs[build.spec.job] = true;
if (build.spec.type === "presubmit") {
opts.authors[build.spec.refs.pulls[0]['author']] = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any case that build.spec.refs.pulls can be null or undefined?

build.spec.refs = prop;
}

if (!build.spec.refs.hasOwnProperty("pulls")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any case that build.spec.refs inherit pulls? if not we can change the condition to !build.spec.refs.pulls

]
}

if ( Object.keys(build.spec.refs).length == 0){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be explicitly periodic type job as we expect postsubmit presubmit and batch to have refs; otherwise, revision cells will be filled with broken links.

If postsubmit, presubmit or batch does not have refs, should we consider to drop it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am inclined to say just drop them but if we don't do that today I don't consider it important fixing here.

@0xmichalis
Copy link
Contributor

Looks OK overall to me. There have been some concerns raised by @rmmh and @BenTheElder in the past wrt the size of prowjobs.js. Maybe we can pass a url parameter that would drop pod specs from the response?

@0xmichalis
Copy link
Contributor

Looks OK overall to me. There have been some concerns raised by @rmmh and @BenTheElder in the past wrt the size of prowjobs.js. Maybe we can pass a url parameter that would drop pod specs from the response?

Opened #7386

opts.authors[build.author] = true;
opts.pulls[build.number] = true;
opts.states[build.state] = true;
for (var i = 0; i < allBuilds.items.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're using ES6 now: for (const build of allBuilds.items) {

opts.pulls[build.number] = true;
opts.states[build.state] = true;
for (var i = 0; i < allBuilds.items.length; i++) {
var build = allBuilds.items[i];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const spec = build.spec;, to make the rest shorter?

opts.jobs[build.spec.job] = true;
if (build.spec.type === "presubmit") {
opts.authors[build.spec.refs.pulls[0]['author']] = true;
opts.pulls[build.spec.refs.pulls[0]['number']] = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pulls[0].number

@@ -353,7 +353,11 @@ function equalSelected(sel, t) {
}

function groupKey(build) {
return build.repo + " " + build.number + " " + build.refs;
return build.spec.refs.org + "/" +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't do the right grouping for batch jobs. Try this:

const refs = build.spec.refs;
const pulls = refs.pulls.map(r => r.number + ':' + r.sha).join(',');
return `${refs.repo} ${refs.base_ref}:${refs.base_sha},${pulls}`;

completionMoment = new moment(completionTime),
d = moment.duration(completionMoment.diff(startMoment));

return d.hours() + "h" + d.minutes() + "m" + d.seconds() + "s";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, see moment/moment#1048.

This is wrong for jobs that take too long, and it will look weird to have a bunch of 0h jobs.

var out = d.seconds() + 's';    
if (d.asHours() >= 1) 
    out = Math.floor(d.asHours()) + 'h' + d.minutes() + 'm' + out;
else if (d.minutes() >= 1) 
    out = d.minutes() + 'm' + out;
return out;

var build = allBuilds.items[i];

// assign default values
var prop = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would skip this, and instead change the one case that uses build.spec.refs to skip if build.spec.refs is empty.

@@ -26,16 +26,16 @@ function optionsForRepo(repo) {
states: {},
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not do an initialization pass to set build.author and build.number, and avoid the construct of build.spec.refs.pulls[0] elsewhere?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still be done-- getting the hnumber out should be simpler.

@0xmichalis 0xmichalis mentioned this pull request Mar 23, 2018
5 tasks
@kpatticha kpatticha force-pushed the refactor-deck-to-use-prowjob branch from d4d8937 to 5e014da Compare April 15, 2018 11:24
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 15, 2018
@kpatticha kpatticha force-pushed the refactor-deck-to-use-prowjob branch from 5e014da to 9f52ad9 Compare April 15, 2018 11:37
@0xmichalis
Copy link
Contributor

@katerinapat is this ready for another round of reviews?

@stevekuznetsov
Copy link
Contributor

When we get closer to merge, please rebase your branch on top of master instead of merging.

@kpatticha
Copy link
Contributor Author

@Kargakis. I pushed 2 more commits. Added the param omit=pod_spec on the request of prowjobs.js and I dropped the default values. Instead I check the cases that the values could not be set.

I'll refactor the duration so it won't display all these 0h.

Although in this PR I didn't include any other refactoring or changing to ES6. Main goal is to refactor the script to support the new response without brake anything. I'll be more happy to refactor the whole spaghetti code in a future PR

@fejta
Copy link
Contributor

fejta commented Jun 8, 2018

/assign @Kargakis @rmmh
/lifecycle stale

Still working on this one?

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 8, 2018
@fejta
Copy link
Contributor

fejta commented Jun 18, 2018

Please address comments and reopen!
/close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants