-
Notifications
You must be signed in to change notification settings - Fork 551
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
fix(sub): Only update subscriptions that have changes in status #2399
fix(sub): Only update subscriptions that have changes in status #2399
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dinhxuanvu 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 |
4b3573c
to
e337f68
Compare
/hold Before we merge this, let's see if anything more obvious stands out by refactoring the resolution syncing. Here's a snippet from a convo we had in Slack.
(see #2400) |
6af6678
to
62baea0
Compare
Currently, when resolution happens, every subscription will get updated regardless if there are any changes applied or not. This resolves into unnecessary API update calls. This commit will filter out subscriptions that don't get changed and only changed ones get updated. Note: Remove an additional update API call from one of subscription sync methods as well. Signed-off-by: Vu Dinh <[email protected]>
// setSubsCond will set the condition to the subscription if it doesn't already | ||
// exist or if it is different | ||
// Only return the list of updated subscriptions | ||
func (o *Operator) setSubsCond(subs []*v1alpha1.Subscription, cond v1alpha1.SubscriptionCondition) []*v1alpha1.Subscription { |
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 is more of a general question/comment than anything blocking: at a glance, this method currently resembles a Setter but we're passing the reference to the list of subscriptions, and outputting a list of subscriptions. Any idea on whether we're actually double dipping here - modifying the input and outputting a new subscription list? I guess that might not matter a whole ton as it's contingent on how the call site is handling this logic, and it's possible my brain power is limited going into EOD.
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 is just a "lazy" solution in term of not wanting to deal with removing element(s) from existing list by slicing the array. I can change this to a solution that will do the slicing so that the existing modified list will be returned instead of a new one.
if updateErr != nil { | ||
logger.WithError(updateErr).Debug("failed to update subs conditions") | ||
return updateErr | ||
} | ||
return err | ||
} | ||
|
||
defer func() { |
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.
+1 to removing this defer case. I think this reads a lot more clearer, and being more explicit in this code path likely helps limit side effects.
} else { | ||
logger.Debugf("no subscriptions were updated") | ||
} | ||
|
||
// Remove resolutionfailed condition from subscriptions | ||
subs = o.removeSubsCond(subs, v1alpha1.SubscriptionResolutionFailed) |
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.
Just a quick note: it feels like this function may be a candidate for refactoring in the future. I don't think we need to tackle that kind of change in this PR but I wanted to get any thoughts on whether you had that same though when poking at this locally?
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'm open for refactoring but what do you have in mind in term of changes that can be made to this function? It is pretty minimal as it is so I'm not sure what else we can do simplify it further.
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.
Just copy-pasting the comment chain on the other PR: #2429 (comment).
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'd like to hold off on refactoring and keeping the scope of these changes small as they're affecting upstream/downstream e2e runs, and combing down hot looping behavior in some edge cases.
if subCond.Equals(cond) { | ||
continue | ||
} |
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.
It looks like this Equals method does account for the edge case where the existing and new status conditions are equal, and avoids bumping the subCond.LastTransitionTime unnecessarily, avoiding another potential hotlooping scenario. Any value in adding a debug logging here, or is that just overkill?
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.
We can add a log here to indicate the condition already exists. I think it can be helpful for debugging reason.
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.
Responded.
} else { | ||
logger.Debugf("no subscriptions were updated") | ||
} | ||
|
||
// Remove resolutionfailed condition from subscriptions | ||
subs = o.removeSubsCond(subs, v1alpha1.SubscriptionResolutionFailed) |
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'm open for refactoring but what do you have in mind in term of changes that can be made to this function? It is pretty minimal as it is so I'm not sure what else we can do simplify it further.
if subCond.Equals(cond) { | ||
continue | ||
} |
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.
We can add a log here to indicate the condition already exists. I think it can be helpful for debugging reason.
// setSubsCond will set the condition to the subscription if it doesn't already | ||
// exist or if it is different | ||
// Only return the list of updated subscriptions | ||
func (o *Operator) setSubsCond(subs []*v1alpha1.Subscription, cond v1alpha1.SubscriptionCondition) []*v1alpha1.Subscription { |
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 is just a "lazy" solution in term of not wanting to deal with removing element(s) from existing list by slicing the array. I can change this to a solution that will do the slicing so that the existing modified list will be returned instead of a new one.
/lgtm |
Let's tackling any refactoring outside of this PR as this is blocked e2e runs. /hold cancel |
/retest |
/retest-required Please review the full test history for this PR and help us cut down flakes. |
1 similar comment
/retest-required Please review the full test history for this PR and help us cut down flakes. |
Currently, when resolution happens, every subscription will get
updated regardless if there are any changes applied or not. This
resolves into unnecessary API update calls.
This commit will filter out subscriptions that don't get changed
and only changed ones get updated.
Signed-off-by: Vu Dinh [email protected]
Description of the change:
Motivation for the change:
Reviewer Checklist
/doc