fluxcd / flagger

Progressive delivery Kubernetes operator (Canary, A/B Testing and Blue/Green deployments)
https://docs.flagger.app
Apache License 2.0
4.93k stars 737 forks source link

sessionAffinity stickiness communication #1532

Open takezyou opened 1 year ago

takezyou commented 1 year ago

Describe the feature

I would like to solve one problem with sessionAffinity functionality.

Canary status:

If sessionAffinity is enabled in this state, a cookie will be given when traffic flows to canary, and canary traffic will increase. Therefore, the traffic will gradually stop flowing to the primary.

I would like to achieve stickiness communication: once traffic flows to primary, it will continue to flow to primary for a certain period of time, and once traffic flows to canary, it will continue to flow to canary for a certain period of time.

This idea is based on the Akamai ALB and AWS ALB sticky setup.

ref.

Proposed solution

I am wondering if it is possible to achieve stickiness communication by giving a cookie to the primary as well, using the following method.

sessionAffinity:
  primary:    
    cookieName: flagger-primary
    maxAge: 86400
  canary:
    cookieName: flagger-canary
    maxAge: 86400
spec:
  hosts: []
  http:
  - match:
    - headers:
        Cookie:
          regex: .*flagger-canary.*kkuchhkCku.*
    name: sticky-route-canary
    route:
    - destination:
        host: primary
      weight: 0
    - destination:
        host: canary
      weight: 100
    timeout: 3.5s
  - match:
    - headers:
        Cookie:
          regex: .*flagger-primary.*fdakljdfa.*
    name: sticky-route-primary
    route:
    - destination:
        host: primary
      weight: 100
    - destination:
        host: canary
      weight: 0
    timeout: 3.5s
  - route:
    - destination:
        host: primary
      headers:
        response:
          add:
            Set-Cookie: flagger-primary=fdakljdfa; Max-Age=86400
      weight: 50
    - destination:
        host: canary
      headers:
        response:
          add:
            Set-Cookie: flagger-canary=kkuchhkCku; Max-Age=86400
      weight: 50

I would like to know if you have any other good solutions.

aryan9600 commented 1 year ago

This is not a problem with the session affinity functionality, it was designed this way on purpose. The idea is to prevent users from switching back to the primary after they have been directed to the canary. We don't want to keep users stuck to the primary.

takezyou commented 1 year ago

@aryan9600 Thanks for your reply. I understood that it is an intentional design of session affinity. I would like to keep them in primary as well for the use case I have, would you consider such a feature?