Repository navigation
add stateful session load balancer support - #2469
ramaraochavali wants to merge 6 commits into
Conversation
Signed-off-by: Rama Chavali <[email protected]>
| // Path to set for the cookie. | ||
| string path = 2; | ||
| // Lifetime of the cookie. | ||
| google.protobuf.Duration ttl = 3 [(google.api.field_behavior) = REQUIRED]; |
There was a problem hiding this comment.
Sure. We can have.
There was a problem hiding this comment.
+1 on a TTL - probably short ( 1h ?)
There was a problem hiding this comment.
Assume this will not interfere with application cookie ttl
| }; | ||
|
|
||
| // Standard load balancing algorithms that require no tuning. | ||
| enum SimpleLB { |
There was a problem hiding this comment.
I am not sure moving these out is a backwards compatible change in proto?
There was a problem hiding this comment.
It is not actually
There was a problem hiding this comment.
Probably not - but why is it required for this PR ?
There was a problem hiding this comment.
Yes, it is not a must to change this.
You can just add the session sticky in
oneof lb_policy {
| // consistently till the backend host on which the session lives goes down. | ||
| message StatefulSession { | ||
| // Load balancer to use for the initial request, before a session is established. | ||
| SimpleLB load_balancer = 1; |
There was a problem hiding this comment.
from envoy doc
HTTP session stickiness in Envoy is generally achieved through hash-based load balancing.
There was a problem hiding this comment.
That is one of the benefits of using stateful session. See my comments above the field
and from Envoy docs
The case where a non hash-based load balancer (Random, Round Robin, etc.) is used and session stickiness is still required. If stateful sessions are enabled in this case, requests for new sessions will be routed to the corresponding upstream host based on the result of load balancing. Requests belonging to existing sessions will be routed to the session’s upstream host.
There was a problem hiding this comment.
My understanding is that the 2 features are separated - use hash load balancer for affinity, use the cookie for exact routing together with another load balancer.
Using both cookie and hash is probably possible but doesn't make a lot of sense.
There was a problem hiding this comment.
@costinm statefull affinity feature is orthogonal to LB choice. Theoretically it should be usable with any LB, including the hash-based algorithms. This is because hash-based LB algorithms only provide "soft-affinity", I.e. when the backend set changes, at least 1/N of the sessions will land on new backend hosts which will break affinity.
There was a problem hiding this comment.
I understand - my point was that there is little reason to use hash-based affinity when session is enabled ( since it provides even stronger stickiness). It is better to combine 'stateful session' with load-based or random or one of the other LBs.
Hash would work - just don't think it's a good choice.
| }; | ||
|
|
||
| // StatefulSession load balancer load balances across backend hosts using 'strong' stickiness. | ||
| // This load balancer enforces stable session stickiness by routing requests to the same backend |
There was a problem hiding this comment.
In the case one backend instance is down, how will this work? I do not see any explicitly saying about this
There was a problem hiding this comment.
TL;DR; The destination is encoded in the cookie and will be routed irrespective of other nodes going down,
There was a problem hiding this comment.
Not sure i can get the answer, i am asking if the one that session indicates is down. How does envoy do
There was a problem hiding this comment.
And a further question, what if the instance is down and actually not in the eds?
There was a problem hiding this comment.
when the instance that hosts the session is down, session is recreated on another node.
There was a problem hiding this comment.
is recreated on another node - using the LB policy in effect. Sticky/stateful just means 'original dest' routing is used
when the cookie with the IP is present, otherwise regular LB takes place.
| // Name of the cookie. | ||
| string name = 1 [(google.api.field_behavior) = REQUIRED]; | ||
| // Path to set for the cookie. | ||
| string path = 2; |
There was a problem hiding this comment.
I think the main problem is path.
Normally in envoy session affinity can be set in routes - so map /example to example.ns.svc, and the path of the cookie will be set to /example
If another route /example2 is also pointing to example.ns - the path will have to be /example2.
In Istio, having the path in DR - which is associated with a destination - it is not possible to do that.
With the Gateway API, sticky session would be attached to a route - and we could generate a working config by setting a per route config.
Please add a lot of docs on this field - with examples and what is not possible ( effectively a destination can only be mapped to a single path ).
This is very important because you may have
example.com/example -> example.svc - with stickyEndpoint1
example.com/admin -> admin.svc with stickyEndpoint2.
The admin and example can't have same path - and path can't be set to "/" unless there is a single service using sticky sessions.
There was a problem hiding this comment.
I would rather not have path in the API then have it broken and confusing. Without path - we use "/", and it works as expected for normal mesh calls ( as long as user doesn't have routes that redirect to multiple backends ), and is mostly broken for ingress ( only one of the backends for a hostname can be sticky )
|
Specifically document the difference between consistentHash would be nice
as well
…On Wed, Aug 31, 2022 at 12:02 PM Costin Manolache ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In networking/v1alpha3/destination_rule.proto
<#2469 (comment)>:
> @@ -444,6 +444,51 @@ message Subset {
TrafficPolicy traffic_policy = 3;
}
+// Describes a HTTP cookie that will be used for session stickiness.
+// If the cookie is not present, it will be generated.
+message HTTPCookie {
+ // Name of the cookie.
+ string name = 1 [(google.api.field_behavior) = REQUIRED];
+ // Path to set for the cookie.
+ string path = 2;
+ // Lifetime of the cookie.
+ google.protobuf.Duration ttl = 3 [(google.api.field_behavior) = REQUIRED];
+};
+
+// Standard load balancing algorithms that require no tuning.
+enum SimpleLB {
Probably not - but why is it required for this PR ?
—
Reply to this email directly, view it on GitHub
<#2469 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEYGXOUXFCDMVWAMXPTVKDV36T3PANCNFSM6AAAAAAQAIAG54>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
| oneof lb_policy { | ||
| SimpleLB simple = 1; | ||
| ConsistentHashLB consistent_hash = 2; | ||
| StatefulSession stateful_session = 5; |
There was a problem hiding this comment.
I don't think this is correct. I would leave lb_policy as is - and add the stateful_session as a separate option, since it applies to any lb_policy. That doesn't require shuffling protos around and seems safer.
There was a problem hiding this comment.
I would check if consistent_hash is allowed with stateful_session - I don't see why not, AFAIK envoy will use the cookie if present or whatever LB is set.
There was a problem hiding this comment.
In gRPC the way it is proposed in https://github.com/grpc/proposal/blob/e49869d41d91ca5e0ea538c833a1480f90b348a0/A55-stateful-session-affinity.md the "child policy" could be consistent_hash (ring_hash) so if the cookie is not present it will go to the child policy
There was a problem hiding this comment.
That seems very reasonable - users who want sticky (stateful) sessions probably also want consistent_hash or maglev, and
that may use a different cookie or parameters.
|
On Wed, Aug 31, 2022 at 2:24 AM Zhonghu Xu ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In networking/v1alpha3/destination_rule.proto
<#2469 (comment)>:
> @@ -623,6 +624,19 @@ message LoadBalancerSettings {
uint64 minimum_ring_size = 4 [deprecated=true];
};
+ // StatefulSession load balancer load balances across backend hosts using 'strong' stickiness.
+ // This load balancer enforces stable session stickiness by routing requests to the same backend
And a further question, what if the instance is down and actually not in
the eds?
I think another important question: what if the instance is up - but not in
EDS ?
Does envoy do any checks to make sure this is not an open proxy - I hope
so, and it needs to be clearly
explained ( and tested !).
… —
Reply to this email directly, view it on GitHub
<#2469 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAUR2XXS3FLDIGTTYBB5ELV34QDZANCNFSM6AAAAAAQAIAG54>
.
You are receiving this because you were assigned.Message ID:
***@***.***>
|
|
|
IMO we should not mix LB - which selects an endpoint based on different rules, including affinity - with session stickiness, i.e. regardless of LB go to this specific IP:port. I did more research on how other implementations work - in particular when stickiness is exposed trough gateways or other A smaller PR with just 'enable sticky' and time would move faster and allow us to get feedback - we can add more later, it's harder |
| // Load balancer to use for the initial request, before a session is established. | ||
| SimpleLB load_balancer = 1; | ||
| // The session state to use. | ||
| oneof session_state { |
There was a problem hiding this comment.
this is not required too, add it when we need to support another option would not break compat
|
One more question - I've looked at proxyless gRPC and gateway use cases, the client or browser handles the cookie jar. For 'mesh' use case - is the client-side sidecar holding a cookie jar when making the requests ? Or does the user have to change their code to track cookies ? And if the client is gRPC ( with envoy sidecar for security/telemetry/etc - not proxyless ) - does gRPC use a cookie jar already ? If you find out - please add it to the comments, in particular if user code needs to track the cookie, I haven't figured it out from envoy docs. |
Yes. User code has to track the cookie. And we are supporting this envoyproxy/envoy#22475 in Envoy so that non browser based apps can use this header to track instead of cookie. |
I think leaving path seems OK. But name should be given. We can't assume/standarize the name from some annotations. If name is not given we can derive based on other infrastructure data as you mentioned. But for typical Istio/envoy use case, name is important |
|
@costinm I agree with most of the comments except the name of cookie. If we agree on that, I will delink it from LB policy and introduce statefulSesstion config, if provided, sticky ness would be enabled. |
|
Not sure using header instead of cookie helps much - most http clients have
support for cookie tracking, just has to be enabled - and I assume gRPC
will add some easy option if they support sticky sessions for proxyless
gRPC.
Cookie is a header too - so if an app can set a header, they can set a
cookie too.
I remember in Java it was a request parameter - jsessionid - and the cookie
name was also standardized. I'm not saying to hard code - just keep it in
meshConfig or some env variable. I would guess java applications will have
to use the name that is defined in the servlet spec ( or was 20 years ago,
I have a strong deja vue...). Concern is that each service defines a
different cookie and we end up with a mess. It may be a way around path
problems - I'm not completely opposed to customizing the cookie name, just
want to make sure we evaluate pros and cons.
…On Thu, Sep 1, 2022 at 10:00 PM Rama Chavali ***@***.***> wrote:
@costinm <https://github.com/costinm> I agree with most of the comments
except the name of cookie. If we agree on that, I will delink it from LB
policy and introduce statefulSesstion config, if provided, sticky ness
would be enabled.
—
Reply to this email directly, view it on GitHub
<#2469 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAUR2SDVQENFHWQH3SV2UTV4GCX7ANCNFSM6AAAAAAQAIAG54>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Signed-off-by: Rama Chavali <[email protected]>
|
@costinm changed. PTAL. |
costinm
left a comment
There was a problem hiding this comment.
Much better - left few cosmetic/docs comments and waiting for others to review, but I think it's pretty close.
| // Name of the cookie to be used. If not specified, environment specific | ||
| // configuration is used. | ||
| string name = 1; | ||
| // Session duration. If not specified, a duration of 1 hour is used. |
There was a problem hiding this comment.
Is it session duration or cookie duration ? Normally ( java ) the session can last indefinitely, as long as requests are received that refresh the cookie.
I would assume envoy does renew the cookie as well.
It is not very common or useful to have a limit on the entire session.
There was a problem hiding this comment.
you are right. It is duration of cookie.
| uint64 minimum_ring_size = 4 [deprecated=true]; | ||
| }; | ||
|
|
||
| // Stateful Session configuration. |
There was a problem hiding this comment.
Some more comments here on client changes requirement ( use a cookie jar ).
And maybe some mention this is mainly for service-to-service, the gateway behavior is not yet supported ( since a hostname may route to different backends - we don't have a way to represent this AFAIK, cookie is single IP for single cluster )
| // When the backend host that hosts the session goes down, sesion is recreated | ||
| // on another backend host. A new backend host is selected based on the the configured | ||
| // load balancer policy. | ||
| StatefulSession stateful_session_config = 5; |
There was a problem hiding this comment.
I am a bit allergic to using 'config', 'policy', 'data' as suffix to fields.
There is nothing on the API that is not a config - or used as policy or data.
There was a problem hiding this comment.
I wont increase your allergy :-)
| google.protobuf.Duration duration = 2; | ||
| } | ||
| // The session state to use. | ||
| oneof session_state { |
There was a problem hiding this comment.
I never understood oneof with a single value or all this nesting in protos.
Just one message - StatefulSession - with 2 fields ( duration, cookie_name ) would be easier to use and less confusing.
Nothing exclusive about having either cookie or header or request parameter, it is possible to configure more than one.
There was a problem hiding this comment.
Nothing exclusive about having either cookie or header or request parameter, it is possible to configure more than one.
Envoy does not support more than one https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/http/stateful_session/v3/stateful_session.proto#envoy-v3-api-field-extensions-filters-http-stateful-session-v3-statefulsessionperroute-stateful-session
There was a problem hiding this comment.
Envoy may not support more than one now - but I wouldn't design a long-term API around limitations on the first implementation.
Persistent sessions are not new - and it is clear other forms of tracking will need to be added, so better to have the correct API with comments explaining that current version of envoy only supports one. Note that the Istio APIs are not officially 'envoy only',
and we are starting to support the multi-vendor K8S Gateway APIs.
As an extra benefit - it would allow us to avoid the nested message and oneof which are pretty confusing for both devs and users.
There was a problem hiding this comment.
I am not saying Envoy may not support others. All I am saying the state would be exclusive i.e. either cookie or header or some thing else. But not combination of all. I can drop oneof here but I think nested message would help us to add oneof later if needed rather than spraying fields across.
There was a problem hiding this comment.
I would agree with removing oneof here. And once we need another option, we can add it back, which is compatable
Signed-off-by: Rama Chavali <[email protected]>
|
In my WIP PR the annotation is actually a label - x-session-cookie - but
was mostly a placeholder to get started.
It is not specific to proxyless gRPC or envoy - and based on the discussion
on your PR I think we should keep it as small as possible,
ie. just something like "networking.istio.io/peristent-session=ID" to
indicate the provider intent for clients to use persistent sessions for the
service ( and all its subsets - when Envoy is fixed to allow this), with
the documentation indicating implementation MAY use the ID
in cookie or header name, but without guarantees that it'll be the actual
cookie name, so future changes can be made.
I think there are few advantages:
- it avoids some confusion associated with DR - like client overrides,
merging, etc - the Service annotation is more clearly a property
of the service, indicating the associated workloads require and use
persistent sessions.
- it is very similar to what the other load balancers support
- should work as well for Gateway/GAMMA users without requiring istio APIs
- hopefully would be easier to promote to an "Gateway policy attachment" -
since most LB vendors support something similar.
I think 'official' labels and annotations also need to be defined in
https://github.com/istio/api/blob/master/annotation/annotations.yaml -
if John is ok with the annotation we can modify this PR to change that
field instead, to keep the comment history ?
For the annotation name bike-shedding, existing names I found are:
- nginx.ingress.kubernetes.io/affinity: "cookie" ( plus few more
annotations to specify the name, expires )
- traefik.ingress.kuberenetes.io/affinity: "true" ( plus "
trafik.ingress.kubernetes.io/session-cookie-name" )
- router.openshift.io/cookie_name: "name"
- run.googleapis.com/sessionAffinity: true - for CloudRun ( as an extension
to KNative service spec )
I personally think 'persistent session' is a better name than 'affinity'
since we already use affinity for the weaker variant, and
java has used this term since ~2000, but happy with any other name the
community want.
…On Mon, Sep 26, 2022 at 2:52 AM Rama Chavali ***@***.***> wrote:
How about first merging the other change in istio/istio, using an
annotation - and revisiting the DestinationRule after we have more usage
and feedback ?
I am fine with that. What does that annotation look like? And is it
implmemented only for proxyless gRPC or regular proxies? If it is
implemented (or planned to be implemented) for both - I am fine.
—
Reply to this email directly, view it on GitHub
<#2469 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAUR2RO3P43IFPGW34AY4LWAFW4BANCNFSM6AAAAAAQAIAG54>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Where would you apply the annotation to? Is this for a K8s Service or some other construct in Istio? |
|
Annotation will be on the Service.
The value of the annotation should be an ID that can be used to associate
different subsets - in Istio with DestinationRule it is not
a problem, we can define subsets from the same Service. In the K8S Gateway
the versions/subsets are each an individual Service.
In other words - for a set of workloads that are part of the persistent
session pool, the same ID ( and indirectly cookie/header name)
must be used and it should be shared by all Services or DRs that may
select subsets. We still need to make changes to
envoy to deal with an endpoint moving to a different Cluster - but at least
we'll have a way to associate all the clusters that
belong to the same persistent-session workload set.
…On Mon, Sep 26, 2022 at 5:00 PM Israel Shapiro ***@***.***> wrote:
the Service annotation is more clearly a property of the service,
indicating the associated workloads require and use persistent sessions.
Where would you apply the annotation to? Is this for a K8s Service or some
other construct in Istio?
If the former then Istio would still need to configure the clients through
xDS to inject and handle some sort of affinity tag (I.e. cookie). This also
means that two different service subsets must must still be defined by a
single K8s service, does it?
—
Reply to this email directly, view it on GitHub
<#2469 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAUR2WTRD3TVPWPMMUFPUDWAI2KBANCNFSM6AAAAAAQAIAG54>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I personally think 'persistent session' is a better name than 'affinity' I am fine with that. Should we use |
|
If we are bikeshedding -
https://istio.io/latest/docs/reference/config/annotations/ has existing
annotations, the prefix is all over the place,
with networking.istio.io, traffic.istio.io, traffic.sidecar.istio.io. I'm
not sure the prefix in front of istio.io helps much - I would just use
istio.io/persistent-session=true or istio.io/persistent-session-cookie=NAME
but I am ok with your proposed name too.
John, any preference ?
I am in doubt about how to express HOW the persistence will be implemented.
In Java the implementations are free to pick -
a client that doesn't support cookies may get the session using the query
param (?jsessionid=XXX), and we prototyped ( don't remember
if it was shipped ) tracking sessions based on TLS session ID from the
handshake.
Would be good to hear from potential users - is there a need to explicitly
control the cookie name ( for example if other infra or code
is generating the cookie ), or leave flexibility to the implementation and
just have a bool ( we can refine it and add more options when
the proper CRD is defined ) ?
…On Tue, Sep 27, 2022 at 11:25 PM Rama Chavali ***@***.***> wrote:
. For the annotation name bike-shedding, existing names I found are:
- nginx.ingress.kubernetes.io/affinity: "cookie" ( plus few more
annotations to specify the name, expires )
- traefik.ingress.kuberenetes.io/affinity: "true" ( plus "
trafik.ingress.kubernetes.io/session-cookie-name" )
- router.openshift.io/cookie_name: "name"
- run.googleapis.com/sessionAffinity: true - for CloudRun ( as an
extension
to KNative service spec )
I personally think 'persistent session' is a better name than 'affinity'
since we already use affinity for the weaker variant, and
java has used this term since ~2000, but happy with any other name the
community want.
I am fine with that. Should we use
traffic.istio.io/session-persistence-cookie and move forward?
—
Reply to this email directly, view it on GitHub
<#2469 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAUR2QYGMUHOWLXVBIYADLWAPQFPANCNFSM6AAAAAAQAIAG54>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
From API perspective ( and how persistent sessions work with other serves )
- both header and cookie ( and other forms like TLS session ID, request
parameter,
etc) can be used.
The doc should mention that envoy currently supports only one. There is no
reason to believe it is impossible for envoy
to support multiple, and we should not design the API based on an envoy
limitation.
…On Tue, Sep 6, 2022 at 8:43 AM Rama Chavali ***@***.***> wrote:
how do you specify either cookie or header can be set but not both?
persistentSession:
cookie: JESSIONID
header: foo
Are you saying, we will document that but not enforce via protobuf?
—
Reply to this email directly, view it on GitHub
<#2469 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAUR2T5R3KKLN4O2PGBCTTV45RCJANCNFSM6AAAAAAQAIAG54>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
@costinm @howardjohn any suggestions on annotation naming? I would like to move them to annotations and implement it. |
|
I merged istio/istio#40660 - it has an
implementation for proxyless gRPC.
It would be great if you can use the same label and implement it in envoy,
happy to make changes as well.
…On Fri, Oct 21, 2022 at 12:25 AM Rama Chavali ***@***.***> wrote:
@costinm <https://github.com/costinm> @howardjohn
<https://github.com/howardjohn> any suggestions on annotation naming? I
would like to move them to annotations and implement it.
—
Reply to this email directly, view it on GitHub
<#2469 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAUR2W5VI7C46PQA4O4TOTWEJAQFANCNFSM6AAAAAAQAIAG54>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
@ramaraochavali: PR needs rebase. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@wbpcode have you been able to try it? Are there any plans to add support for weighted clusters? Any idea what changes would be required? |
|
Any idea when this can be merged ? |
|
PR needs rebase. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@ramaraochavali: The following tests failed, say
DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
|
i will open a fresh PR |
API support needed for istio/istio#39740 and istio/istio#37910