Skip to content

thrift router: Support request subset lb#18541

Merged
mattklein123 merged 17 commits intoenvoyproxy:mainfrom
xiaoma2015:add_thrift_metadata_filter
Oct 15, 2021
Merged

thrift router: Support request subset lb#18541
mattklein123 merged 17 commits intoenvoyproxy:mainfrom
xiaoma2015:add_thrift_metadata_filter

Conversation

@xiaoma2015
Copy link
Copy Markdown
Contributor

Signed-off-by: Zhangdong Ma zhdma_xd@163.com

Commit Message:
Implement the function of subset lb for request metadata filter like http:

// The request's metadata, if present, takes precedence over the route's.

Risk Level: Low
Testing: N/A
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

Signed-off-by: Zhangdong Ma <zhdma_xd@163.com>
@xiaoma2015 xiaoma2015 requested a review from zuercher as a code owner October 9, 2021 08:26
@repokitteh-read-only
Copy link
Copy Markdown

Hi @xiaoma2015, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #18541 was opened by xiaoma2015.

see: more, trace.

@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Oct 11, 2021

We need add some tests for this new feature.

@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Oct 11, 2021

/assign

Signed-off-by: Zhangdong Ma <zhdma_xd@163.com>
Signed-off-by: Zhangdong Ma <zhdma_xd@163.com>
Signed-off-by: Zhangdong Ma <zhdma_xd@163.com>
Signed-off-by: Zhangdong Ma <zhdma_xd@163.com>
Copy link
Copy Markdown
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

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

Thanks for your contributions, and some minor comments are added.

Comment on lines +159 to +165
if (route_entry_has_match) {
ON_CALL(callbacks_.route_->route_entry_, metadataMatchCriteria())
.WillByDefault(Return(&route_entry_matches));
} else {
ON_CALL(callbacks_.route_->route_entry_, metadataMatchCriteria())
.WillByDefault(Return(nullptr));
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So, where is the verify of metadata match criteria?

Copy link
Copy Markdown
Contributor Author

@xiaoma2015 xiaoma2015 Oct 12, 2021

Choose a reason for hiding this comment

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

test code coming soon

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

/updated

Comment on lines +282 to +289
if (filter_it != request_metadata.end() && route_criteria != nullptr) {
metadata_match_criteria_ = route_criteria->mergeMatchCriteria(filter_it->second);
} else if (filter_it != request_metadata.end()) {
metadata_match_criteria_ =
std::make_unique<Envoy::Router::MetadataMatchCriteriaImpl>(filter_it->second);
} else {
return route_criteria;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

May be following form can make this branches more clear:

if (filter_it != request_metadata.end()) {
  metadata_match_criteria_ = route_criteria != nullptr ? ... : ...;
  // or
  // if (route_criteria != nullptr) { .... }
} else {
  return route_criteria;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

got it

Signed-off-by: Zhangdong Ma <zhdma_xd@163.com>
Signed-off-by: Zhangdong Ma <zhdma_xd@163.com>
Copy link
Copy Markdown
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

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

Thanks. Looks great. And add some comments about the line comments.

initializeRouter();
startRequest(MessageType::Call);

// Test case for router filter metadata is not empty
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

May be this comment is unnecessary?

initializeRouter();
startRequest(MessageType::Call);

// Test case for router filter metadata is empty
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

May be this comment is unnecessary?

verifyMetadataMatchCriteriaFromRoute(true);
}

// Test for request metadata is empty
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

May Test the case where both route metadata match criteria and dynamic metadata match criteria are empty. ?

EXPECT_EQ((*it)->value().value().string_value(), "devel");
it++;

// `version` should be what came from the request, overriding the route entry.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

May

`version` should be what came from the request and override the route entry's.

?

Copy link
Copy Markdown
Member

@rgs1 rgs1 left a comment

Choose a reason for hiding this comment

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

Thanks! Two comments.

return route_criteria;
}

return metadata_match_criteria_.get();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we can simplify this a bit:

    if (filter_it == request_metadata.end()) {
      return route_criteria;
    }

    metadata_match_criteria_ = route_criteria != nullptr ? route_criteria->mergeMatchCriteria(filter_it->second) : std::make_unique<Envoy::Router::MetadataMatchCriteriaImpl>(filter_it->second);
    return metadata_match_criteria_.get();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

using ifelse is better?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thx for review
using ifelse is better?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah looks great -- I am just a fan of the ternary operator 😁.

@rgs1
Copy link
Copy Markdown
Member

rgs1 commented Oct 12, 2021

Also you'll need to merge main once and possibly twice if #18586 lands while this is being reviewed.

Signed-off-by: Zhangdong Ma <zhdma_xd@163.com>
Signed-off-by: Zhangdong Ma <zhdma_xd@163.com>
@xiaoma2015
Copy link
Copy Markdown
Contributor Author

Thanks! Two comments.

thx for review
Is use if is better ?
`
if (filter_it == request_metadata.end()) {
return route_criteria;
}

if (route_criteria != nullptr) {
  metadata_match_criteria_ = route_criteria->mergeMatchCriteria(filter_it->second);
} else {
  metadata_match_criteria_ =
      std::make_unique<Envoy::Router::MetadataMatchCriteriaImpl>(filter_it->second);
}

return metadata_match_criteria_.get();

`

Signed-off-by: Zhangdong Ma <zhdma_xd@163.com>
Copy link
Copy Markdown
Member

@rgs1 rgs1 left a comment

Choose a reason for hiding this comment

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

Looks great - thank you! One last ask: can you add an entry to docs/root/version_history/current.rst noting this was added?

return route_criteria;
}

return metadata_match_criteria_.get();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah looks great -- I am just a fan of the ternary operator 😁.

Signed-off-by: Zhangdong Ma <zhdma_xd@163.com>
@xiaoma2015
Copy link
Copy Markdown
Contributor Author

Looks great - thank you! One last ask: can you add an entry to docs/root/version_history/current.rst noting this was added?

done.
like this: * thrift_proxy: support subset lb for request metadata filter

Copy link
Copy Markdown
Member

@rgs1 rgs1 left a comment

Choose a reason for hiding this comment

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

Thanks! One last thing then it's good for me.

* http: added support for :ref:`retriable health check status codes <envoy_v3_api_field_config.core.v3.HealthCheck.HttpHealthCheck.retriable_statuses>`.
* thrift_proxy: add upstream response zone metrics in the form ``cluster.cluster_name.zone.local_zone.upstream_zone.thrift.upstream_resp_success``.
* vcl_socket_interface: added VCL socket interface extension for fd.io VPP integration to :ref:`contrib images <install_contrib>`. This can be enabled via :ref:`VCL <envoy_v3_api_msg_extensions.vcl.v3alpha.VclSocketInterface>` configuration.
* thrift_proxy: support subset lb for request metadata filter.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit - I think it should be just:

* thrift_proxy: support subset lb when using request or route metadata.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

got it

Signed-off-by: Zhangdong Ma <zhdma_xd@163.com>
…voy into add_thrift_metadata_filter

Signed-off-by: Zhangdong Ma <zhdma_xd@163.com>
Signed-off-by: Zhangdong Ma <zhdma_xd@163.com>
rgs1
rgs1 previously approved these changes Oct 14, 2021
@rgs1
Copy link
Copy Markdown
Member

rgs1 commented Oct 14, 2021

@xiaoma2015 please merge main.

…hrift_metadata_filter

Signed-off-by: Zhangdong Ma <zhdma_xd@163.com>
@xiaoma2015
Copy link
Copy Markdown
Contributor Author

@xiaoma2015 please merge main.
done

Copy link
Copy Markdown
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

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

Thanks.

@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Oct 15, 2021

cc @rgs1 cc @zuercher

@mattklein123 mattklein123 merged commit 11945b4 into envoyproxy:main Oct 15, 2021
@xiaoma2015 xiaoma2015 deleted the add_thrift_metadata_filter branch October 18, 2021 02:49
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.

5 participants