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

Delete unused status keys from watchable #2660

Closed
arkodg opened this issue Feb 20, 2024 · 9 comments · Fixed by #2782
Closed

Delete unused status keys from watchable #2660

arkodg opened this issue Feb 20, 2024 · 9 comments · Fixed by #2782
Assignees
Labels
kind/bug Something isn't working road-to-ga
Milestone

Comments

@arkodg
Copy link
Contributor

arkodg commented Feb 20, 2024

Description:

The status keys are only stored and not deleted. Either all the status keys or at least the stale ones should be deleted to free up memory

r.ProviderResources.GatewayStatuses.Store(key, &gateway.Status)

&
r.ProviderResources.EnvoyPatchPolicyStatuses.Store(key, e.Status)

@arkodg arkodg added triage kind/bug Something isn't working road-to-ga and removed triage labels Feb 20, 2024
@arkodg arkodg added the help wanted Extra attention is needed label Feb 20, 2024
@arkodg arkodg added this to the v1.0.0-rc1 milestone Feb 20, 2024
@arkodg
Copy link
Contributor Author

arkodg commented Feb 20, 2024

one solution could be deleting the status from watchable right after processing it in

func (r *gatewayAPIReconciler) subscribeAndUpdateStatus(ctx context.Context) {

@ShyunnY
Copy link
Contributor

ShyunnY commented Feb 21, 2024

At least when we can determine the status update result, we can delete it in subscribeAndUpdateStatus

@arkodg
Copy link
Contributor Author

arkodg commented Feb 21, 2024

yeah +1 @ShyunnY

@ShyunnY
Copy link
Contributor

ShyunnY commented Feb 23, 2024

if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
obj := update.Resource
// Get the resource.
if err := u.client.Get(context.Background(), update.NamespacedName, obj); err != nil {
if kerrors.IsNotFound(err) {
return nil
}
return err
}
newObj := update.Mutator.Mutate(obj)
if isStatusEqual(obj, newObj) {
u.log.WithName(update.NamespacedName.Name).
WithName(update.NamespacedName.Namespace).
Info("status unchanged, bypassing update")
return nil
}
newObj.SetUID(obj.GetUID())
return u.client.Status().Update(context.Background(), newObj)
}); err != nil {
u.log.Error(err, "unable to update status", "name", update.NamespacedName.Name,
"namespace", update.NamespacedName.Namespace)
}

When status is updated, do we need to obtain the update result to decide whether to delete status keys?

I have two ideas:

  • First: regardless of the status update result, we delete the status key in the watchable. Assuming that the update result fails, there is no need to process it, just wait for the next reconcile. We can delete the status key directly in the subscribeAndUpdateStatus function.
  • Second: We modify the apply method to accept err externally. If the status update result err != nil, we skip the deletion of status keys. If everything is fine (which is what we want to see), then we delete the status keys

@arkodg
Copy link
Contributor Author

arkodg commented Feb 23, 2024

@ShyunnY 2 options I see are

  • Mark and Sweep in in the publisher Gateway API Layer similar to what is done for XdsIR and InfraIR

    // getIRKeysToDelete returns the list of IR keys to delete

    • Pros

      • status cached in watchable will prevent any more publishes to consumer saving CPU
    • Cons

      • status in watchable takes up memory
  • Delete all after processing is done in the subscriber provider layer

    • Pros

      • Reduces memory
    • Cons

      • provider will receive all publishes, and will perform an extra read on the resource to compare status, that resource should hopefully be cached in controller-runtime, else it will be an I/O op to API server

@ShyunnY
Copy link
Contributor

ShyunnY commented Feb 24, 2024

In my opinion, I would vote for the first way.

@arkodg
Copy link
Contributor Author

arkodg commented Feb 24, 2024

1 sounds good

@arkodg arkodg modified the milestones: v1.0.0-rc1, v1.0.0 Mar 2, 2024
@uniglot
Copy link
Contributor

uniglot commented Mar 4, 2024

Hi, can I work on this issue with the first option, unless someone's already dealing with it?

@zirain zirain removed the help wanted Extra attention is needed label Mar 4, 2024
@zirain
Copy link
Member

zirain commented Mar 4, 2024

@uniglot thanks for taking this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working road-to-ga
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

4 participants