Conversation
1b3a8d2 to
764d0fd
Compare
pkg/fsm/events/events.go
Outdated
| if message == "" { | ||
| message = "Object is ready" | ||
| } | ||
| e.recorder.Event(obj, EventTypeNormal, EventReadyReason, message) |
There was a problem hiding this comment.
A thought for future iterations.
One best practice I've seen around k8s events is avoiding repetitive/duplicate events - like emitting an event once when an object is reconciled successfully for the first time, and not on subsequent reconsile loops.
It might be nice if this RecordReady function did the dedupe for you, or had a flag to enable/disable dedupe logic.
Like I said, just a thought - feel free to kick this idea into the future!
There was a problem hiding this comment.
That's a cool idea. Let me think on how best to do the dedup. Due to the concern with event cardinality is the reason why I chose not to emit events automatically in the sdk and instead leave it up to the controller especially in v1. That being said let me mull it over on how best to tackle this in the interface itself
There was a problem hiding this comment.
Not to discourage the idea, but this may be difficult to implement on the SDK given that Events model point-in-time events. So, naively, an event for reconciliation at T1 is distinct from an event for reconciliation at T2.
That being said, the user of the SDK can make decisions about what constitutes as a "unique" event (i.e. the dedupe logic would need to be on the caller side since it's contingent on their specific logic)
There was a problem hiding this comment.
Ya I decided to punt on this as a follow up to have some time to think about how best to do it or make the call that this should be a client side responsibility in which case we can come up with a recommendation in the docs
| return | ||
| } | ||
|
|
||
| m.sink.RecordEvent(triggerGVK, objectName, objectNamespace, eventType, reason, controllerName) |
There was a problem hiding this comment.
Can recording fail? should we be erroring here and surfacing this in the logs?
There was a problem hiding this comment.
The metrics interface from prometheus for Inc() call does not return any error so not really sure how to capture failure and this matches what we do with other metrics. Let me look again to see if I missed something. For context the prom inc function looks like:
func (c *counter) Inc() {
atomic.AddUint64(&c.valInt, 1)
}
harveyxia
left a comment
There was a problem hiding this comment.
This LGTM—how do you envision metrics against the events being used?
pkg/fsm/events/events.go
Outdated
| EventReadyReason = "Ready" | ||
|
|
||
| EventTypeNormal = "Normal" | ||
| EventTypeWarning = "Warning" |
There was a problem hiding this comment.
Can these be kept private if access is done through the receiver methods like RecordReady?
There was a problem hiding this comment.
yes good catch I'll make them private
pkg/fsm/events/events.go
Outdated
| if message == "" { | ||
| message = "Object is ready" | ||
| } | ||
| e.recorder.Event(obj, EventTypeNormal, EventReadyReason, message) |
There was a problem hiding this comment.
Not to discourage the idea, but this may be difficult to implement on the SDK given that Events model point-in-time events. So, naively, an event for reconciliation at T1 is distinct from an event for reconciliation at T2.
That being said, the user of the SDK can make decisions about what constitutes as a "unique" event (i.e. the dedupe logic would need to be on the caller side since it's contingent on their specific logic)
I was chatting with Justin and he mentioned that it could be useful to be able to alert on certain k8s events or if events are not simply tied to state transitions, having metrics would provide an easy way to visualize them in a dashboard. It feels very much a client specific behaviour regarding this utility which is why I pitched the idea to see what others thought |
Co-authored-by: Harvey Xia <[email protected]>
Co-authored-by: Jess Yuen <[email protected]>
💸 TL;DR
📜 Details
eventspackage to create a client-go event recorder. Despite the event recorder interface being extremely simple and already being able to use it with the sdk, the neweventspackage will allow us to add extra smarts to the package.🧪 Testing Steps / Validation
kubectl describeoutputEvents: Type Reason Age From Message ---- ------ ---- ---- ------- Normal NSCreated 5s orchestration-controller-manager Namespace created in clustercurl):✅ Checks
I am open to skipping the metrics inclusion but wanted to share the current version to start getting people's thoughts on the utility of the events interface