Skip to content

feat :Add GetActivePods to handle/datastore and remove deleted pod from prefix-cache scorer #1376

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kfirtoledo
Copy link
Contributor

@kfirtoledo kfirtoledo commented Aug 14, 2025

This PR introduces two main enhancements:

  1. GetActivePods support in the plugin handle and datastore
  • Added GetActivePods() method to plugins.Handle interface.
  • Updated eppHandle to store and call a GetActivePodsFunc.
  • Implemented GetActivePods in the datastore to return the list of currently active pods.
  1. Remove deleted pod from prefix-cache scorer
  • Added RemovePod method to prefix.indexer to remove a pod
  • This enables cleanup of deleted pod after period of time that pod becomes inactive.

These changes allow plugins to query active pods directly from the handle and support cache cleanup for inactive pods in the prefix-cache scorer (Fix #1289)

Copy link

netlify bot commented Aug 14, 2025

Deploy Preview for gateway-api-inference-extension ready!

Name Link
🔨 Latest commit 651f62e
🔍 Latest deploy log https://app.netlify.com/projects/gateway-api-inference-extension/deploys/689da933e7691200085a59d5
😎 Deploy Preview https://deploy-preview-1376--gateway-api-inference-extension.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 14, 2025
@k8s-ci-robot k8s-ci-robot requested review from ahg-g and liu-cong August 14, 2025 09:15
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kfirtoledo
Once this PR has been reviewed and has the lgtm label, please assign danehans for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 14, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @kfirtoledo. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 14, 2025
@kfirtoledo
Copy link
Contributor Author

/assign @nirrozenbaum

@kfirtoledo
Copy link
Contributor Author

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 14, 2025
@ahg-g
Copy link
Contributor

ahg-g commented Aug 14, 2025

@elevran is this aligned with the new datalayer APIs?

@elevran
Copy link
Contributor

elevran commented Aug 14, 2025

@elevran is this aligned with the new datalayer APIs?

I don't see a conflict - the datastore API is minimally affected.
Might be cleaner to allow registration for cleanup or Pod deletion instead of listing all Pods periodically, but this is not something I've touched in the data layer yet (plan to refactor the k8s data sources as well, as we discussed on the original design issue).

@@ -27,6 +29,9 @@ type Handle interface {
Context() context.Context

HandlePlugins

// GetActivePods returns a list of all active pods
GetActivePods() []types.NamespacedName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: In go, it's more idiomatic to use ActivePods

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider returning a map[types.NamespacedName]bool instead of a list so the plugin doesn't need to convert a list to a map/set

@@ -61,6 +61,7 @@ type Datastore interface {
PodList(predicate func(backendmetrics.PodMetrics) bool) []backendmetrics.PodMetrics
PodUpdateOrAddIfNotExist(pod *corev1.Pod) bool
PodDelete(namespacedName types.NamespacedName)
GetActivePods() []types.NamespacedName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add this, we can use PodList.

@@ -239,6 +248,45 @@ func (m *Plugin) matchLongestPrefix(ctx context.Context, hashes []BlockHash) map
return res
}

// StartPodActiveWatcher starts a goroutine that watches for active pods.
func (m *Plugin) StartPodActiveWatcher(ctx context.Context, handle plugins.Handle) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call this something like CleanUpInactivePods to be more descriptive?

ticker := time.NewTicker(PodActiveCheckInterval)
defer ticker.Stop()

podLastSeen := make(map[ServerID]time.Time)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking of a much simpler implementation: iterate over current pods in the podToLRU in the indexer, and if that pod doesn't exist in ActivePods, remove. And this approach does not need a PodInactivityTimeout.

@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prefix-cache-scorer does not handle pod delete
6 participants