[Improve](point query) audit point query (#21587)
This commit is contained in:
@ -40,4 +40,18 @@ public class ExecuteStmt extends StatementBase {
|
||||
public RedirectStatus getRedirectStatus() {
|
||||
return RedirectStatus.NO_FORWARD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSql() {
|
||||
String sql = "EXECUTE(";
|
||||
int size = args.size();
|
||||
for (int i = 0; i < size; ++i) {
|
||||
sql += args.get(i).toSql();
|
||||
if (i < size - 1) {
|
||||
sql += ", ";
|
||||
}
|
||||
}
|
||||
sql += ")";
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
|
||||
@ -219,10 +219,16 @@ public class ConnectProcessor {
|
||||
"msg: Not supported such prepared statement");
|
||||
return;
|
||||
}
|
||||
ctx.setStartTime();
|
||||
if (prepareCtx.stmt.getInnerStmt() instanceof QueryStmt) {
|
||||
ctx.getState().setIsQuery(true);
|
||||
}
|
||||
prepareCtx.stmt.setIsPrepared();
|
||||
int paramCount = prepareCtx.stmt.getParmCount();
|
||||
// null bitmap
|
||||
byte[] nullbitmapData = new byte[(paramCount + 7) / 8];
|
||||
packetBuf.get(nullbitmapData);
|
||||
String stmtStr = "";
|
||||
try {
|
||||
// new_params_bind_flag
|
||||
if ((int) packetBuf.get() != 0) {
|
||||
@ -252,6 +258,7 @@ public class ConnectProcessor {
|
||||
executor = new StmtExecutor(ctx, executeStmt);
|
||||
ctx.setExecutor(executor);
|
||||
executor.execute();
|
||||
stmtStr = executeStmt.toSql();
|
||||
} catch (Throwable e) {
|
||||
// Catch all throwable.
|
||||
// If reach here, maybe palo bug.
|
||||
@ -259,9 +266,11 @@ public class ConnectProcessor {
|
||||
ctx.getState().setError(ErrorCode.ERR_UNKNOWN_ERROR,
|
||||
e.getClass().getSimpleName() + ", msg: " + e.getMessage());
|
||||
}
|
||||
auditAfterExec(stmtStr, prepareCtx.stmt.getInnerStmt(), null, false);
|
||||
}
|
||||
|
||||
private void auditAfterExec(String origStmt, StatementBase parsedStmt, Data.PQueryStatistics statistics) {
|
||||
private void auditAfterExec(String origStmt, StatementBase parsedStmt,
|
||||
Data.PQueryStatistics statistics, boolean printFuzzyVariables) {
|
||||
origStmt = origStmt.replace("\n", " ");
|
||||
// slow query
|
||||
long endTime = System.currentTimeMillis();
|
||||
@ -283,7 +292,7 @@ public class ConnectProcessor {
|
||||
.setStmtId(ctx.getStmtId())
|
||||
.setQueryId(ctx.queryId() == null ? "NaN" : DebugUtil.printId(ctx.queryId()))
|
||||
.setTraceId(spanContext.isValid() ? spanContext.getTraceId() : "")
|
||||
.setFuzzyVariables(ctx.getSessionVariable().printFuzzyVariables());
|
||||
.setFuzzyVariables(!printFuzzyVariables ? "" : ctx.getSessionVariable().printFuzzyVariables());
|
||||
|
||||
if (ctx.getState().isQuery()) {
|
||||
MetricRepo.COUNTER_QUERY_ALL.increase(1L);
|
||||
@ -436,7 +445,7 @@ public class ConnectProcessor {
|
||||
finalizeCommand();
|
||||
}
|
||||
}
|
||||
auditAfterExec(auditStmt, executor.getParsedStmt(), executor.getQueryStatisticsForAuditLog());
|
||||
auditAfterExec(auditStmt, executor.getParsedStmt(), executor.getQueryStatisticsForAuditLog(), true);
|
||||
// execute failed, skip remaining stmts
|
||||
if (ctx.getState().getStateType() == MysqlStateType.ERR) {
|
||||
break;
|
||||
@ -480,7 +489,7 @@ public class ConnectProcessor {
|
||||
ctx.getState().setErrType(QueryState.ErrType.ANALYSIS_ERR);
|
||||
}
|
||||
}
|
||||
auditAfterExec(origStmt, parsedStmt, statistics);
|
||||
auditAfterExec(origStmt, parsedStmt, statistics, true);
|
||||
}
|
||||
|
||||
// analyze the origin stmt and return multi-statements
|
||||
|
||||
@ -31,6 +31,9 @@ public class PrepareStmtContext {
|
||||
public Analyzer analyzer;
|
||||
public String stmtString;
|
||||
|
||||
// Timestamp in millisecond last command starts at
|
||||
protected volatile long startTime;
|
||||
|
||||
public PrepareStmtContext(PrepareStmt stmt, ConnectContext ctx, Planner planner,
|
||||
Analyzer analyzer, String stmtString) {
|
||||
this.stmt = stmt;
|
||||
@ -41,4 +44,12 @@ public class PrepareStmtContext {
|
||||
this.analyzer = analyzer;
|
||||
this.stmtString = stmtString;
|
||||
}
|
||||
|
||||
public long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime() {
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user