Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[thrift_proxy] Add metadata_match to RouteAction and WeightedClusters #4402

Merged

Conversation

brirams
Copy link
Contributor

@brirams brirams commented Sep 11, 2018

Description
This change adds the ability to attach metadata to the clusters and weighted clusters to allow users to filter a down to instances that match metadata criteria provided. This is used only when the subset load balancer is enabled and leverages what exists already for http metadata matching.

Changes include:

  • moving implementation for http MetadataMatchCriteriaImpl into a single file
  • using that in the thrift router
  • construct MetadataMatchCriteria objects from protobufs
  • expose through Thrift::Router::RouteEntry and use in router impl

Risk Level: LOW
Testing: tests, new and old, pass
Docs Changes: added description for new proto fields. docs build successfully.

- add to proto definition
- add BUILD dependency to MetadataMatchCriteria[Impl]
- add fields to RouteEntryImplBase, add method to RouteEntry interface

Signed-off-by: Brian Ramos <[email protected]>
- Keep track of parent RouteEntryImplBase into WeightedClusterEntry to
  support metadataMatchCriteria implementation. Use parent's metadata
  when none provided in WeightedClusterEntry
- use route_entry's metadataMatchCriteria for Router's
  LoadBalanceContext metadataMatchCriteria
- formatting fixes

Signed-off-by: Brian Ramos <[email protected]>
- move implementation of a method into the header file. rearrange
  header file to make it actually work.
- move BUILD deps around to depend on interface vs. implementation
  appropriately
- update mocks to support new RouteEntry method

Signed-off-by: Brian Ramos <[email protected]>
- WeightedClusterEntries were being constructed before metadata_match
  for a RouteAction was created, resulting in the merging
  functionality not working. Fixed
- test various cases
- format everything

Signed-off-by: Brian Ramos <[email protected]>
Signed-off-by: Brian Ramos <[email protected]>
// Optional endpoint metadata match criteria. Only endpoints in the upstream
// cluster with metadata matching that set in metadata_match will be
// considered. Keys and values should be provided under the "envoy.lb" metadata key. Note that
envoy.api.v2.core.Metadata metadata_match = 3;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this got copied from the RDS route.proto, but we should probably make clear that this only applies to the subset load balancer. So like

Optional endpoint metadata match criteria used by subset load balancer.

Also, there's a dangling "Note that" at the end of the comment.

// this will be merged with what's provided in :ref: `RouteAction.Metadata
// <envoy_api_field_config.filter.network.thrift_proxy.v2alpha1.RouteAction.metadata_match>`,
// with values here taking precedence.
envoy.api.v2.core.Metadata metadata_match = 3;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same bit about subset load balancer here.

v3.set_string_value("v3");
HashedValue hv1(v1), hv2(v2), hv3(v3);

// match with multiple weighted cluster metatada criterions defined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*metadata criteria

@@ -212,43 +212,6 @@ HashPolicyImpl::generateHash(const Network::Address::Instance* downstream_addr,
return hash;
}

std::vector<MetadataMatchCriterionConstSharedPtr>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the extension policy says these source/common changes should go in a separate PR for ease of review.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zuercher zuercher self-assigned this Sep 13, 2018
Copy link
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@zuercher zuercher assigned brian-pane and zuercher and unassigned zuercher Sep 14, 2018
@zuercher
Copy link
Member

@rgs1 @fishcakez if you're interested

@brian-pane
Copy link
Contributor

Meta-commentary on this PR: what we've found with the subset load balancer in production usage as an edge proxy is that its computation of upstream state changes is quite CPU-intensive (and is done in each worker thread, so it competes with request processing). I suspect the subset load balancer may need some optimization work to be viable for Thrift service mesh usage in environments with a large number of upstreams. @rgs1 has deeper context on this issue.

new Envoy::Router::MetadataMatchCriteriaImpl(filter_it->second));
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would 62441f9 work with thrift without further work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this relates to @brian-pane's perf comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it will, yes.

// <envoy_api_field_config.filter.network.thrift_proxy.v2alpha1.WeightedCluster.ClusterWeight.metadata_match>`,
// with values there taking precedence. Keys and values should be provided under the "envoy.lb"
// metadata key.
envoy.api.v2.core.Metadata metadata_match = 3;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few questions:

a) are we planning on supporting something like 2d25067 so that we can write filters that sets dynamic metadata based on a thrift header?

b) do thrift endpoints support mutable metadata like we do for HTTP (cfr 810ec2e)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. i don't know of any concrete plans to do so since we don't keep track of RequestInfo in the thrift connection manager right now
  2. it's all the same cluster/upstream management so it should just work

@zuercher zuercher merged commit c32aed9 into envoyproxy:master Sep 14, 2018
@brirams brirams deleted the brirams/#5836/thrift_proxy_metadata_match branch September 14, 2018 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants