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

kubectl: Use fields from event series when computing describe events for a object #104482

Merged
merged 4 commits into from Sep 13, 2021

Conversation

harjas27
Copy link
Contributor

@harjas27 harjas27 commented Aug 20, 2021

What type of PR is this?

/kind bug

What this PR does / why we need it:

When using kubectl describe <resource> <name> , the events returned for the resource do not use the EventSeries.Count and EventSeries.LastObservedTime
This PR adds the logic to compute the age of the event using these fields

Which issue(s) this PR fixes:

Fixes kubernetes/kubectl#1095

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Changed kubectl describe to compute Age of an event using the count and lastObservedTime fields available in the event series 

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Aug 20, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @harjas27. Thanks for your PR.

I'm waiting for a kubernetes 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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Aug 20, 2021
@harjas27
Copy link
Contributor Author

/cc @eddiezane

@lauchokyip
Copy link
Member

/ok-to-test
/triage accepted
/priority backlog

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Aug 22, 2021
@pacoxu pacoxu added this to Needs review in SIG CLI Aug 24, 2021
firstTimestampSince = translateTimestampSince(e.FirstTimestamp)
}
if e.Series != nil {
interval = fmt.Sprintf("%s (x%d over %s)", translateMicroTimestampSince(e.Series.LastObservedTime), e.Series.Count+1, firstTimestampSince)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why e.Series.Count+1? Strictly speaking e.Series should be nil when only one event has occurred:

	// Data about the Event series this event represents or nil if it's a singleton Event.
	// +optional
	Series *EventSeries `json:"series,omitempty" protobuf:"bytes,11,opt,name=series"`

I can see the argument that since we have an event, e.Series.Count should logically be at least 1. However, if the field does contain a number, I don't think we should increment it.

Take a look at this example from the KEP:

# After second occurrence, Event looks like:

{
  regarding: A,
  action: B,
  reportingController: C,
  ...,
  series: {count: 2},
}

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 had added the +1 following a comment in the code:

// When a series is created for the first time, its count is set to 1.
// However, for a series to be created, there needs to be an isomorphic
// singleton event created beforehand. This singleton event is not
// counted in the series count which is why one is added here.
count = obj.Series.Count + 1

Also referred this. When a series is created for the first time, its count is set to 1 and for the series to be created, there needs to be a singleton event created.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, that's a good find, but I'm still unsure what is correct. It strikes me as very strange to expect clients (including humans reading the -o yaml output directly) to know the implementation details of the reporter, i.e. that it considers the series to exclude the first occurrence. The description in the KEP (that count should be 2 on the second occurrence) makes a lot more sense to me.

I also found the following validation, which disallows event counts less than two:

if event.Series != nil {
if event.Series.Count < 2 {
allErrs = append(allErrs, field.Invalid(field.NewPath("series.count"), "", "should be at least 2"))
}
if event.Series.LastObservedTime.Time == zeroTime {
allErrs = append(allErrs, field.Required(field.NewPath("series.lastObservedTime"), ""))
}
}

And the following comment thread, from the implementation PR:

image

cc @soltysh since you were approver on the printers PR

Copy link
Contributor

Choose a reason for hiding this comment

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

@KnVerey good catch, it looks like at the time the printer PR merged the validation wasn't fully complete. If you check the current code

if event.Series != nil {
if event.Series.Count < 2 {
allErrs = append(allErrs, field.Invalid(field.NewPath("series.count"), "", "should be at least 2"))
}
if event.Series.LastObservedTime.Time == zeroTime {
allErrs = append(allErrs, field.Required(field.NewPath("series.lastObservedTime"), ""))
}
}
you'll notice that the minimum required value for counter is 2 and not one like from the above script. Which means that the series represent values exactly like describe in the KEP and not in client-go. So we need to drop +1 from this PR and also from the printers.

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.

/approve
/hold

You still need to address @KnVerey comment dropping +1 from counter and fix the release notes. @KnVerey has the final approval on the PR

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 10, 2021
@KnVerey
Copy link
Contributor

KnVerey commented Sep 10, 2021

@harjas27 please update the test assertion and add a release note to your PR description

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Sep 10, 2021
@KnVerey
Copy link
Contributor

KnVerey commented Sep 13, 2021

/label tide/merge-method-squash
/unhold
/lgtm
/approve

Thank you @harjas27 ! Would you be interested in contributing the fix to remove the extra +1 from the printer code you found in a follow up PR?

@k8s-ci-robot k8s-ci-robot added tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Sep 13, 2021
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 13, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: harjas27, KnVerey, 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

@k8s-ci-robot k8s-ci-robot merged commit c6935ad into kubernetes:master Sep 13, 2021
SIG CLI automation moved this from Needs review to Done Sep 13, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.23 milestone Sep 13, 2021
ibabou pushed a commit to ibabou/kubernetes that referenced this pull request Sep 28, 2021
…for a object (kubernetes#104482)

* take into account new fields for event

* add event with old event fields for test

* fix: remove unnecessary "+1" from event series count

* fix: update the assertion for failing test case
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. area/kubectl 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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/backlog Higher priority than priority/awaiting-more-evidence. 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. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Development

Successfully merging this pull request may close these issues.

"kubectl describe <resource>" doesn't take into account the new fields of core.v1/event
5 participants