envoyproxy / envoy

Cloud-native high-performance edge/middle/service proxy
https://www.envoyproxy.io
Apache License 2.0
24.8k stars 4.77k forks source link

Support sticky_session when using weighted_clusters #29027

Open Schtil opened 1 year ago

Schtil commented 1 year ago

You cannot use sticky sessions when using weighted_clusters. Any hash_policy and lb_policy are ignored(

Configuration example:

static_resources:
  listeners:
  - name: echo_server
    address:
      socket_address:
        address: 0.0.0.0
        port_value: 8080
    filter_chains:
    - filters:
      - name: envoy.filters.network.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          route_config:
            name: ingress_all_routes
            virtual_hosts:
            - name: echo_server
              domains: ['*']
              routes:
              - match:
                  prefix: /
                route:
                  timeout: 30s
                  hash_policy:
                  - header:
                      header_name: "x-request-id"
                  weighted_clusters:
                    runtime_key_prefix: routing.traffic_split.echo_server-all
                    clusters:
                      - name: echo_server-vm2
                        weight: 50
                      - name: echo_server-vm1
                        weight: 50
clusters:
  - name: echo_server-vm1
    type: STRICT_DNS
    lb_policy: RING_HASH
    dns_lookup_family: V4_ONLY
    connect_timeout: 30s
    load_assignment:
      cluster_name: echo_server-vm1
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: localhost
                port_value: 8000
  - name: echo_server-vm2
    type: STRICT_DNS
    lb_policy: RING_HASH
    dns_lookup_family: V4_ONLY
    connect_timeout: 30s
    load_assignment:
      cluster_name: echo_server-vm2
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: localhost
                port_value: 8001

And with 50 requests for the format: curl localhost:8080 --header 'x-request-id: 26efbc98-3b7d-11ee-be56-0242ac120002' Requests are distributed among two clusters rather than one cluster

Schtil commented 1 year ago

I found similar questions https://github.com/envoyproxy/envoy/issues/7276

My question is more like a feature request than a bug)

yanavlasov commented 1 year ago

This feature has been requested before, however nobody found time to implement it. Marking as a feature request.

Tratcher commented 1 month ago

Similar to https://github.com/envoyproxy/envoy/issues/24741 which uses session affinity.