Skip to content

traffic splitting with session affinity #8167

Closed

Description

@vadimeisenbergibm

Can Envoy perform traffic splitting while preserving session affinity? For example, use Ring Hash or Maglev to select the weighted cluster according to its weight? This way, when route.RouteAction.HashPolicy is specified, the same weighted cluster and the same endpoint point will be used by applying Ring Hash/Maglev twice, for selecting the weighted cluster and for selecting the endpoint.

Activity

  1. added
    question
    on Sep 6, 2019
  2. zuercher commented on Sep 6, 2019

    @zuercher
    Member

    This isn't currently possible. Weighted clusters are chosen based on a random value selected at request time. I'll go ahead and label this as an enhancement request.

  3. added
    enhancement
    help wanted
    and removed
    question
    on Sep 6, 2019
  4. vadimeisenbergibm commented on Sep 6, 2019

    @vadimeisenbergibm
    ContributorAuthor

    @zuercher Thanks!

  5. changed the title [-]Question: traffic splitting with session affinity[/-] [+]traffic splitting with session affinity[/+] on Sep 6, 2019
  6. temporafugiunt commented on Sep 12, 2019

    @temporafugiunt

    @zuercher Is the behavior I outline below expected when using weighted traffic splitting or am I doing something wrong? Here is my real world example of what I am seeing with a kubernetes cluster using Istio / Envoy with weighted traffic splitting turned on to attempt to perform "canary testing" of a new version of a web application.

    I have two different versions of my web app which "compile" random names for JavaScript files using WebPack to kill caching between versions. If my route changes mid download of a JS file (which it appears it does as this is the behavior I am seeing) the file may or may not exist in the version I have just switched to because it might have a different name so it terminates downloading with only a partial file. The call succeeds with 200 but the contents are incomplete.

    Even if it didn't the contents of the file could change between versions so if it can't choose a service subset at first request and stick to that subset during subsequent calls during the same page load then I could essentially be downloading a file whose contents change mid stream maybe?

    Would you expect this given the nature of what I am trying to do and given that Envoy does not support session affinity with weight based traffic splitting, or am I just neglecting something or is Istio not supporting something yet perhaps?

  7. zuercher commented on Sep 12, 2019

    @zuercher
    Member

    The weighted cluster choices are made per-request even if the requests are sent on the same connection.

    The call succeeds with 200 but the contents are incomplete.

    That doesn't sound like a weighted cluster routing problem. It sounds like either the upstream server itself is truncating the data or something about how you're updating Envoy's config is causing a problem. I would look at Envoy's log to see what's going on.

    Even if it didn't the contents of the file could change between versions so if it can't choose a service subset at first request and stick to that subset during subsequent calls during the same page load then I could essentially be downloading a file whose contents change mid stream maybe?

    Envoy does not have support for session affinity built in. Imagine a downstream's first request retrieves v1 of an HTML page from cluster A (as a result of a weighted cluster choice). If that HTML contains a reference to app.js it is entirely possible that the request for app.js will be be sent to cluster B (based on a second weighted cluster choice) resulting in a mismatch. If the javascript's path changes from version to version you'd get a 404 (proxied from the upstream) when the mismatch occurs.

    In the past, I've achieved session affinity in Envoy with 3 routes:

    1. A route that matches on a Cookie header/value for v1 and routes to only the v1 cluster.
    2. A route that matches on a Cookie header/value for v2 and routes to the only v2 cluster.
    3. A route that makes a weighted cluster choice between v1 and v2 and uses response_headers_to_add to set a Set-Cookie header for the selected cluster.

    This means that x% of your new sessions will see the canary version, which is a bit different that x% of requests. Also, when you're done with the canary (completed deployed or rolled back) you'll need a way to get the clients on the other version to reload (or keep it running until it happens organically).

  8. kyessenov commented on Sep 12, 2019

    @kyessenov
    Contributor

    I think the request is using a normalized hash function instead of the random coin. As long as the hash function output is uniformly distributed, it's the same thing. We can probably compose a cryptographic function on top of the hash policy to guarantee one-way properties.

  9. zuercher commented on Sep 13, 2019

    @zuercher
    Member

    That seems like a reasonable feature to add.

  10. temporafugiunt commented on Sep 13, 2019

    @temporafugiunt

    @zuercher Thank you, that is a good idea and I will try that!

    That doesn't sound like a weighted cluster routing problem. It sounds like either the upstream server itself is truncating the data or something about how you're updating Envoy's config is causing a problem. I would look at Envoy's log to see what's going on.

    Sorry for the n00b question... But can you recommend any good documentation resources on how to debug envoy to determine root cause for an issue like this? If not I will have a discussion with Dr. Google for a while to see if I can find something.

  11. zuercher commented on Sep 13, 2019

    @zuercher
    Member

    I would enable debug logging (-l debug). You should be able to see the request and response headers for both the downstream and upstream requests. Beyond that, you might have better luck asking in the Envoy slack channel (with logs & config snippets) or else opening a separate issue.

  12. vietwow commented on Dec 15, 2019

    @vietwow

    Hi, any news for this feature ?

  13. Jeskz0rd commented on Jan 23, 2020

    @Jeskz0rd

    Any suggestions for a workaround? 🤔

  14. 18 remaining items

  15. gongzh commented on Sep 15, 2021

    @gongzh

    Hi, just commenting to show interest for this feature. The use case would be with experimentation. Traffic should be split between control and variant models/apps and users must be directed to a consistent variant. Bucketing is based on a user id header.

    Hello, is there any progress or plan on this feature? thanks!

  16. mksha commented on Oct 6, 2021

    @mksha

    @alyssawilk anyone working on it?

  17. alyssawilk commented on Oct 6, 2021

    @alyssawilk
    Contributor

    No one is assigned which is a pretty good sign that no one is working on this :-)

  18. mksha commented on Oct 6, 2021

    @mksha

    is there a plan to work on it, bec its very generic usecase for everyone.

  19. alyssawilk commented on Oct 6, 2021

    @alyssawilk
    Contributor

    The Envoy project doesn't have paid developers, it is an open source community where anyone can contribute. So largely features don't happen until someone wants them enough to implement them or pay someone like Tetrate to do so.

  20. mksha commented on Feb 7, 2022

    @mksha

    @rootsongjc Do we have this feature in upstream now?

  21. rootsongjc commented on Feb 8, 2022

    @rootsongjc
    Member

    @mksha I don't think so.

  22. jcometki commented on Feb 22, 2022

    @jcometki

    I had this same issue, I solved that with the following configuration:

    apiVersion: networking.istio.io/v1beta1
    kind: VirtualService
    metadata:
      name: sample-virtual-service
    spec:
      gateways:
        - default
      hosts:
        - sample-host
      http:
        - match:
            - headers:
                Cookie:
                  regex: .*userAffinity=v1.*
          route:
            - destination:
                host: sample-host.svc.cluster.local
                port:
                  number: 80
                subset: v1
        - match:
            - headers:
                Cookie:
                  regex: .*userAffinity=v2.*
          route:
            - destination:
                host: sample-host.svc.cluster.local
                port:
                  number: 80
                subset: v2
        - route:
            - destination:
                host: sample-host.svc.cluster.local
                port:
                  number: 80
                subset: v1
              weight: 75
            - destination:
                host: sample-host.svc.cluster.local
                port:
                  number: 80
                subset: v2
              headers:
                response:
                  add:
                    Set-Cookie: userAffinity=v2; Max-Age=3600000
              weight: 25
    ---
    apiVersion: networking.istio.io/v1beta1
    kind: DestinationRule
    metadata:
      name: sample-destination-rule
    spec:
      host: sample-host.svc.cluster.local
      subsets:
        - labels:
            app: sample-app-v1
          name: v1
          trafficPolicy:
            loadBalancer:
              consistentHash:
                httpCookie:
                  name: userAffinity=v1
                  ttl: 1h
        - labels:
            app: sample-app-v2
          name: v2
  23. mksha commented on Feb 22, 2022

    @mksha

    @jcometki We have something similar in place, but i have a question about DestinationRule that you have, May I know what is the need of having name: userAffinity=v1 rather than just name: userAffinity
    Ideally name property is to represent name of the cookie but the name:value pair. May be I am missing something, but would love to understand your point as well.

  24. itnazeer commented on Apr 27, 2022

    @itnazeer

    Did any one get this working?

  25. 4meepo commented on Apr 27, 2022

    @4meepo

    Any updates or workaround? : )

  26. zuercher commented on Apr 28, 2022

    @zuercher
    Member

    I'm going to close this ticket. Many of the recent comments have been for projects that build on Envoy and as such aren't really appropriate here.

    See https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto.html#config-route-v3-routeaction-hashpolicy-cookie and https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/stateful_session_filter#config-http-filters-stateful-session for various types of session affinity that are currently supported. The former implements the feature originally requested.

  27. rixongary commented on Feb 27, 2024

    @rixongary

    @jcometki hello. thanks for the config you posted above. I know this was 2 years ago now, but I am wondering if you could provide any more information on how this worked out for you?

    I think there would be a problem where once a user hits the v2 subset and gets the cookie, all of their subsequent requests would be sent to v2, but those requests would not be taken into account for weighting calculations, therefore, you would end up with more than 5% of requests going to the v2 subset, and this problem would get worse and worse the higher the canary weight was set.

    If anyone has a solution for this, I'd love to hear. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions