]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: set correct requestId and hostId on s3select error 56864/head
authorSeena Fallah <seenafallah@gmail.com>
Fri, 12 Apr 2024 18:49:23 +0000 (20:49 +0200)
committerSeena Fallah <seenafallah@gmail.com>
Wed, 17 Jul 2024 07:56:14 +0000 (09:56 +0200)
Previously, these fields remained constant despite the possibility
of populating them with appropriate values.
Ref. https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html

Fixes: https://tracker.ceph.com/issues/65468
Signed-off-by: Seena Fallah <seenafallah@gmail.com>
src/rgw/rgw_s3select.cc
src/rgw/rgw_s3select_private.h

index d989147cdc7d67e14bf7ea9410376f289f62ba11..800d276a6aab1c75c4ade9ef8d73e21dbd771d2f 100644 (file)
@@ -214,10 +214,10 @@ void aws_response_handler::init_end_response()
   rgw_flush_formatter_and_reset(s, s->formatter);
 }
 
-void aws_response_handler::send_error_response(const char* error_code, const char* error_message, const char* resource_id)
+void aws_response_handler::send_error_response(const char* error_code, const char* error_message)
 {
   m_fp_chunk_encoding();
-  std::string out_error_msg = std::string(error_code) + " :" + std::string(error_message) + " :" + std::string(resource_id);
+  std::string out_error_msg = std::string(error_code) + " :" + std::string(error_message) + " :" + s->trans_id;
   error_result.resize(header_crc_size, '\0');
   get_buffer()->clear();
   header_size = create_error_header_records(out_error_msg.data());
@@ -242,8 +242,7 @@ void aws_response_handler::send_success_response()
 static constexpr const char* empty_error="--";
 
 void aws_response_handler::send_error_response_rgw_formatter(const char* error_code = empty_error,
-    const char* error_message = empty_error,
-    const char* resource_id = empty_error)
+    const char* error_message = empty_error)
 {
   set_req_state_err(s, 0);
   dump_errno(s, 400);
@@ -252,8 +251,9 @@ void aws_response_handler::send_error_response_rgw_formatter(const char* error_c
   s->formatter->open_object_section("Error");
   s->formatter->dump_string("Code", error_code);
   s->formatter->dump_string("Message", error_message);
-  s->formatter->dump_string("Resource", "#Resource#");
-  s->formatter->dump_string("RequestId", resource_id);
+  if (!s->trans_id.empty())
+    s->formatter->dump_string("RequestId", s->trans_id);
+  s->formatter->dump_string("HostId", s->host_id);
   s->formatter->close_section();
   rgw_flush_formatter_and_reset(s, s->formatter);
 }
@@ -436,7 +436,7 @@ int RGWSelectObj_ObjStore_S3::run_s3select_on_csv(const char* query, const char*
 
   if (s3select_syntax.get_error_description().empty() == false) {
     //error-flow (syntax-error)
-    m_aws_response_handler.send_error_response(s3select_syntax_error,s3select_syntax.get_error_description().c_str(),s3select_resource_id);
+    m_aws_response_handler.send_error_response(s3select_syntax_error,s3select_syntax.get_error_description().c_str());
     ldpp_dout(this, 10) << "s3-select query: failed to prase the following query {" << query << "}" << dendl;
     ldpp_dout(this, 10) << "s3-select query: syntax-error {" << s3select_syntax.get_error_description() << "}" << dendl;
     return -1;
@@ -453,7 +453,7 @@ int RGWSelectObj_ObjStore_S3::run_s3select_on_csv(const char* query, const char*
 
     if (status < 0) {
       //error flow(processing-time)
-      m_aws_response_handler.send_error_response(s3select_processTime_error,m_s3_csv_object.get_error_description().data(),s3select_resource_id);
+      m_aws_response_handler.send_error_response(s3select_processTime_error,m_s3_csv_object.get_error_description().data());
       
       ldpp_dout(this, 10) << "s3-select query: failed to process query; {" << m_s3_csv_object.get_error_description() << "}" << dendl;
       return -1;
@@ -497,7 +497,7 @@ int RGWSelectObj_ObjStore_S3::run_s3select_on_parquet(const char* query)
   }
   if (s3select_syntax.get_error_description().empty() == false) {
     //the SQL statement failed the syntax parser
-    m_aws_response_handler.send_error_response(s3select_syntax_error,m_s3_parquet_object.get_error_description().c_str(),s3select_resource_id);
+    m_aws_response_handler.send_error_response(s3select_syntax_error, m_s3_parquet_object.get_error_description().c_str());
 
     ldpp_dout(this, 10) << "s3-select query: failed to prase query; {" << s3select_syntax.get_error_description() << "}" << dendl;
     status = -1;
@@ -507,7 +507,7 @@ int RGWSelectObj_ObjStore_S3::run_s3select_on_parquet(const char* query)
     status = m_s3_parquet_object.run_s3select_on_object(m_aws_response_handler.get_sql_result());
     if (status < 0) {
 
-      m_aws_response_handler.send_error_response(s3select_processTime_error,m_s3_parquet_object.get_error_description().c_str(),s3select_resource_id);
+      m_aws_response_handler.send_error_response(s3select_processTime_error, m_s3_parquet_object.get_error_description().c_str());
 
       return -1;
     }
@@ -531,8 +531,7 @@ int RGWSelectObj_ObjStore_S3::run_s3select_on_json(const char* query, const char
   if (m_json_datatype.compare("DOCUMENT") != 0) {
     const char* s3select_json_error_msg = "s3-select query: wrong json dataType should use DOCUMENT; ";
     m_aws_response_handler.send_error_response_rgw_formatter(s3select_json_error,
-      s3select_json_error_msg,
-      s3select_resource_id);
+      s3select_json_error_msg);
     ldpp_dout(this, 10) << s3select_json_error_msg << dendl;
     return -EINVAL;
   } 
@@ -542,8 +541,7 @@ int RGWSelectObj_ObjStore_S3::run_s3select_on_json(const char* query, const char
   if (s3select_syntax.get_error_description().empty() == false) {
   //SQL statement is wrong(syntax).
     m_aws_response_handler.send_error_response(s3select_syntax_error,
-      s3select_syntax.get_error_description().c_str(),
-      s3select_resource_id);
+      s3select_syntax.get_error_description().c_str());
     ldpp_dout(this, 10) << "s3-select query: failed to prase query; {" << s3select_syntax.get_error_description() << "}" << dendl;
     return -EINVAL;
   }
@@ -564,8 +562,7 @@ int RGWSelectObj_ObjStore_S3::run_s3select_on_json(const char* query, const char
     ldpp_dout(this, 10) << "S3select: failed to process JSON object: " << e.what() << dendl;
     m_aws_response_handler.get_sql_result().append(e.what());
     m_aws_response_handler.send_error_response(s3select_processTime_error,
-       e.what(),
-       s3select_resource_id);
+       e.what());
     return -EINVAL;
   }
   uint32_t length_post_processing = m_aws_response_handler.get_sql_result().size();
@@ -573,8 +570,7 @@ int RGWSelectObj_ObjStore_S3::run_s3select_on_json(const char* query, const char
   if (status < 0) {
     //error flow(processing-time)
     m_aws_response_handler.send_error_response(s3select_processTime_error,
-       m_s3_json_object.get_error_description().c_str(),
-       s3select_resource_id);
+       m_s3_json_object.get_error_description().c_str());
     ldpp_dout(this, 10) << "s3-select query: failed to process query; {" << m_s3_json_object.get_error_description() << "}" << dendl;
     return -EINVAL;
   }
index c40ac8837fffe112af0b1da5657459df999cd2fc..7beac4f4a5d881e60d6f93c5f7634875db6dfd5c 100644 (file)
@@ -153,8 +153,7 @@ public:
   void init_stats_response();
 
   void send_error_response(const char* error_code,
-                           const char* error_message,
-                           const char* resource_id);
+                           const char* error_message);
 
   void send_success_response();
 
@@ -163,8 +162,7 @@ public:
   void send_stats_response();
 
   void send_error_response_rgw_formatter(const char* error_code,
-                           const char* error_message,
-                           const char* resource_id);
+                           const char* error_message);
 
   std::string* get_buffer()
   {
@@ -238,10 +236,9 @@ private:
   std::function<void(void)> fp_chunked_transfer_encoding;
   int m_header_size;
 
-  const char* s3select_processTime_error = "s3select-ProcessingTime-Error";
-  const char* s3select_syntax_error = "s3select-Syntax-Error";
-  const char* s3select_resource_id = "resourcse-id";
-  const char* s3select_json_error = "json-Format-Error";
+  const char* s3select_processTime_error = "ProcessingTimeError";
+  const char* s3select_syntax_error = "UnsupportedSyntax";
+  const char* s3select_json_error = "InvalidJsonType";
 
 public:
   unsigned int chunk_number;