xds: parse HttpFault filter from LDS/RDS response#7841
xds: parse HttpFault filter from LDS/RDS response#7841dapengzhang0 merged 7 commits intogrpc:masterfrom
Conversation
| static final String TRANSPORT_SOCKET_NAME_TLS = "envoy.transport_sockets.tls"; | ||
| static final String HTTP_FAULT_FILTER_NAME = "envoy.fault"; | ||
| @VisibleForTesting | ||
| static boolean enableFaultInjection = |
There was a problem hiding this comment.
Why define the env var here? You can alway parse configurations regardless the feature is turned on or not. It should be used to gate the feature implementation (in XdsNameResolver).
There was a problem hiding this comment.
I have thought about this and felt EnvoyProtoData is a better location than XdsNameResolver. Because it's also awkward to define the flag in XdsNameResolver:
- either
EnvoyProtoDatawill be depending onXdsNameResolver - or
XdsNameResolvercan not gate the feature because if the env var is false but EnvoyProtoData parsing the fault proto returns an error, xds will fail because of the error. - or pass a flag in the args of
StructOrError<Route> EnvoyProtoData.fromEnvoyProtoRoute()
I'm also considering to group all env variables to a class XdsEnv, WDYT?
There was a problem hiding this comment.
I don't think we should couple response parsing with specific features. We should just parse whatever data we want from response messages based on our development stage, but not based on what features we are releasing. A invalid configuration is always invalid. I believe most importantly we are using env var to gate our implementation codepath, because we have not tested that and it could be buggy/wrong. We do not want code to execute branches implementing the feature. Ideally, it should gate both name resolver's code and response parsing code. But, the parsing code is more mechanical and less critical, plus we aren't applying any of our own feature-specific logic to the parsing. The fault inject configurations are either absent or being valid.
group all env variables to a class XdsEnv
That sounds a horrible idea, at least for Java (like our existing XdsLbPolicies, it's horrible Java). Those env vars aren't related to other, we shouldn't just dump everything together just because we want easy references.
There was a problem hiding this comment.
Parse proto regardless of feature flag now.
|
|
||
| static StructOrError<HttpFault> decodeFaultFilterConfig(Any rawFaultFilterConfig) { | ||
| if (rawFaultFilterConfig.getTypeUrl().equals( | ||
| "type.googleapis.com/envoy.config.filter.http.fault.v2.HTTPFault")) { |
There was a problem hiding this comment.
nit: define constants for these type urls.
There was a problem hiding this comment.
Well, this is style preference 😛. If the constant is used only one place in the main code then I don't favor static constant as this is more straightforward.
There was a problem hiding this comment.
There is little to do with being used once or multiple times.
This string is long. Also more importantly, this is something coming from the xDS API definition, instead of something that the implementer comes up with. So declaring it as a constant on the top is much readable and understandable for readers.
There was a problem hiding this comment.
I disagree. Declaring it as a constant adds an extra indirection and it's less readable than put it inline. An inline constant is still a constant. There is little to do with the string being long or short, unless it has too many lines.
There was a problem hiding this comment.
Still, I am not in favor of having these two String literals used here. It looks so messy. We've been doing the conventional way in XdsClient. This is really bad.
| hasFaultInjection = true; | ||
| if (httpFilter.hasTypedConfig()) { | ||
| StructOrError<HttpFault> httpFaultOrError = | ||
| decodeFaultFilterConfig(httpFilter.getTypedConfig()); |
There was a problem hiding this comment.
nit: do not statically import methods. Also, shouldn't this be EnvoyProtoData.HttpFault. fromEnvoyProtoHttpFault()? EnvoyProtoData should not expose any static method for other external classes to use, as in the future we may want to move each individual data type into its own file.
There was a problem hiding this comment.
Refactored to EnvoyProtoData.HttpFault. decodeFaultFilterConfig().
Parse HTTPFault from 4 possible places:
EnvoyProtoData.HttpFaultwill be a field ofLdsUpdateEnvoyProtoData.HttpFaultwill be a field ofEnvoyProtoData.VirtualHostEnvoyProtoData.HttpFaultwill be a field ofEnvoyProtoData.RouteEnvoyProtoData.HttpFaultwill be a field ofEnvoyProtoData.ClusterWeightDesign doc: grpc/proposal#201