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

cloud_storage_clients: Fix xml parsing when searching for error code in response #14848

Merged
merged 2 commits into from
Nov 9, 2023

Conversation

abhijat
Copy link
Contributor

@abhijat abhijat commented Nov 9, 2023

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

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v23.2.x
  • v23.1.x
  • v22.3.x

Release Notes

  • none

iobuf_to_delete_objects_result is moved to public API to make testing it
easier.
@abhijat abhijat marked this pull request as ready for review November 9, 2023 06:49
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.
@vbotbuildovich
Copy link
Collaborator

@abhijat abhijat merged commit 415d7db into redpanda-data:dev Nov 9, 2023
26 checks passed
@vbotbuildovich
Copy link
Collaborator

/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);
Copy link
Contributor

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
  • 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");
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants