-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Improve the output of kubectl get events
#66643
Conversation
@kubernetes/sig-cli-bugs |
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)
a46c483
to
2f275b7
Compare
@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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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)) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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
[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 |
Remember, columns themselves are not API. We have |
True, we left ourselves the ability to modify them slightly, but changing printers columns you are changing the API, and by moving some to |
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 We can add that language to the api doc for sure. |
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. |
@@ -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"}, |
There was a problem hiding this comment.
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" ? :)
There was a problem hiding this comment.
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
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.
-o wide