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

Event recorder should enfoce API conventions for Event Reason #14111

Open
derekwaynecarr opened this issue Sep 17, 2015 · 22 comments
Open

Event recorder should enfoce API conventions for Event Reason #14111

derekwaynecarr opened this issue Sep 17, 2015 · 22 comments
Assignees
Labels
lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. priority/backlog Higher priority than priority/awaiting-more-evidence. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery.

Comments

@derekwaynecarr
Copy link
Member

As code produces events, we are not always enforcing our own API conventions for EventNames

An example PR where we had to make a change:
#14110

We should enforce proper event naming conventions as defined here:
https://github.com/kubernetes/kubernetes/blob/master/docs/devel/api-conventions.md#events

The best way to stop this in the future is for the Event recorder to error/warn when an invalid event name is provided.

@derekwaynecarr derekwaynecarr self-assigned this Sep 17, 2015
@derekwaynecarr
Copy link
Member Author

fyi @bgrant0607 - assume you are agreeable to code enforcing our api-conventions for events?

@derekwaynecarr
Copy link
Member Author

The validation for an Event should also enforce the naming convention:

https://github.com/kubernetes/kubernetes/blob/master/pkg/api/validation/events.go#L26

@derekwaynecarr derekwaynecarr changed the title Event recorder should enfoce API conventions for Event names Event recorder should enfoce API conventions for Event Reason Sep 17, 2015
@simon3z
Copy link
Contributor

simon3z commented Sep 17, 2015

@derekwaynecarr given the description of reason:

'reason' is the reason this event is generated. 'reason' should be short and unique; it should be in UpperCamelCase format (starting with a capital letter). "reason" will be used to automate handling of events, so imagine people writing switch statements to handle them. You want to make that easy.

I'd go with something more structured as:

type EventReason string

const (
    /* Some meaningful explanation about CIDRNotAvailable */
    CIDRNotAvailable EventReason = "CIDRNotAvailable"

    /* Some meaningful explanation about CIDRAssignmentFailed */
    CIDRAssignmentFailed EventReason = "CIDRAssignmentFailed"

    ...
)

func (recorder *recorderImpl) Eventf(object runtime.Object, reason EventReason, ...) {
    ...
}

What do you think? (cc @bgrant0607 )

@jiangyaoguo
Copy link
Contributor

@derekwaynecarr Reason Should be in CamelCase. At most we can validate it's one word begin with capital letter. Is this enough for validate reason if we want do this in event recorder?

@alex-mohr alex-mohr added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Sep 17, 2015
@alex-mohr
Copy link
Contributor

@lavalamp is this team/CSI? or you as interested events guru?

@bgrant0607
Copy link
Member

Strengthening validation would be a breaking API change. As much as I'd like to enforce the conventions, this can't be the way to do it. Or maybe the check could be enabled only during tests.

Could we write a code validator instead?

It is also true that it seems hard to make the check stronger than just capitalization, but not capitalizing the first letter is one of the most common inconsistencies.

@bgrant0607 bgrant0607 added priority/backlog Higher priority than priority/awaiting-more-evidence. team/api sig/contributor-experience Categorizes an issue or PR as relevant to SIG Contributor Experience. and removed sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Sep 17, 2015
@bgrant0607
Copy link
Member

Defining constants as in @simon3z's example also SGTM.

@pmorie
Copy link
Member

pmorie commented Sep 17, 2015

@kubernetes/rh-cluster-infra @kubernetes/rh-ux

@simon3z
Copy link
Contributor

simon3z commented Sep 17, 2015

Defining constants as in @simon3z's example also SGTM.

The advantage of that is that I suppose you can use reflection to validate the entries (list all the EventReason constants in the record package and check for no spaces, first capital letter, etc.)

Anyway having all the reasons in one place already would allow people to easily review that part of the code and spot inconsistencies.

@liggitt
Copy link
Member

liggitt commented Sep 17, 2015

+1 for validation of whatever sort we can do in a compatible way

-1 for centralized reasons. I shouldn't have to change core event code to report new event reasons for a new component. Remember that event reporters might not even live in the kubernetes code base

@lavalamp
Copy link
Member

Agree.

On Thu, Sep 17, 2015 at 3:18 PM, Jordan Liggitt notifications@github.com
wrote:

+1 for validation of whatever sort we can do in a compatible way

-1 for centralized reasons. I shouldn't have to change core event code to
report new event reasons for a new component. Remember that event reporters
might not even live in the kubernetes code base


Reply to this email directly or view it on GitHub
#14111 (comment)
.

@jiangyaoguo
Copy link
Contributor

What about add a optional validation in apiserver and open it during tests?

@alex-mohr
Copy link
Contributor

Re: centralized reasons, there's a strong benefit to people building automated systems that are clients of k8s to have a reasonably-explicit list of such things, rather than having to discover them at runtime in production when a new one starts being reported.

Re: event reporters outside the codebase, presumably some form of namespacing could allow them to report common established errors but define new ones where absolutely necessary.

And it may be instructive to look at http errors with a numeric generic-code plus more detailed text for inspiration?

@lavalamp
Copy link
Member

@alex-mohr the problem with centralized reasons is that it is a recipe for brittle clients: the act of adding a reason becomes an api-breaking change. Event reasons are very explicitly not centralized for this reason.

@bgrant0607 bgrant0607 removed the sig/contributor-experience Categorizes an issue or PR as relevant to SIG Contributor Experience. label Feb 19, 2016
@k8s-github-robot k8s-github-robot added the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label May 31, 2017
@0xmichalis
Copy link
Contributor

@kubernetes/sig-api-machinery-misc

@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Jun 9, 2017
@k8s-github-robot k8s-github-robot removed the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Jun 9, 2017
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or @fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 26, 2017
@bgrant0607
Copy link
Member

cc @gmarek

@gmarek
Copy link
Contributor

gmarek commented Jan 26, 2018

/remove-lifecycle state
/lifecycle frozen

@k8s-ci-robot k8s-ci-robot added the lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. label Jan 26, 2018
@gmarek
Copy link
Contributor

gmarek commented Jan 26, 2018

@yastij - I wrote a bunch of validation logic for Events v2 in the initial PR, but it may be worth revisiting to check if all fields are properly validated, according to kubernetes/community#1659.

@yastij
Copy link
Member

yastij commented Jan 26, 2018

@gmarek - I'll take a look

@nikhita
Copy link
Member

nikhita commented Mar 4, 2018

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 4, 2018
@sftim
Copy link
Contributor

sftim commented Aug 17, 2023

Strengthening validation would be a breaking API change. As much as I'd like to enforce the conventions, this can't be the way to do it. Or maybe the check could be enabled only during tests.

Could we write a code validator instead?

It is also true that it seems hard to make the check stronger than just capitalization, but not capitalizing the first letter is one of the most common inconsistencies.

We now have warnings and a framework for instrumentation, so maybe there's something we can revisit here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. priority/backlog Higher priority than priority/awaiting-more-evidence. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery.
Projects
None yet
Development

No branches or pull requests