-
Notifications
You must be signed in to change notification settings - Fork 589
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
cloud_storage_clients: Fix xml parsing when searching for error code in response #14848
cloud_storage_clients: Fix xml parsing when searching for error code in response #14848
Conversation
iobuf_to_delete_objects_result is moved to public API to make testing it easier.
When searching for error codes in an XML tree, ptree::count does not honor dot paths. The change uses get_optional and adds some tests for the method.
a94bc31
to
1ec6cfe
Compare
ducktape was retried in job https://buildkite.com/redpanda/redpanda/builds/40759#018bb31b-13c7-491d-8007-ad02ab6bce64 |
/backport v23.2.x |
@@ -243,4 +243,7 @@ class s3_client : public client { | |||
ss::shared_ptr<client_probe> _probe; | |||
}; | |||
|
|||
std::variant<client::delete_objects_result, rest_error_response> | |||
iobuf_to_delete_objects_result(iobuf&& buf); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i know you didn't add this function here, but you are making it "public" so i believe the following comment is appropriate
This function can have a better name.
x_to_*
usually means a type conversion/format of some sort, not the case here- this method expects the input to be xml, the method doesn't say anything about the input expectations
something along the line of parse_delete_objects_result
is much better name
- it tells what it is doing: parsing
- it tells the input expectations: delete objects result (from the context (ie the namespace location) we know that it must be a cloud storage delete objects result
-
- i'll correct myself
parse_**s3**_delete_objects_result
is a better name, it won't work for azure but since it is in the same namespace it might confuse users
- i'll correct myself
- iobuf is a detail and is part of the type declaration, we don't need it in the name. moreover, we can have multiple overloads for different type of "input carriers" and won't need to have dozen of function names
iobuf_to_delete_objects_result(iobuf&& buf) { | ||
auto root = util::iobuf_to_ptree(std::move(buf), s3_log); | ||
auto result = client::delete_objects_result{}; | ||
try { | ||
if (root.count("Error.Code") > 0) { | ||
if (auto error_code = root.get_optional<ss::sstring>("Error.Code"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't expect you to change anything here, but (I believe) we can save some CPU instructions by doing extracting the child object here
if( auto error_payload = root.get_child_optional("Error"); error_payload.has_value() {
...
auto code = error_payload.get<ss::sstring>("Code");
}
changes:
- remove tree walking for each property
- remove the empty string optional and let it throw to show the expectations and intentions
-
- these properties must always be present, if they are not we are likely doing something wrong or parsing a bogus message
FIXES: #14014
When searching for error codes in an XML tree, ptree::count which we used does not honor dot paths. The change uses get_optional and adds some tests for the method.
Backports Required
Release Notes