Skip to content

Commit

Permalink
www: Make step lock duration formatting consistent with builds
Browse files Browse the repository at this point in the history
  • Loading branch information
p12tic committed Dec 31, 2023
1 parent 5eafd95 commit 0ca3d99
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 36 deletions.
30 changes: 2 additions & 28 deletions www/react-base/src/components/BuildSummary/BuildSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
ConfigContext,
analyzeStepUrls,
buildDurationFormatWithLocks,
durationFormat,
stepDurationFormatWithLocks,
useCurrentTime,
useStateWithParentTrackingWithDefaultIfNotSet,
useStepUrlAnalyzer
Expand Down Expand Up @@ -104,32 +104,6 @@ type BuildSummaryStepLineProps = {
parentFullDisplay: boolean
}

function getTimeTextForStep(step: Step, now: number) {
const lockDuration = step.locks_acquired_at !== null
? step.locks_acquired_at - step.started_at!
: 0;

if (step.complete) {
const stepDurationText = durationFormat(step.complete_at! - step.started_at!);

if (lockDuration > 1) {
// Since lock delay includes general step setup overhead, then sometimes the started_at and locks_acquired_at
// may fall into different seconds. However, it's unlikely that step setup would take more than one second.
return `${stepDurationText} (${durationFormat(lockDuration)} spent waiting for locks)`
}
return stepDurationText;
}

const ongoingStepDurationText = durationFormat(now - step.started_at!);
if (lockDuration > 1) {
// Since lock delay includes general step setup overhead, then sometimes the started_at and locks_acquired_at
// may fall into different seconds. However, it's unlikely that step setup would take more than one second.
return `${ongoingStepDurationText} (${durationFormat(lockDuration)} spent waiting for locks)`
}

return ongoingStepDurationText;
}

const BuildSummaryStepLine = observer(({build, step, logs, parentFullDisplay}: BuildSummaryStepLineProps) => {
const config = useContext(ConfigContext);
const now = useCurrentTime();
Expand All @@ -150,7 +124,7 @@ const BuildSummaryStepLine = observer(({build, step, logs, parentFullDisplay}: B

return (
<span className="bb-build-summary-time">
{getTimeTextForStep(step, now)}
{stepDurationFormatWithLocks(step, now)}
&nbsp;
{step.state_string}
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import {
results2text
} from "buildbot-data-js";
import {ConfigContext} from "../../contexts/Config";
import {buildDurationFormatWithLocks} from "../../util/DataUtils";
import {durationFormat, useCurrentTime} from "../../util/Moment";
import {buildDurationFormatWithLocks, stepDurationFormatWithLocks} from "../../util/DataUtils";
import {useCurrentTime} from "../../util/Moment";
import {analyzeStepUrls, useStepUrlAnalyzer} from "../../util/StepUrls";
import {BadgeRound} from "../BadgeRound/BadgeRound";
import {BadgeStatus} from "../BadgeStatus/BadgeStatus";
Expand Down Expand Up @@ -125,11 +125,7 @@ export const BuildSummaryTooltip = observer(({build}: BuildSummaryTooltipProps)
if (step.started_at !== null) {
stepInfoWhenStarted = (
<span className="bb-buildsummary-tooltip-step-time">
{
step.complete
? <span>{durationFormat(step.complete_at! - step.started_at)}</span>
: <span>{durationFormat(now - step.started_at)}</span>
}
{ stepDurationFormatWithLocks(step, now) }
&nbsp;
{limitStringLength(step.state_string, 40)}
</span>
Expand Down
30 changes: 29 additions & 1 deletion www/react-ui/src/util/DataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Copyright Buildbot Team Members
*/

import {Build, Builder, DataCollection, Master} from "buildbot-data-js";
import {Build, Builder, DataCollection, Master, Step} from "buildbot-data-js";
import {durationFormat} from "./Moment";

export function hasActiveMaster(builder: Builder, masters: DataCollection<Master>) {
Expand Down Expand Up @@ -45,3 +45,31 @@ export function buildDurationFormatWithLocks(build: Build, now: number) {
}
return res;
}

export function stepDurationFormatWithLocks(step: Step, now: number) {
const lockDuration = step.locks_acquired_at !== null
? step.locks_acquired_at - step.started_at!
: 0;

if (step.complete) {
const stepDurationText = durationFormat(step.complete_at! - step.started_at!);

if (lockDuration > 1) {
// Since lock delay includes general step setup overhead, then sometimes the started_at and
// locks_acquired_at may fall into different seconds. However, it's unlikely that step setup
// would take more than one second.
return `${stepDurationText} (locks: ${durationFormat(lockDuration)})`
}
return stepDurationText;
}

const ongoingStepDurationText = durationFormat(now - step.started_at!);
if (lockDuration > 1) {
// Since lock delay includes general step setup overhead, then sometimes the started_at and
// locks_acquired_at may fall into different seconds. However, it's unlikely that step setup
// would take more than one second.
return `${ongoingStepDurationText} (locks: ${durationFormat(lockDuration)})`
}

return ongoingStepDurationText;
}

0 comments on commit 0ca3d99

Please sign in to comment.