github-actions[bot] commented on code in PR #62651:
URL: https://github.com/apache/doris/pull/62651#discussion_r3112087646
##########
fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java:
##########
@@ -646,6 +653,35 @@ public void execute(TUniqueId queryId) throws Exception {
}
}
+
+ /**
+ * Pre-resolve the workload group name and set it on ConnectContext.
+ * This ensures the workload group is available for audit logging even if
the query
+ * fails before reaching Coordinator.exec() (e.g., "Database does not
exist" during planning).
+ * Coordinator.exec() will later overwrite this with the authoritative
value after
Review Comment:
`executeInternalQuery()` still has the same lifecycle that motivated this
fix: it writes the audit log in `finally`, but `workloadGroupName` is only
populated inside `coord.exec()`. If parsing or planning throws before
`coord.exec()`, internal SQL still records an empty `audit_log.workload_group`.
Since this PR is fixing that audit-log invariant, please apply the same
pre-resolution there as well, or centralize the initialization so both paths
share it.
##########
fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java:
##########
@@ -646,6 +653,35 @@ public void execute(TUniqueId queryId) throws Exception {
}
}
+
+ /**
+ * Pre-resolve the workload group name and set it on ConnectContext.
+ * This ensures the workload group is available for audit logging even if
the query
+ * fails before reaching Coordinator.exec() (e.g., "Database does not
exist" during planning).
+ * Coordinator.exec() will later overwrite this with the authoritative
value after
+ * privilege checking and workload group validation.
+ */
+ private void resolveWorkloadGroupName() {
+ if (!Config.enable_workload_group) {
+ context.setWorkloadGroupName("");
+ return;
+ }
+ try {
+ String groupName = context.getSessionVariable().getWorkloadGroup();
+ if (Strings.isNullOrEmpty(groupName)) {
+ groupName =
Env.getCurrentEnv().getAuth().getWorkloadGroup(context.getQualifiedUser());
+ }
+ if (Strings.isNullOrEmpty(groupName)) {
+ groupName = WorkloadGroupMgr.DEFAULT_GROUP_NAME;
Review Comment:
If pre-resolution throws here, we leave the previous statement's
`workloadGroupName` on the reused `ConnectContext`, so the next planning
failure can still be audited under a stale group. This is reachable in
production: `Auth.getWorkloadGroup()` can hit the LDAP-backed
`UserPropertyMgr.getPropertyIfNull()` path, and `LdapClient.getDn()` /
`getUserDn()` throws `RuntimeException` on LDAP misconfiguration or duplicate
users. Please clear `context.workloadGroupName` before the `try` (or in this
`catch`) so failure falls back to empty instead of reusing the last query's
value.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]