-
Notifications
You must be signed in to change notification settings - Fork 8
Session affinity scorer #117
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
Session affinity scorer #117
Conversation
dmitripikus
commented
May 4, 2025
- Session affinity scorer implementation
- Fix in request headers transfer
* dev: Added a simple unit test for the PostResponse plugin invocation Invoke the PostResponse handlers and send any added headers to the user Added code to scheduler to enable running the PostResponse plugins Use an init() function instead of modifying the scheduler code to inject our config Added PostResponse to scheduler config Fixed scorer tests
} | ||
|
||
func (s *SessionAffinityScorer) Name() string { | ||
return "session affinity scorer" |
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.
s/session affinity scorer/session-affinity-scorer/ for alignment with other scorers.
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.
fixed, thanks
// session was sent to, by giving that pod the specified weight and assigning | ||
// zero score to the rest of the targets | ||
type SessionAffinityScorer struct { | ||
sessions *sync.Map |
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 field is never used.
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.
fixed, thanks
@@ -74,3 +74,8 @@ type PostResponse interface { | |||
Plugin | |||
PostResponse(ctx *types.SchedulingContext, pod types.Pod) | |||
} | |||
|
|||
type ScorerWithPostResponse struct { |
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 struct is redundant
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.
fixed, thanks
sessions: &sync.Map{}, | ||
} | ||
return plugins.ScorerWithPostResponse{ | ||
Scorer: s, |
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.
if you remove the struct from prev comment, then here just return s
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.
fixed, thanks
reqHeaders := ctx.Req.Headers | ||
|
||
var sessionId = "" | ||
for k, v := range reqHeaders { |
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 foor loop is very inefficient. headers field is a map (hash), means we can check if key exists in O(1) without iteration over all keys
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.
fixed, thanks
|
||
func (s *SessionAffinityScorer) PostResponse(ctx *types.SchedulingContext, pod types.Pod) { | ||
ctx.MutatedHeaders[sessionIDHeader] = encode(pod.GetPod().NamespacedName.String()) | ||
} |
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.
is this a temp hack?
it puts as session id the namespaced name of the pod (encoded).
meaning different requests that are served by the same pod get the same value, which is not unique (not ID)
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.
Right, it's not a session Id, but a session token. I'll rename the header to Session-Token
- Map fetch is done instead of loop
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.
/lgtm
/approve
Thanks Dima!
* 'session affinity scorer' partial implementation (without headers in response) * Fix in filling request headers * Encoded value of namespaced pod name is sent in response to client * Support of session affinity scorer configuration via environment variables, is added * Go file for session affinity scorer is renamed * Redundant 'sessions' field is removed * Redundant 'ScorerWithPostResponse' struct is removed * - SessionID is renamed to sessionToken - Map fetch is done instead of loop * Session token name is changed to 'x-session-token' * Minor fixes are made in README * Small fix after merge --------- Co-authored-by: Shmuel Kallner <kallner@il.ibm.com>
* 'session affinity scorer' partial implementation (without headers in response) * Fix in filling request headers * Encoded value of namespaced pod name is sent in response to client * Support of session affinity scorer configuration via environment variables, is added * Go file for session affinity scorer is renamed * Redundant 'sessions' field is removed * Redundant 'ScorerWithPostResponse' struct is removed * - SessionID is renamed to sessionToken - Map fetch is done instead of loop * Session token name is changed to 'x-session-token' * Minor fixes are made in README * Small fix after merge --------- Co-authored-by: Shmuel Kallner <kallner@il.ibm.com>
* 'session affinity scorer' partial implementation (without headers in response) * Fix in filling request headers * Encoded value of namespaced pod name is sent in response to client * Support of session affinity scorer configuration via environment variables, is added * Go file for session affinity scorer is renamed * Redundant 'sessions' field is removed * Redundant 'ScorerWithPostResponse' struct is removed * - SessionID is renamed to sessionToken - Map fetch is done instead of loop * Session token name is changed to 'x-session-token' * Minor fixes are made in README * Small fix after merge --------- Co-authored-by: Shmuel Kallner <kallner@il.ibm.com>