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

parse full duration for time formatting #1520

Merged
merged 1 commit into from
Mar 15, 2022

Conversation

jbpratt
Copy link
Contributor

@jbpratt jbpratt commented Mar 4, 2022

Changes

Use native .String() impl for time.Duration

fixes #1495

Signed-off-by: jbpratt jbpratt78@gmail.com

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes tests (if functionality changed/added)
  • Run the code checkers with make check
  • Regenerate the manpages, docs and go formatting with make generated
  • Commit messages follow commit message best practices

See the contribution guide
for more details.

Release Notes

Print more accurate duration

@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Mar 4, 2022
@tekton-robot tekton-robot requested review from hrishin and sthaha March 4, 2022 15:54
@tekton-robot
Copy link
Contributor

Hi @jbpratt. Thanks for your PR.

I'm waiting for a tektoncd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tekton-robot tekton-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 4, 2022
@jbpratt
Copy link
Contributor Author

jbpratt commented Mar 4, 2022

Hi, this may not be the desired result for describing the duration, if so we can close this and close up #1495 as won't fix 😺

@jbpratt
Copy link
Contributor Author

jbpratt commented Mar 4, 2022

I think the output in question (in the issue) comes from here

{{decorate "taskruns" ""}}{{decorate "underline bold" "Taskruns\n"}}
NAME TASK NAME STARTED DURATION STATUS
{{- range $taskrun := .TaskrunList }}{{ if checkTRStatus $taskrun }}
{{decorate "bullet" $taskrun.TaskrunName }} {{ $taskrun.PipelineTaskName }} {{ formatAge $taskrun.Status.StartTime $.Params.Time }} {{ formatDuration $taskrun.Status.StartTime $taskrun.Status.CompletionTime }} {{ formatCondition $taskrun.Status.Conditions }}
{{- end }}
{{- end }}
{{- end }}
which uses this function
"formatDuration": formatted.Duration,
leading to this
func Duration(t1, t2 *metav1.Time) string {
if t1.IsZero() || t2.IsZero() {
return "---"
}
dur := t2.Time.Sub(t1.Time)
return durafmt.ParseShort(dur).String()
}
Changing ParseShort to Parse results in the seemingly desired output.

@jbpratt
Copy link
Contributor Author

jbpratt commented Mar 5, 2022

Adding some output examples:

❯ tkn taskrun list
NAME                                                            STARTED      DURATION     STATUS
zzzzz-6xz4m                                                     1 hour ago   1 hour       Succeeded
...

❯ ./bin/tkn taskrun list
NAME                                                            STARTED      DURATION                      STATUS
zzzzz-6xz4m                                                     1 hour ago   1 hour 30 minutes 6 seconds   Succeeded
...

❯ tkn taskrun describe zzzzz-6xz4m
...
STARTED      DURATION    STATUS
1 hour ago   1 hour      Succeeded
...

❯ ./bin/tkn taskrun describe zzzzz-6xz4m
...
STARTED      DURATION                      STATUS
1 hour ago   1 hour 30 minutes 6 seconds   Succeeded

which I think is closer to what is shown in the dashboard
2022-03-04_18-41

@pradeepitm12
Copy link
Contributor

/ok-to-test

@tekton-robot tekton-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 8, 2022
@tekton-robot
Copy link
Contributor

The following is the coverage report on the affected files.
Say /test pull-tekton-cli-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/formatted/time.go 27.3% 63.6% 36.4

@jbpratt
Copy link
Contributor Author

jbpratt commented Mar 8, 2022

/test pull-tekton-cli-unit-tests

@piyush-garg
Copy link
Contributor

Instead of having this long text 1 hour 30 minutes 6 seconds, I think we can have something like 1h30m6s

@jbpratt
Copy link
Contributor Author

jbpratt commented Mar 8, 2022

Instead of having this long text 1 hour 30 minutes 6 seconds, I think we can have something like 1h30m6s

Sure, I'll need to figure that out because the library used doesn't support that https://github.com/hako/durafmt (maybe a custom format, or this just works with native time/duration). Any suggestions are welcome :)

@jbpratt jbpratt force-pushed the parse-duration-proper branch from 6f6dce5 to 493fbb7 Compare March 8, 2022 11:26
@jbpratt
Copy link
Contributor Author

jbpratt commented Mar 8, 2022

@piyush-garg PTAL, I've updated to use the native .String impl for time.Duration but days are represented differently.

❯ ./bin/tkn taskrun describe zzzzz-6xz4m
Name:              zzzzz-6xz4m
Namespace:         default
Service Account:   default
Timeout:           2h0m0s
Labels:
 app.kubernetes.io/managed-by=tekton-pipelines

🌡️  Status

STARTED      DURATION    STATUS
3 days ago   1h30m6s     Succeeded

🦶 Steps

 NAME                STATUS
 ∙ sleep-long-time   Completed

@tekton-robot
Copy link
Contributor

The following is the coverage report on the affected files.
Say /test pull-tekton-cli-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/formatted/time.go 27.3% 63.6% 36.4

Use native `time.Duration.String()` format

fixes tektoncd#1495

Signed-off-by: jbpratt <jbpratt78@gmail.com>
@jbpratt jbpratt force-pushed the parse-duration-proper branch from 493fbb7 to a79baae Compare March 8, 2022 11:36
@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 8, 2022
@jbpratt
Copy link
Contributor Author

jbpratt commented Mar 8, 2022

Again, if this isn't desired we can close this out and leave an explanation on the ticket (#1495)

@tekton-robot
Copy link
Contributor

The following is the coverage report on the affected files.
Say /test pull-tekton-cli-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/formatted/time.go 27.3% 63.6% 36.4

@jbpratt
Copy link
Contributor Author

jbpratt commented Mar 14, 2022

Hi @pradeepitm12 @piyush-garg @vdemeester please take a look

@piyush-garg
Copy link
Contributor

/lgtm
/cc @vdemeester @pradeepitm12 @chmouel for opinions/reviews

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 15, 2022
@tekton-robot tekton-robot requested a review from chmouel March 15, 2022 10:30
@tekton-robot
Copy link
Contributor

@piyush-garg: GitHub didn't allow me to request PR reviews from the following users: for, opinions/reviews.

Note that only tektoncd members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/lgtm
/cc @vdemeester @pradeepitm12 @chmouel for opinions/reviews

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@pradeepitm12
Copy link
Contributor

/lgtm

Copy link
Member

@chmouel chmouel left a comment

Choose a reason for hiding this comment

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

This looks way much better to me, those "human duration" always bugged me. Feel free to clean this go.mod entry then and that should probably good to go.

pkg/formatted/time.go Show resolved Hide resolved
@chmouel
Copy link
Member

chmouel commented Mar 15, 2022

/lgtm
/approve

@tekton-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chmouel

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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 15, 2022
@tekton-robot tekton-robot merged commit df0da5d into tektoncd:main Mar 15, 2022
@jbpratt jbpratt deleted the parse-duration-proper branch March 15, 2022 16:42
pradeepitm12 added a commit that referenced this pull request Mar 24, 2022
#1525 | [Piyush Garg] Update docs to latest version 0.23.0 | 2022/03/09-17:25
#1528 | [Chmouel Boudjnah] generate universal binaries for osx | 2022/03/11-10:28
#1529 | [PuneetPunamiya] Adds namespace where operator is installed | 2022/03/11-14:06
#1530 | [Chmouel Boudjnah] Remove go11modules export instructions in README | 2022/03/14-15:49
#1526 | [Chmouel Boudjnah] Add information about arch package | 2022/03/14-16:17
#1523 | [Vincent Demeester] ROADMAP.md: update it to reflect 2022 goals | 2022/03/15-11:18
#1467 | [mathew-fleisch] Go compile darwin-arm64 in makefile for m1 macs | 2022/03/15-13:04
#1520 | [jbpratt] parse full duration for time formatting | 2022/03/15-16:12
#1531 | [Chmouel Boudjnah] Add "tkn taskrun export" | 2022/03/18-09:46
#1538 | [Chmouel Boudjnah] update to cobra 1.4.0 | 2022/03/18-11:42
null | [PuneetPunamiya] Updates the configMap name for Operator version | 2022/03/18-13:01
null | [Chmouel Boudjnah] Add -o name to pipeline start | 2022/03/22-11:32
null | [Piyush Garg] This will fix the version command failing for chain and operator | 2022/03/23-12:16
null | [Pradeep Kumar] fix error while deleting pr without status | 2022/03/24-07:16

Signed-off-by: Pradeep Kumar <pradkuma@redhat.com>
pradeepitm12 added a commit that referenced this pull request Mar 24, 2022
#1525 | [Piyush Garg] Update docs to latest version 0.23.0 | 2022/03/09-17:25
#1528 | [Chmouel Boudjnah] generate universal binaries for osx | 2022/03/11-10:28
#1529 | [PuneetPunamiya] Adds namespace where operator is installed | 2022/03/11-14:06
#1530 | [Chmouel Boudjnah] Remove go11modules export instructions in README | 2022/03/14-15:49
#1526 | [Chmouel Boudjnah] Add information about arch package | 2022/03/14-16:17
#1523 | [Vincent Demeester] ROADMAP.md: update it to reflect 2022 goals | 2022/03/15-11:18
#1467 | [mathew-fleisch] Go compile darwin-arm64 in makefile for m1 macs | 2022/03/15-13:04
#1520 | [jbpratt] parse full duration for time formatting | 2022/03/15-16:12
#1531 | [Chmouel Boudjnah] Add "tkn taskrun export" | 2022/03/18-09:46
#1538 | [Chmouel Boudjnah] update to cobra 1.4.0 | 2022/03/18-11:42
null | [PuneetPunamiya] Updates the configMap name for Operator version | 2022/03/18-13:01
null | [Chmouel Boudjnah] Add -o name to pipeline start | 2022/03/22-11:32
null | [Piyush Garg] This will fix the version command failing for chain and operator | 2022/03/23-12:16
null | [Pradeep Kumar] fix error while deleting pr without status | 2022/03/24-07:16

Signed-off-by: Pradeep Kumar <pradkuma@redhat.com>
pradeepitm12 added a commit that referenced this pull request Mar 24, 2022
#1525 | [Piyush Garg] Update docs to latest version 0.23.0 | 2022/03/09-17:25
#1528 | [Chmouel Boudjnah] generate universal binaries for osx | 2022/03/11-10:28
#1529 | [PuneetPunamiya] Adds namespace where operator is installed | 2022/03/11-14:06
#1530 | [Chmouel Boudjnah] Remove go11modules export instructions in README | 2022/03/14-15:49
#1526 | [Chmouel Boudjnah] Add information about arch package | 2022/03/14-16:17
#1523 | [Vincent Demeester] ROADMAP.md: update it to reflect 2022 goals | 2022/03/15-11:18
#1467 | [mathew-fleisch] Go compile darwin-arm64 in makefile for m1 macs | 2022/03/15-13:04
#1520 | [jbpratt] parse full duration for time formatting | 2022/03/15-16:12
#1531 | [Chmouel Boudjnah] Add "tkn taskrun export" | 2022/03/18-09:46
#1538 | [Chmouel Boudjnah] update to cobra 1.4.0 | 2022/03/18-11:42
null | [PuneetPunamiya] Updates the configMap name for Operator version | 2022/03/18-13:01
null | [Chmouel Boudjnah] Add -o name to pipeline start | 2022/03/22-11:32
null | [Piyush Garg] This will fix the version command failing for chain and operator | 2022/03/23-12:16
null | [Pradeep Kumar] fix error while deleting pr without status | 2022/03/24-07:16

Signed-off-by: Pradeep Kumar <pradkuma@redhat.com>
pradeepitm12 added a commit that referenced this pull request Mar 24, 2022
#1525 | [Piyush Garg] Update docs to latest version 0.23.0 | 2022/03/09-17:25
#1528 | [Chmouel Boudjnah] generate universal binaries for osx | 2022/03/11-10:28
#1529 | [PuneetPunamiya] Adds namespace where operator is installed | 2022/03/11-14:06
#1530 | [Chmouel Boudjnah] Remove go11modules export instructions in README | 2022/03/14-15:49
#1526 | [Chmouel Boudjnah] Add information about arch package | 2022/03/14-16:17
#1523 | [Vincent Demeester] ROADMAP.md: update it to reflect 2022 goals | 2022/03/15-11:18
#1467 | [mathew-fleisch] Go compile darwin-arm64 in makefile for m1 macs | 2022/03/15-13:04
#1520 | [jbpratt] parse full duration for time formatting | 2022/03/15-16:12
#1531 | [Chmouel Boudjnah] Add "tkn taskrun export" | 2022/03/18-09:46
#1538 | [Chmouel Boudjnah] update to cobra 1.4.0 | 2022/03/18-11:42
null | [PuneetPunamiya] Updates the configMap name for Operator version | 2022/03/18-13:01
null | [Chmouel Boudjnah] Add -o name to pipeline start | 2022/03/22-11:32
null | [Piyush Garg] This will fix the version command failing for chain and operator | 2022/03/23-12:16
null | [Pradeep Kumar] fix error while deleting pr without status | 2022/03/24-07:16

Signed-off-by: Pradeep Kumar <pradkuma@redhat.com>
pradeepitm12 added a commit that referenced this pull request Mar 25, 2022
#1525 | [Piyush Garg] Update docs to latest version 0.23.0 | 2022/03/09-17:25
#1528 | [Chmouel Boudjnah] generate universal binaries for osx | 2022/03/11-10:28
#1529 | [PuneetPunamiya] Adds namespace where operator is installed | 2022/03/11-14:06
#1530 | [Chmouel Boudjnah] Remove go11modules export instructions in README | 2022/03/14-15:49
#1526 | [Chmouel Boudjnah] Add information about arch package | 2022/03/14-16:17
#1523 | [Vincent Demeester] ROADMAP.md: update it to reflect 2022 goals | 2022/03/15-11:18
#1467 | [mathew-fleisch] Go compile darwin-arm64 in makefile for m1 macs | 2022/03/15-13:04
#1520 | [jbpratt] parse full duration for time formatting | 2022/03/15-16:12
#1531 | [Chmouel Boudjnah] Add "tkn taskrun export" | 2022/03/18-09:46
#1538 | [Chmouel Boudjnah] update to cobra 1.4.0 | 2022/03/18-11:42
null | [PuneetPunamiya] Updates the configMap name for Operator version | 2022/03/18-13:01
null | [Chmouel Boudjnah] Add -o name to pipeline start | 2022/03/22-11:32
null | [Piyush Garg] This will fix the version command failing for chain and operator | 2022/03/23-12:16
null | [Pradeep Kumar] fix error while deleting pr without status | 2022/03/24-07:16

Signed-off-by: Pradeep Kumar <pradkuma@redhat.com>
pradeepitm12 added a commit that referenced this pull request Mar 25, 2022
#1525 | [Piyush Garg] Update docs to latest version 0.23.0 | 2022/03/09-17:25
#1528 | [Chmouel Boudjnah] generate universal binaries for osx | 2022/03/11-10:28
#1529 | [PuneetPunamiya] Adds namespace where operator is installed | 2022/03/11-14:06
#1530 | [Chmouel Boudjnah] Remove go11modules export instructions in README | 2022/03/14-15:49
#1526 | [Chmouel Boudjnah] Add information about arch package | 2022/03/14-16:17
#1523 | [Vincent Demeester] ROADMAP.md: update it to reflect 2022 goals | 2022/03/15-11:18
#1467 | [mathew-fleisch] Go compile darwin-arm64 in makefile for m1 macs | 2022/03/15-13:04
#1520 | [jbpratt] parse full duration for time formatting | 2022/03/15-16:12
#1531 | [Chmouel Boudjnah] Add "tkn taskrun export" | 2022/03/18-09:46
#1538 | [Chmouel Boudjnah] update to cobra 1.4.0 | 2022/03/18-11:42
null | [PuneetPunamiya] Updates the configMap name for Operator version | 2022/03/18-13:01
null | [Chmouel Boudjnah] Add -o name to pipeline start | 2022/03/22-11:32
null | [Piyush Garg] This will fix the version command failing for chain and operator | 2022/03/23-12:16
null | [Pradeep Kumar] fix error while deleting pr without status | 2022/03/24-07:16

Signed-off-by: Pradeep Kumar <pradkuma@redhat.com>
pradeepitm12 added a commit that referenced this pull request Mar 25, 2022
#1525 | [Piyush Garg] Update docs to latest version 0.23.0 | 2022/03/09-17:25
#1528 | [Chmouel Boudjnah] generate universal binaries for osx | 2022/03/11-10:28
#1529 | [PuneetPunamiya] Adds namespace where operator is installed | 2022/03/11-14:06
#1530 | [Chmouel Boudjnah] Remove go11modules export instructions in README | 2022/03/14-15:49
#1526 | [Chmouel Boudjnah] Add information about arch package | 2022/03/14-16:17
#1523 | [Vincent Demeester] ROADMAP.md: update it to reflect 2022 goals | 2022/03/15-11:18
#1467 | [mathew-fleisch] Go compile darwin-arm64 in makefile for m1 macs | 2022/03/15-13:04
#1520 | [jbpratt] parse full duration for time formatting | 2022/03/15-16:12
#1531 | [Chmouel Boudjnah] Add "tkn taskrun export" | 2022/03/18-09:46
#1538 | [Chmouel Boudjnah] update to cobra 1.4.0 | 2022/03/18-11:42
null | [PuneetPunamiya] Updates the configMap name for Operator version | 2022/03/18-13:01
null | [Chmouel Boudjnah] Add -o name to pipeline start | 2022/03/22-11:32
null | [Piyush Garg] This will fix the version command failing for chain and operator | 2022/03/23-12:16
null | [Pradeep Kumar] fix error while deleting pr without status | 2022/03/24-07:16

Signed-off-by: Pradeep Kumar <pradkuma@redhat.com>
pradeepitm12 added a commit that referenced this pull request Mar 25, 2022
#1525 | [Piyush Garg] Update docs to latest version 0.23.0 | 2022/03/09-17:25
#1528 | [Chmouel Boudjnah] generate universal binaries for osx | 2022/03/11-10:28
#1529 | [PuneetPunamiya] Adds namespace where operator is installed | 2022/03/11-14:06
#1530 | [Chmouel Boudjnah] Remove go11modules export instructions in README | 2022/03/14-15:49
#1526 | [Chmouel Boudjnah] Add information about arch package | 2022/03/14-16:17
#1523 | [Vincent Demeester] ROADMAP.md: update it to reflect 2022 goals | 2022/03/15-11:18
#1467 | [mathew-fleisch] Go compile darwin-arm64 in makefile for m1 macs | 2022/03/15-13:04
#1520 | [jbpratt] parse full duration for time formatting | 2022/03/15-16:12
#1531 | [Chmouel Boudjnah] Add "tkn taskrun export" | 2022/03/18-09:46
#1538 | [Chmouel Boudjnah] update to cobra 1.4.0 | 2022/03/18-11:42
null | [PuneetPunamiya] Updates the configMap name for Operator version | 2022/03/18-13:01
null | [Chmouel Boudjnah] Add -o name to pipeline start | 2022/03/22-11:32
null | [Piyush Garg] This will fix the version command failing for chain and operator | 2022/03/23-12:16
null | [Pradeep Kumar] fix error while deleting pr without status | 2022/03/24-07:16

Signed-off-by: Pradeep Kumar <pradkuma@redhat.com>
piyush-garg added a commit that referenced this pull request Mar 25, 2022
#1525 | [Piyush Garg] Update docs to latest version 0.23.0 | 2022/03/09-17:25
#1528 | [Chmouel Boudjnah] generate universal binaries for osx | 2022/03/11-10:28
#1529 | [PuneetPunamiya] Adds namespace where operator is installed | 2022/03/11-14:06
#1530 | [Chmouel Boudjnah] Remove go11modules export instructions in README | 2022/03/14-15:49
#1526 | [Chmouel Boudjnah] Add information about arch package | 2022/03/14-16:17
#1523 | [Vincent Demeester] ROADMAP.md: update it to reflect 2022 goals | 2022/03/15-11:18
#1467 | [mathew-fleisch] Go compile darwin-arm64 in makefile for m1 macs | 2022/03/15-13:04
#1520 | [jbpratt] parse full duration for time formatting | 2022/03/15-16:12
#1531 | [Chmouel Boudjnah] Add "tkn taskrun export" | 2022/03/18-09:46
#1538 | [Chmouel Boudjnah] update to cobra 1.4.0 | 2022/03/18-11:42
null | [PuneetPunamiya] Updates the configMap name for Operator version | 2022/03/18-13:01
null | [Chmouel Boudjnah] Add -o name to pipeline start | 2022/03/22-11:32
null | [Piyush Garg] This will fix the version command failing for chain and operator | 2022/03/23-12:16
null | [Pradeep Kumar] fix error while deleting pr without status | 2022/03/24-07:16

Signed-off-by: Piyush Garg <pgarg@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

Question: how to make PipelineRun show actual duration when it took longer than 1 hour?
5 participants