-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Emit kubernetes events from KEDA #1523
Conversation
7b0ca5a
to
b943f36
Compare
pkg/scaling/scale_handler.go
Outdated
@@ -90,6 +94,9 @@ func (h *scaleHandler) HandleScalableObject(scalableObject interface{}) error { | |||
cancelValue() | |||
} | |||
h.scaleLoopContexts.Store(key, cancel) | |||
h.recorder.Event(withTriggers, corev1.EventTypeNormal, eventreason.ScalersRestarted, "Restarted scalers watch") | |||
} else { | |||
h.recorder.Event(withTriggers, corev1.EventTypeNormal, eventreason.ScalersStarted, "Started scalers watch") |
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.
Would this emit every time the controller pod restarts?
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.
Yes. I wasn't sure if there is a best practice somewhere for when to emit events. I tried to add all the ones mentioned in #530 but if there is a best practices for this I'd love to check 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.
The basic guideline is it should only be when something actually occurs. So any situation where a reconcile happens and it takes no action, it should produce no events :) Otherwise they can get spammy and overwhelm Etcd.
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.
But I don't suppose that controller pod restarts happen that often or it is something that we should consider as normal. Not sure what other way we can emit this kind of event?
} else { | ||
reqLogger.V(1).Info(msg) | ||
conditions.SetReadyCondition(metav1.ConditionTrue, "ScaledObjectReady", msg) | ||
r.Recorder.Event(scaledObject, corev1.EventTypeNormal, eventreason.Ready, msg) |
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.
This isn't usually the kind of thing you would want in an event since it's not a specific action or event, it's a convergent state.
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.
Agree, we should emit only once, for the first time.
b943f36
to
42e9f8b
Compare
Before we merge, can you PR a new sub-page to our Would be good to list all event types and what scenario they represent. |
controllers/scaledjob_controller.go
Outdated
} else { | ||
reqLogger.V(1).Info(msg) | ||
conditions.SetReadyCondition(metav1.ConditionTrue, "ScaledJobReady", msg) | ||
r.Recorder.Event(scaledJob, corev1.EventTypeNormal, eventreason.Ready, msg) |
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.
This should be emitted only for the first time (if at all).
} else { | ||
reqLogger.V(1).Info(msg) | ||
conditions.SetReadyCondition(metav1.ConditionTrue, "ScaledObjectReady", msg) | ||
r.Recorder.Event(scaledObject, corev1.EventTypeNormal, eventreason.Ready, msg) |
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.
Agree, we should emit only once, for the first time.
pkg/scaling/scale_handler.go
Outdated
@@ -90,6 +94,9 @@ func (h *scaleHandler) HandleScalableObject(scalableObject interface{}) error { | |||
cancelValue() | |||
} | |||
h.scaleLoopContexts.Store(key, cancel) | |||
h.recorder.Event(withTriggers, corev1.EventTypeNormal, eventreason.ScalersRestarted, "Restarted scalers watch") | |||
} else { | |||
h.recorder.Event(withTriggers, corev1.EventTypeNormal, eventreason.ScalersStarted, "Started scalers watch") |
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.
But I don't suppose that controller pod restarts happen that often or it is something that we should consider as normal. Not sure what other way we can emit this kind of event?
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 list of events looks okay!
What about these events:
Follow-up PR/issue is ok, just asking |
Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>
52306cd
to
d3191b5
Compare
Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>
d3191b5
to
2872b99
Compare
Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>
Thanks @coderanger, @zroubalik, @tomkerkhove for the feedback.
Some remarks:
|
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.
Overall +1 from me on the API plumbing side.
} | ||
|
||
if triggerAuthentication.ObjectMeta.Generation == 1 { | ||
r.Recorder.Event(triggerAuthentication, corev1.EventTypeNormal, eventreason.TriggerAuthenticationAdded, "New TriggerAuthentication configured") |
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.
This seems like a slightly weird one, but I don't think it will do any harm :)
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.
Yeah, we can go with this for now :)
@@ -90,6 +95,8 @@ func (h *scaleHandler) HandleScalableObject(scalableObject interface{}) error { | |||
cancelValue() | |||
} | |||
h.scaleLoopContexts.Store(key, cancel) | |||
} else { | |||
h.recorder.Event(withTriggers, corev1.EventTypeNormal, eventreason.KEDAScalersStarted, "Started scalers watch") |
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 this would display on every restart of the controller? Can probably drop this and the scalers-stopped events since they don't correspond to actual actions, just internal code state.
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.
Yeah, but how often do we want to(or would like to see) restart the controller? Is this happening that often? And in fact, with a restart the scalers do start watch, so the event message is correct.
I've had a look kedacore/keda-docs#361 and it's a bit odd since some have the KEDA prefix and others don't. I know I've requested this, but if others think it's stupid I would remove it or add the prefix to all of them. Thoughts @zroubalik? Just for context: The reason why I suggested this was for consumers since they typically process the whole event stream and this would make it easier for them to understand where these come from.
Thanks 💘
That's not ideal as you might want to filter out to detect authentication issues, but we can still split them later on if this is too much trouble now. Thoughts @zroubalik?
Let's leave this out then, we can still add it later on if need be? |
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.
Looking good, I like the renamed event names!
- we should probably add a controller for ClusterTriggerAuthentication and cover this new resource as well.
- ad "Scaledobject/SCaledJob is linked to trigger authentication" discussion - yeah, we would need to track it as you suggest. But I don't think is necessary to add this complexity now. We could add later if there's a need from community. what you say @tomkerkhove?
scaleHandler scaling.ScaleHandler | ||
} | ||
|
||
// SetupWithManager initializes the ScaledJobReconciler instance and starts a new controller managed by the passed Manager instance. | ||
func (r *ScaledJobReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||
r.scaleHandler = scaling.NewScaleHandler(mgr.GetClient(), nil, mgr.GetScheme(), r.GlobalHTTPTimeout) | ||
r.scaleHandler = scaling.NewScaleHandler(mgr.GetClient(), nil, mgr.GetScheme(), r.GlobalHTTPTimeout, mgr.GetEventRecorderFor("scale-handler")) |
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.
Event recorder for Metrics Adapter is named keda-metrics-adapter
and this one is named scale-handler
. For consistency, this one could be maybe named keda-operator
/ keda-controller
and sync them with those set in main.go WDYT?
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.
Yeah, I think that makes sense. I'll change it to one recorder with the name keda-operator
CHANGELOG.md
Outdated
@@ -43,6 +43,7 @@ | |||
- Global authentication credentials can be managed using `ClusterTriggerAuthentication` objects ([#1452](https://github.com/kedacore/keda/pull/1452)) | |||
- Introducing OpenStack Swift scaler ([#1342](https://github.com/kedacore/keda/issues/1342)) | |||
- Introducing MongoDB scaler ([#1467](https://github.com/kedacore/keda/pull/1467)) | |||
- Emit Kubernetes Events on KEDA events ([#1523](https://github.com/kedacore/keda/pull/1523)):wq |
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.
Nit: This should be moved to Unreleased section above.
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.
And remove the vim suffix at the end :)
} | ||
|
||
if triggerAuthentication.ObjectMeta.Generation == 1 { | ||
r.Recorder.Event(triggerAuthentication, corev1.EventTypeNormal, eventreason.TriggerAuthenticationAdded, "New TriggerAuthentication configured") |
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.
Yeah, we can go with this for now :)
@@ -90,6 +95,8 @@ func (h *scaleHandler) HandleScalableObject(scalableObject interface{}) error { | |||
cancelValue() | |||
} | |||
h.scaleLoopContexts.Store(key, cancel) | |||
} else { | |||
h.recorder.Event(withTriggers, corev1.EventTypeNormal, eventreason.KEDAScalersStarted, "Started scalers watch") |
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.
Yeah, but how often do we want to(or would like to see) restart the controller? Is this happening that often? And in fact, with a restart the scalers do start watch, so the event message is correct.
I personally don't have a problem with
+1 split later if needed
+1 |
So you're ok with how they are or would you use KEDA prefix for all? |
I am ok with how they are now. |
Regarding the naming, I was initially looking how the default kubernetes events are named, and they were all named as |
Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>
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.
Sounds good to me, it's a lot better than the default ones :D
LGTM, let me know when the docs are updated!
Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>
🚀 |
@@ -90,6 +95,8 @@ func (h *scaleHandler) HandleScalableObject(scalableObject interface{}) error { | |||
cancelValue() | |||
} | |||
h.scaleLoopContexts.Store(key, cancel) | |||
} else { | |||
h.recorder.Event(withTriggers, corev1.EventTypeNormal, eventreason.KEDAScalersStarted, "Started scalers watch") |
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.
@ahmelsayed Is it possible to add the name of every scaler/trigger here?
@@ -115,6 +122,7 @@ func (h *scaleHandler) DeleteScalableObject(scalableObject interface{}) error { | |||
cancel() | |||
} | |||
h.scaleLoopContexts.Delete(key) | |||
h.recorder.Event(withTriggers, corev1.EventTypeNormal, eventreason.KEDAScalersStopped, "Stopped scalers watch") |
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.
@ahmelsayed Is it possible to add the name of every scaler/trigger here?
* Emit kubernetes events from KEDA Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com> * CR comments Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com> * Fix CI errors Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com> * goimports Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com> * Code review comments Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com> * Fix CHANGELOG.md Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>
* Emit kubernetes events from KEDA Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com> * CR comments Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com> * Fix CI errors Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com> * goimports Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com> * Code review comments Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com> * Fix CHANGELOG.md Signed-off-by: Ahmed ElSayed <ahmels@microsoft.com>
Signed-off-by: Ahmed ElSayed ahmels@microsoft.com
This PR adds the following events:
For both
ScaledObjects
andScaledJobs
:Ready
CheckFailed
Deleted
ScalersStarted
ScalersRestarted
ScalersStopped
For
ScaledObjects
:ScaleTargetActivated
ScaleTargetDeactivated
ScaleTargetActivationFailed
ScaleTargetDeactivationFailed
For
ScaledJobs
:JobsCreated
If this list looks okay, I'll open a docs PR to list them in there.
Checklist
Fixes #530