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

[WIP] Several Small Fixes #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.TimeZone;

/**
* {@link WorkflowJob} ui extension point {@link Action}.
Expand Down Expand Up @@ -54,4 +56,18 @@ public Collection<? extends Action> createFor(WorkflowJob target) {
return Collections.singleton(new WorkflowStageViewAction(target));
}
}

public String getTimeZone() {
return System.getProperty("user.timezone");
}

// Time zone offset right now in HH:MM format
public String getTimeZoneOffset() {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is used to inject DST-corrected offset for the Jenkins host into the front-end (added in a small script fragment inserted into the placeholder Jelly for stage view).

TimeZone tz = TimeZone.getTimeZone(getTimeZone());
int offsetTotalMin = tz.getOffset(new Date().getTime()) / (1000*60) ;
int absOffsetMin = Math.abs(offsetTotalMin);
int offsetHours = absOffsetMin/60;
int offsetRealMin = absOffsetMin-(offsetHours*60);
return ((offsetTotalMin>0) ? '+' : '-') + offsetHours + ":" + offsetRealMin;
}
}
10 changes: 5 additions & 5 deletions ui/src/main/js/model/runs-stage-grouped.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ function addStageTotals(runGroup) {
var run = runGroup.runs[i];

if (run.stages && (run.status === 'IN_PROGRESS' || run.status === 'PAUSED_PENDING_INPUT')) {
addCompletionEstimates(run, runGroup.avgDurationMillisNoPause, runGroup.runs.length);
addCompletionEstimates(run, runGroup.avgDurationMillisNoPause, endToEndRuns);
Copy link
Member Author

Choose a reason for hiding this comment

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

May avoid factoring incomplete runs into completion estimates. Possible fix for JENKINS-38536

for (var ii = 0; ii < run.stages.length; ii++) {
var stage = run.stages[ii];
var stageData = getStageData(stage.name, runGroup);

if (stage.percentCompleteEstimate === undefined) {
if (stage.status === 'IN_PROGRESS' || stage.status === 'PAUSED_PENDING_INPUT') {
addCompletionEstimates(stage, stageData.avgDurationMillisNoPause, runGroup.runs.length);
addCompletionEstimates(stage, stageData.avgDurationMillisNoPause, endToEndRuns);
}
}
}
Expand Down Expand Up @@ -225,7 +225,7 @@ function addEndTimes(jobRunsData) {
time.setEndTime(run);
if (run.stages) {
for (var ii = 0; ii < run.stages.length; ii++) {
time.setEndTime(run.stages[ii]);
time.setEndTime(run.stages[ii]);
}
}
}
Expand All @@ -238,8 +238,8 @@ function addEndTimes(jobRunsData) {
* (i.e. a run, a runGroup or a stage).
*/
function addCompletionEstimates(timedObject, avgDurationMillis, averagedOver) {
if (averagedOver === 0) {
// If no runs have completed yet, then we can't make an estimate, so just mark it at 50%.
if (averagedOver === 0 || !(avgDurationMillis > 0)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Duration > 0 covers NaN and undefined + other weird cases.

// If no runs have completed yet, then we can't make an estimate, so just mark it undefined
timedObject.percentCompleteEstimate = 50;
} else {
timedObject.percentCompleteEstimate = (timedObject.durationMillisNoPause / avgDurationMillis * 100);
Expand Down
8 changes: 8 additions & 0 deletions ui/src/main/js/view/templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ var jqProxy = require('../../jQuery');
var formatters = require('../../util/formatters');
var moment = require('moment');

// Fix date formatting - set moment locale to UTC to match normal display
// Needs to get the Jenkins locale here, probably from jelly
// Moment._locale

/**
* Templating support.
*/
Expand Down Expand Up @@ -87,6 +91,10 @@ registerHBSHelper('formatDate', function (date, toFormat) {
return date;
}

if (myTimeZoneOffset) { // Do time zone conversion using parseData *sigh.*
//moment.locale(myTimeZone);
Copy link
Member Author

Choose a reason for hiding this comment

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

Here's where we'd inject custom formatting using Jenkins host timeZoneOffset.

Copy link
Member Author

@svanoort svanoort Sep 29, 2016

Choose a reason for hiding this comment

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

Moment.js does have time zone offset options, though they require offset in a particular format and are a little finnicky on parsing.

}

var aliasFormat = formatAliases[toFormat];
if (aliasFormat) {
return moment(date).format(aliasFormat);
Expand Down
8 changes: 5 additions & 3 deletions ui/src/main/js/view/templates/pipeline-staged.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@
<tr class="totals">
<td class="stage-start"><div class="cell-color">
Average stage times:<br />
{{#if avgDurationMillisNoPause}}
{{#ifCond avgDurationMillisNoPause '>' 0 }}
Copy link
Member Author

Choose a reason for hiding this comment

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

Covers NaN, undefined, etc.

(Average <span style="text-decoration: underline;" title="builds that run all stages">full</span> run time: ~{{formatTime avgDurationMillisNoPause 2}})
{{else}}
&nbsp;
{{/if}}
{{/ifCond}}
</div></td>
{{#each stageData}}
<td class="stage-total-{{@index}}">
<div class="cell-color">
<div class="duration">{{formatTime avgDurationMillisNoPause 2}}</div>
{{#ifCond avgDurationMillisNoPause '>' 0}}
<div class="duration">{{formatTime avgDurationMillisNoPause 2}}</div>
{{/ifCond}}
<div class="stackedBarChart"></div>
</div>
</td>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:fmt="jelly:fmt" xmlns:t="/lib/hudson">
<st:documentation>
<st:attribute name="name" use="required">
The name of Pipeline controller to use for rendering.
Expand All @@ -9,6 +9,9 @@
Optional fragment caption, passed through to the controller.
</st:attribute>
</st:documentation>
<script>var myTimeZone = '${it.timeZone}'; var myTimeZoneOfset = '${it.timeZoneOffset}';</script>
<!--${System.getProperty('user.timezone')}
${new String('goober')}-->
<div class="cbwf-stage-view">
<div cbwf-controller="${name}" objectUrl="${rootURL}/${it.target.url}" fragCaption="${fragCaption}" />
<st:adjunct includes="org.jenkinsci.pipeline.stageview_adjunct"/>
Expand Down