Jason Fehr has posted comments on this change. ( https://gerrit.cloudera.org/24502 )
Change subject: IMPALA-15107: Support Direct Thrift Upload for AI Profile Analyzer ...................................................................... Patch Set 10: (27 comments) https://gerrit.cloudera.org/#/c/24502/10//COMMIT_MSG Commit Message: https://gerrit.cloudera.org/#/c/24502/10//COMMIT_MSG@9 PS10, Line 9: CLI-only Instead of saying "CLI-only", say HTTP API only. There are other ways of calling HTTP APIs than using a CLI. Also in lines 20 and 23. https://gerrit.cloudera.org/#/c/24502/10/be/src/service/impala-http-handler.cc File be/src/service/impala-http-handler.cc: https://gerrit.cloudera.org/#/c/24502/10/be/src/service/impala-http-handler.cc@497 PS10, Line 497: HttpStatusCode::Ok If there is an error, the most applicable 4xx or 5xx http status code should be returned. https://gerrit.cloudera.org/#/c/24502/10/be/src/service/impala-http-handler.cc@509 PS10, Line 509: set_error(slot_status.GetDetail()); Also need to set the status code to `HttpStatusCode::ServiceUnavailable`. https://gerrit.cloudera.org/#/c/24502/10/be/src/service/impala-http-handler.cc@554 PS10, Line 554: if (Webserver::FindFormUrlEncodedValue( : req.post_data, "thrift_profile", &raw_thrift_profile)) { This determination should be made based on the "Content-Type" http request header. If that header exists and has a value of "application/x-www-form-urlencoded", then read the profile out of the "thrift_profile" field. https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Type https://gerrit.cloudera.org/#/c/24502/10/be/src/service/query-profile-ai-analysis.h File be/src/service/query-profile-ai-analysis.h: https://gerrit.cloudera.org/#/c/24502/10/be/src/service/query-profile-ai-analysis.h@51 PS10, Line 51: // for, and keeps it until the analysis is finished. Please add a note that this class is not thread safe. https://gerrit.cloudera.org/#/c/24502/9/be/src/service/query-profile-ai-analysis.cc File be/src/service/query-profile-ai-analysis.cc: https://gerrit.cloudera.org/#/c/24502/9/be/src/service/query-profile-ai-analysis.cc@980 PS9, Line 980: static RuntimeProfileBase::Verbosity DefaultVerbosityForProfile( : const RuntimeProfile& profile) { : const RuntimeProfile* exec_profile = : dynamic_cast<const RuntimeProfile*>(profile.GetChildByPrefix("Execution Profile")); : if > Close() only closes the tracker it's called on, so the process tracker was Done https://gerrit.cloudera.org/#/c/24502/9/be/src/service/query-profile-ai-analysis.cc@992 PS9, Line 992: // to, saturating instead of overflowing. : static int64_t MaxDecompressedUploadSize(int64_t archive_size) { > The reservation is now held by AiAnalysisSlot, which the handler keeps for Done https://gerrit.cloudera.org/#/c/24502/9/be/src/service/query-profile-ai-analysis.cc@997 PS9, Line 997: } > Added validation at the untrusted entry point: CreateFromArchiveString take Done https://gerrit.cloudera.org/#/c/24502/10/be/src/service/query-profile-ai-analysis.cc File be/src/service/query-profile-ai-analysis.cc: https://gerrit.cloudera.org/#/c/24502/10/be/src/service/query-profile-ai-analysis.cc@78 PS10, Line 78: DEFINE_int64(query_profile_ai_analysis_max_upload_size_bytes, 500L * 1024L * 1024L, Specifying this value in bytes seems overly granular. Can we support the number and units format like the `-codegen_cache_capacity` flag does (e.g. "500MB", "2GB", etc)? https://gerrit.cloudera.org/#/c/24502/10/be/src/service/query-profile-ai-analysis.cc@168 PS10, Line 168: // Backend tests run without an ExecEnv, and so without a process tracker to charge : // against. The existence of code only for testing is a design smell and should be avoided if possible. Instead, initialize an ExecEnv instance in the test code. For an example, see https://github.com/apache/impala/blob/dabb3c970482d88bc30aa1c2456c85c8b9c4fd43/be/src/observe/otel-trace-manager-test.cc#L64-L125 https://gerrit.cloudera.org/#/c/24502/10/be/src/service/query-profile-ai-analysis.cc@172 PS10, Line 172: mem_tracker_.reset(new MemTracker( : -1, "QueryProfileAiAnalysis", exec_env->process_mem_tracker())); We should not allow the AI analysis to consume all the process memory. Instead, declare a new startup flag that specifies a max amount of memory that the AI analysis can consume and create an intermediate MemTracker instance that sits between this MemTracker instance and the process mem tracker. This intermediate MemTracker instance will have a hard memory limit set by the new startup flag. https://gerrit.cloudera.org/#/c/24502/10/be/src/service/query-profile-ai-analysis.cc@994 PS10, Line 994: const int64_t ratio = FLAGS_query_profile_ai_analysis_max_upload_expansion_ratio; Nit: unnecessary variable declaration. https://gerrit.cloudera.org/#/c/24502/10/be/src/service/query-profile-ai-analysis.cc@1022 PS10, Line 1022: static constexpr int PROFILE_CONVERSION_MEM_ESTIMATE_FACTOR = 8; Nit: add a comment that explains how the number 8 was determined to be the correct value. https://gerrit.cloudera.org/#/c/24502/10/be/src/service/query-profile-ai-analysis.cc@1041 PS10, Line 1041: const AiAnalysisSlot& slot Unnecessary function parameter. In a release build, `slot` will not be used at all. Instead, add a comment to the header file where `GenerateAiAnalysisFromProfile()` is declared stating callers must hold an AiAnalysisSlot. https://gerrit.cloudera.org/#/c/24502/10/be/src/util/runtime-profile-archive.cc File be/src/util/runtime-profile-archive.cc: https://gerrit.cloudera.org/#/c/24502/10/be/src/util/runtime-profile-archive.cc@65 PS10, Line 65: static const int64_t AGG_INSTANCE_VALUE_MEM_ESTIMATE = 16; What are the units of this value? Is it bytes? Please rename to include the units or add to the comments explaining which units are used for this const. https://gerrit.cloudera.org/#/c/24502/10/be/src/util/runtime-profile-archive.cc@53 PS10, Line 53: // Deepest profile tree accepted from untrusted input. Building the tree, pretty-printing : // it and rendering it as JSON all recurse once per level, so the depth must stay well : // below what the stack can hold. Real profiles nest a few dozen levels at most. : static const int MAX_PROFILE_TREE_DEPTH = 256; : : // Deepest counter tree accepted within one profile node. ToJson() and PrettyPrint() : // recurse once per level of 'child_counters_map'. : static const int MAX_COUNTER_TREE_DEPTH = 64; : : // Estimated cost in the materialized profile of one per-instance value of an aggregated : // counter: an AtomicBool plus an AtomicInt64 in AveragedCounter, or one entry of a : // vector that AggregatedRuntimeProfile keeps per instance. : static const int64_t AGG_INSTANCE_VALUE_MEM_ESTIMATE = 16; Even though these limits are set high, I don't like seeing them hardcoded. Consider using a hidden gflag startup flag to specify these values. https://gerrit.cloudera.org/#/c/24502/10/be/src/util/runtime-profile-archive.cc@76 PS10, Line 76: const string& Nit: use `std::string_view` instead of `const string&`. https://gerrit.cloudera.org/#/c/24502/10/be/src/util/runtime-profile-archive.cc@89 PS10, Line 89: class ThriftProfileTreeValidator { This class should be declared in a header file and implemented in a cc file. It may be useful elsewhere besides within this file. https://gerrit.cloudera.org/#/c/24502/10/be/src/util/runtime-profile-archive.cc@336 PS10, Line 336: const string& Nit: use `std::string_view` instead of `const string&`. https://gerrit.cloudera.org/#/c/24502/10/be/src/util/webserver.h File be/src/util/webserver.h: https://gerrit.cloudera.org/#/c/24502/10/be/src/util/webserver.h@128 PS10, Line 128: /// If 'max_post_length_bytes' is positive it replaces --webserver_max_post_length_bytes Need to add a note to `--webserver_max_post_length_bytes` that this limit does not apply to the "/query_ai_analysis_generate" endpoint. https://gerrit.cloudera.org/#/c/24502/10/be/src/util/webserver.h@132 PS10, Line 132: int64_t max_post_length_bytes = -1); Use a default of `FLAG_webserver_max_post_length_bytes`. https://gerrit.cloudera.org/#/c/24502/10/be/src/util/webserver.h@151 PS10, Line 151: /// Finds 'key' in the form-urlencoded 'data' and points 'raw_value' at its : /// still-encoded value, returning false if absent. 'key' matches only at the start of : /// 'data' or right after a '&', so data that merely contains "<key>=" is not mistaken : /// for a form field. Unlike GetVars() the pair is split on the first '=' only, so a : /// value containing '=' - base64 padding, say - is returned whole. : static bool FindFormUrlEncodedValue( : std::string_view data, std::string_view key, std::string_view* raw_value); Use `sq_get_var()` instead instead of rolling our own parser. https://gerrit.cloudera.org/#/c/24502/10/be/src/util/webserver.h@171 PS10, Line 171: -1 UrlHandler is an internal-only class, do not specify a default value for `max_post_length_bytes`. https://gerrit.cloudera.org/#/c/24502/10/be/src/util/webserver.h@202 PS10, Line 202: int64_t max_post_length_bytes_ = -1; This class member should be unset here and also be marked const. Then, both constructors will set this const at class construction. https://gerrit.cloudera.org/#/c/24502/10/be/src/util/webserver.h@242 PS10, Line 242: sq_callback_result_t ReadPostBody(struct sq_connection* connection, int64_t max_length, : const char* uri, MemTracker* body_mem_tracker, std::string* out_body, : int64_t* reserved_bytes); Since this function is a member of the same class that owns `post_body_mem_tracker_`, instead of passing a `MemTracker*`, pass a boolean such as `bool track_mem` that uses `post_body_mem_tracker_` if set to `true`. Also, add new parameters onto the end of the function parameter list to make it easier to follow code changes through git history. https://gerrit.cloudera.org/#/c/24502/10/be/src/util/webserver.cc File be/src/util/webserver.cc: https://gerrit.cloudera.org/#/c/24502/10/be/src/util/webserver.cc@423 PS10, Line 423: Close() Need to call `post_body_mem_tracker_->CloseAndUnregisterFromParent()` since `post_body_mem_tracker_` was initialized with a parent `MemTracker`. https://gerrit.cloudera.org/#/c/24502/10/be/src/util/webserver.cc@1295 PS10, Line 1295: << ": limit is " << max_length; Include the remote user and IP address in this log message so that admins can easily identify who is sending large payloads. -- To view, visit https://gerrit.cloudera.org/24502 To unsubscribe, visit https://gerrit.cloudera.org/settings Gerrit-Project: Impala-ASF Gerrit-Branch: master Gerrit-MessageType: comment Gerrit-Change-Id: Iff05c3cde7b34a56e31f020611cc33ff4e02aa32 Gerrit-Change-Number: 24502 Gerrit-PatchSet: 10 Gerrit-Owner: Gokul Kolady <[email protected]> Gerrit-Reviewer: Abhishek Rawat <[email protected]> Gerrit-Reviewer: Anubhav Jindal <[email protected]> Gerrit-Reviewer: Gokul Kolady <[email protected]> Gerrit-Reviewer: Impala Public Jenkins <[email protected]> Gerrit-Reviewer: Jason Fehr <[email protected]> Gerrit-Reviewer: Quanlong Huang <[email protected]> Gerrit-Reviewer: Yida Wu <[email protected]> Gerrit-Comment-Date: Tue, 24 Nov 2026 18:58:03 +0000 Gerrit-HasComments: Yes
