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

add json to metadata response side support #29460

Merged
merged 14 commits into from
Oct 25, 2023
Merged

Conversation

cqi1217
Copy link
Contributor

@cqi1217 cqi1217 commented Sep 6, 2023

Commit Message:
Currently the json to metadata filter can only extract value from request body, this PR adds the support to extract value from response body.
Related PR: #28394
Additional Description:
Risk Level:low
Testing:unit tests
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

@repokitteh-read-only
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @adisuissa
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #29460 was opened by cqi1217.

see: more, trace.

Signed-off-by: cqi1217 <[email protected]>
Copy link
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

Thanks!
Left a couple of minor API comments.
Assigning @JuniorHsu as code-owner.
/assign @JuniorHsu

MatchRules request_rules = 1 [(validate.rules).message = {required: true}];
MatchRules request_rules = 1;

// Rules to match json body of responses
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: add '.' at the end of the sentence (also for the comment of request_rules)

@adisuissa
Copy link
Contributor

/wait

Signed-off-by: cqi1217 <[email protected]>
@cqi1217
Copy link
Contributor Author

cqi1217 commented Oct 4, 2023

/retest

cqi1217 added 2 commits October 5, 2023 06:25
Signed-off-by: cqi1217 <[email protected]>
Signed-off-by: cqi1217 <[email protected]>
@@ -177,54 +191,68 @@ bool Filter::addMetadata(const std::string& meta_namespace, const std::string& k
}

void Filter::finalizeDynamicMetadata(Http::StreamFilterCallbacks& filter_callback,
const StructMap& struct_map, bool& processing_finished_flag) {
const StructMap& struct_map, bool& processing_finished_flag,
bool shouldClearRouteCache) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should_clear_route_cache here and there

NiceMock<Envoy::StreamInfo::MockStreamInfo> stream_info_;
envoy::config::core::v3::Metadata dynamic_metadata_;
std::shared_ptr<FilterConfig> config_;
std::shared_ptr<Filter> filter_;
Buffer::OwnedImpl buffer_;
Http::TestRequestHeaderMapImpl incoming_headers_{
{":path", "/ping"}, {":method", "GET"}, {"Content-Type", "application/json"}};
Http::TestResponseHeaderMapImpl response_headers_{
{":path", "/ping"}, {":method", "GET"}, {"Content-Type", "application/json"}};
Copy link
Contributor

Choose a reason for hiding this comment

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

let's remove path/method and add status 200 to match common sense

@@ -143,6 +173,30 @@ TEST_F(FilterTest, BasicStringMatch) {
EXPECT_EQ(getCounterValue("json_to_metadata.rq_invalid_json_body"), 0);
}

TEST_F(FilterTest, BasicResponseStringMatch) {
initializeFilter(request_config_yaml_);
Copy link
Contributor

Choose a reason for hiding this comment

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

rename to config_yaml_

cqi1217 added 2 commits October 6, 2023 03:44
Signed-off-by: cqi1217 <[email protected]>
@JuniorHsu
Copy link
Contributor

try merge the main to see if ci passes?

@cqi1217
Copy link
Contributor Author

cqi1217 commented Oct 6, 2023

seems it is still failing

Copy link
Contributor

@JuniorHsu JuniorHsu left a comment

Choose a reason for hiding this comment

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

only one nit


// Process the case without body, i.e., on_missing is applied for all rules.
void handleAllOnMissing(const Rules& rules, bool& processing_finished_flag);
void handleAllOnMissing(const Rules& rules, bool& processing_finished_flag,
Http::StreamFilterCallbacks& filter_callback, bool shouldClearRouteCache);
Copy link
Contributor

Choose a reason for hiding this comment

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

snake style in *.h file

also input variable should in front of output variable. processing_finished_flag and filter_callback are probably need to be after should_clear_route_cache
https://google.github.io/styleguide/cppguide.html#Inputs_and_Outputs

cqi1217 added 2 commits October 12, 2023 00:04
Signed-off-by: cqi1217 <[email protected]>
Signed-off-by: cqi1217 <[email protected]>
Copy link
Contributor

@JuniorHsu JuniorHsu left a comment

Choose a reason for hiding this comment

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

over to maintainer's review @KBaichoo

Copy link
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

/lgtm api

@cqi1217
Copy link
Contributor Author

cqi1217 commented Oct 20, 2023

@KBaichoo could you take a look? thanks

@alyssawilk
Copy link
Contributor

sorry this wasn't assigned to Kevin so wouldn't show up on his PR reminders - fixed that today

Copy link
Contributor

@KBaichoo KBaichoo left a comment

Choose a reason for hiding this comment

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

Sorry for the delay, this otherwise looks good. Thank you for working on this.

/wait

Signed-off-by: Cai Qi <[email protected]>
@cqi1217
Copy link
Contributor Author

cqi1217 commented Oct 25, 2023

addressed comments

Copy link
Contributor

@KBaichoo KBaichoo left a comment

Choose a reason for hiding this comment

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

Thank you!

@KBaichoo KBaichoo merged commit 3f3790d into envoyproxy:main Oct 25, 2023
103 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants