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

Improve the output of kubectl get events #66643

Merged
merged 1 commit into from
Jul 31, 2018

Conversation

smarterclayton
Copy link
Contributor

@smarterclayton smarterclayton commented Jul 26, 2018

Events have long shown the most data of the core objects in their output, but that data is of varying use to a user. Following the principle that events are intended for the system to communicate information back to the user, and that Message is the primary human readable field, this commit alters the default columns to ensure event is shown with the most width given to the message, and all other fields organized by their relevance to the message.

  1. Events are no longer sorted in the printer (this was a bug and was broken with paging and server side rendering)
  2. Only the last seen, type, reason, kind, and message fields are shown by default, which makes the message prominent
  3. Source, subobject, count, and first seen are only shown under -o wide
  4. The duration fields were changed to be the more precise output introduced for job duration (2-3 sig figs)
  5. Prioritized the column order for scanning - when, how important, what kind of error, what kind of object, and the message.
  6. Trim trailing newlines on the message.
Improved the output of `kubectl get events` to prioritize showing the message, and move some fields to `-o wide`.
$ kubectl get events --sort-by lastTimestamp
LAST SEEN TYPE      REASON                   KIND                    MESSAGE
16m       Normal    SawCompletedJob          CronJob                 Saw completed job: image-mirror-origin-v3.11-quay-1532581200
16m       Normal    SuccessfulDelete         CronJob                 Deleted job image-mirror-origin-v3.11-quay-1532577600
14m       Normal    Scheduled                Pod                     Successfully assigned 50c42204-9091-11e8-b2a1-0a58ac101869 to origin-ci-ig-n-fqfh
14m       Normal    Pulling                  Pod                     pulling image "docker-registry.default.svc:5000/ci/commenter:latest"
14m       Normal    Created                  Pod                     Created container
14m       Normal    Pulled                   Pod                     Successfully pulled image "docker-registry.default.svc:5000/ci/commenter:latest"
14m       Normal    Started                  Pod                     Started container
14m       Normal    SandboxChanged           Pod                     Pod sandbox changed, it will be killed and re-created.
4m14s     Normal    ScaleDown                Pod                     deleting pod for node scale down
4m14s     Normal    ScaleDown                Pod                     deleting pod for node scale down
4m14s     Normal    ScaleDown                Pod                     deleting pod for node scale down
4m14s     Normal    ScaleDown                Pod                     deleting pod for node scale down
4m14s     Normal    ScaleDown                Pod                     deleting pod for node scale down
4m14s     Normal    ScaleDown                Pod                     deleting pod for node scale down
4m14s     Normal    ScaleDown                Pod                     deleting pod for node scale down
4m13s     Normal    SuccessfulCreate         ReplicationController   Created pod: tide-30-hmncf
4m13s     Normal    Scheduled                Pod                     Successfully assigned tide-30-hmncf to origin-ci-ig-n-x64l
4m12s     Normal    SuccessfulCreate         ReplicationController   Created pod: console-jenkins-operator-16-dd5k8
4m12s     Normal    SuccessfulCreate         ReplicationController   Created pod: sinker-23-scfmt

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jul 26, 2018
@k8s-ci-robot k8s-ci-robot requested review from dixudx and eparis July 26, 2018 05:19
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 26, 2018
@smarterclayton
Copy link
Contributor Author

@kubernetes/sig-cli-bugs

@k8s-ci-robot k8s-ci-robot added sig/cli Categorizes an issue or PR as relevant to SIG CLI. kind/bug Categorizes issue or PR as related to a bug. labels Jul 26, 2018
@krmayankk
Copy link

seems like this fixes an issue i filed long time back #29838 .

Events have long shown the most data of the core objects in their output, but that data is of varying use
to a user. Following the principle that events are intended for the system to communicate information back
to the user, and that Message is the primary human readable field, this commit alters the default columns
to ensure event is shown with the most width.

1. Events are no longer sorted in the printer (this was a bug and was broken with paging and server side
   rendering)
2. Only the last seen, type, reason, kind, and message fields are shown by default, which makes the
   message prominent
3. Source, subobject, count, and first seen are only shown under `-o wide`
4. The duration fields were changed to be the more precise output introduced for job duration (2-3 sig figs)
@smarterclayton
Copy link
Contributor Author

@juanvallejo @soltysh

@smarterclayton
Copy link
Contributor Author

@gmarek for events as well

@@ -57,17 +57,29 @@ func HumanDuration(d time.Duration) string {
}
minutes := int(d / time.Minute)
if minutes < 10 {
return fmt.Sprintf("%dm%ds", minutes, int(d/time.Second)%60)
s := int(d/time.Second) % 60
if s == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe a small test for these duration changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added new tests to the _test.go

@juanvallejo
Copy link
Contributor

lgtm, one small comment

cc @soltysh


return []metav1beta1.TableRow{row}, nil
}

// Sorts and prints the EventList in a human-friendly format.
func printEventList(list *api.EventList, options printers.PrintOptions) ([]metav1beta1.TableRow, error) {
sort.Sort(events.SortableEvents(list.Items))
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure where sorting is being done now, are they sorted in the get command now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The apiserver returns in natural order. To sort events by timestamp, you have to ask for it - sort doesn't work at this level because chunking would result in the objects being sorted.

We might in the future add a feature that allows a resource to define its default sort on the client side, but we'd need to think more about it.

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

My only concern is that this is changing API, slightly but still. But that's a reasonable change, one that will improve UX.
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 31, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: smarterclayton, soltysh

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

@smarterclayton
Copy link
Contributor Author

Remember, columns themselves are not API. We have --template | -o yaml ... for that.

@soltysh
Copy link
Contributor

soltysh commented Jul 31, 2018

Remember, columns themselves are not API. We have --template | -o yaml ... for that.

True, we left ourselves the ability to modify them slightly, but changing printers columns you are changing the API, and by moving some to -o wide this is changing just that.

@smarterclayton
Copy link
Contributor Author

smarterclayton commented Jul 31, 2018

No, printer columns do not fall under API guarantees. We explicitly say that the content of columns and their display is not an API. The table format is, but not the content of the table. Otherwise we would never be able to improve the experience. The closest analogue is that the Message field of an error is not an API, and we reserve the right to display the best message possible for a given condition.

We can add that language to the api doc for sure.

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 66445, 66643, 60551). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit f49708b into kubernetes:master Jul 31, 2018
@@ -1927,7 +1927,7 @@ func TestTranslateTimestampSince(t *testing.T) {
{"unknown", translateTimestampSince(metav1.Time{}), "<unknown>"},
{"30 seconds ago", translateTimestampSince(metav1.Time{Time: time.Now().Add(-3e10)}), "30s"},
{"5 minutes ago", translateTimestampSince(metav1.Time{Time: time.Now().Add(-3e11)}), "5m"},
{"an hour ago", translateTimestampSince(metav1.Time{Time: time.Now().Add(-6e12)}), "1h"},
{"an hour ago", translateTimestampSince(metav1.Time{Time: time.Now().Add(-6e12)}), "100m"},

Choose a reason for hiding this comment

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

Should this not be "60m" instead of "100m" ? :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the textual representation gets "truncated" down

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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants