Skip to content

Ring Hash consistent traffic splitting between multiple upstreams #7276

Closed

Description

@Stoakes

Hello,

I'm trying to consistently split traffic between multiple upstreams to do some canary release. However, I can't get ring hash based on header working with weighted_cluster: for a given header value, queries are not always routed to the same cluster. Istio and Ambassador have this feature, so I guess it's possible with Envoy standalone.

I've been looking through code and doc for a while but I can't figure out what is wrong with the following configuration.

Here is a small docker-compose file reproducing my setup and its configuration.
The expected behaviour would be that for a given header for i in {1..20}; do curl -H "x-userid: aGivenHeaderValue" localhost:8080/weighted/consistent; done returns always the same version number.

#docker-compose.yaml
version: "3"
services:
  envoy:
    image: envoyproxy/envoy-alpine:v1.10.0
    volumes:
      - ./envoy.yaml:/etc/envoy/envoy.yaml
    ports:
      - "8080:8080"
      - "8081:8081"
    command: "/usr/local/bin/envoy --config-path /etc/envoy/envoy.yaml --mode serve --service-cluster envoy"
  helloweb1:
    image: gcr.io/google-samples/hello-app:1.0
  helloweb2:
    image: gcr.io/google-samples/hello-app:2.0
#envoy.yaml
static_resources:
  listeners:
  - address:
      socket_address:
        address: 0.0.0.0
        port_value: 8080
    filter_chains:
    - filters:
      - name: envoy.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
          codec_type: auto
          stat_prefix: ingress_http
          route_config:
            name: local_route
            virtual_hosts:
            - name: backend
              domains:
              - "*"
              routes:
              - match:
                  prefix: /weighted/consistent
                route:
                    weighted_clusters:
                      clusters:
                      - name: helloweb1
                        weight: 80
                      - name: helloweb2
                        weight: 20
                    hash_policy:
                    - header:
                        header_name: x-userid
                
          http_filters:
          - name: envoy.router
            typed_config: {}
  clusters:
  - name: helloweb1
    connect_timeout: 0.5s
    type: strict_dns
    lb_policy: RING_HASH
    load_assignment:
      cluster_name: helloweb1
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: helloweb1
                port_value: 8080
  - name: helloweb2
    connect_timeout: 0.5s
    type: strict_dns
    lb_policy: RING_HASH
    load_assignment:
      cluster_name: helloweb2
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: helloweb2
                port_value: 8080

admin:
  access_log_path: /dev/null
  address:
    socket_address:
      address: 0.0.0.0
      port_value: 8081

Probably useless in this case, but here is the /server_info output:

$ curl localhost:8081/server_info
{
 "version": "e95ef6bc43daeda16451ad4ef20979d8e07a5299/1.10.0/Clean/RELEASE/BoringSSL",
 "state": "LIVE",
 "command_line_options": {
  "base_id": "0",
  "concurrency": 8,
  "config_path": "/etc/envoy/envoy.yaml",
  "config_yaml": "",
  "allow_unknown_fields": false,
  "admin_address_path": "",
  "local_address_ip_version": "v4",
  "log_level": "info",
  "component_log_level": "",
  "log_format": "[%Y-%m-%d %T.%e][%t][%l][%n] %v",
  "log_path": "",
  "hot_restart_version": false,
  "service_cluster": "envoy",
  "service_node": "",
  "service_zone": "",
  "mode": "Serve",
  "max_stats": "16384",
  "max_obj_name_len": "60",
  "disable_hot_restart": false,
  "enable_mutex_tracing": false,
  "restart_epoch": 0,
  "cpuset_threads": false,
  "file_flush_interval": "10s",
  "drain_time": "600s",
  "parent_shutdown_time": "900s"
 },
 "uptime_current_epoch": "109s",
 "uptime_all_epochs": "109s"
}

Thank you for your help

Activity

  1. added
    question
    on Jun 14, 2019
  2. mattklein123 commented on Jun 14, 2019

    @mattklein123
    Member

    Consistent hashing works only within a cluster today, not across weighted clusters. This would be a different feature request.

  3. stale commented on Jul 14, 2019

    @stale

    This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.

  4. added
    stale
    on Jul 14, 2019
  5. Stoakes commented on Jul 15, 2019

    @Stoakes
    Author

    Ok, thank you for your answer and good luck for the upcoming work on Envoy, it's a great project !

  6. Stoakes commented on Sep 7, 2019

    @Stoakes
    Author

    For anyone interested in the topic, #8167 deals with it too.

  7. temporafugiunt commented on Sep 12, 2019

    @temporafugiunt

    This is affecting weighted traffic splitting in Istio as well, istio/istio#9764

  8. Moisi commented on Aug 26, 2023

    @Moisi

    newbie followup question: why is the hash-policy part of the route and not the cluster ? I was surprised to find this out. I with it would be documented better ... still need to take a look at the tests for this. but still.

  9. ktalg commented on Nov 6, 2023

    @ktalg
    Contributor

    newbie followup question: why is the hash-policy part of the route and not the cluster ? I was surprised to find this out. I with it would be documented better ... still need to take a look at the tests for this. but still.

    Because envoy's configuration is divided into 2 parts: upstream and downstream, the former is responsible for handling traffic matching and processing, while the latter maintains information about the target instance, the hash policy belongs to the former configuration item

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

    questionstale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions