[Profile] Add cpu time cost in query audit (#5051)

This commit is contained in:
Lijia Liu
2020-12-13 22:22:15 +08:00
committed by GitHub
parent f847e22eeb
commit ff4bd1223f
13 changed files with 63 additions and 13 deletions

View File

@ -75,6 +75,8 @@ public class AuditEvent {
public String feIp = "";
@AuditField(value = "Stmt")
public String stmt = "";
@AuditField(value = "CpuTimeMS")
public long cpuTimeMs = -1;
public static class AuditEventBuilder {
@ -127,6 +129,11 @@ public class AuditEvent {
return this;
}
public AuditEventBuilder setCpuTimeMs(long cpuTimeMs) {
auditEvent.cpuTimeMs = cpuTimeMs;
return this;
}
public AuditEventBuilder setScanRows(long scanRows) {
auditEvent.scanRows = scanRows;
return this;

View File

@ -115,6 +115,7 @@ public class ConnectProcessor {
.setState(ctx.getState().toString()).setQueryTime(elapseMs)
.setScanBytes(statistics == null ? 0 : statistics.scan_bytes)
.setScanRows(statistics == null ? 0 : statistics.scan_rows)
.setCpuTimeMs(statistics == null ? 0 : statistics.cpu_ms)
.setReturnRows(ctx.getReturnRows())
.setStmtId(ctx.getStmtId())
.setQueryId(ctx.queryId() == null ? "NaN" : DebugUtil.printId(ctx.queryId()));

View File

@ -1125,6 +1125,9 @@ public class StmtExecutor {
if (statisticsForAuditLog.scan_rows == null) {
statisticsForAuditLog.scan_rows = 0L;
}
if (statisticsForAuditLog.cpu_ms == null) {
statisticsForAuditLog.cpu_ms = 0L;
}
return statisticsForAuditLog;
}
}

View File

@ -100,6 +100,7 @@ public class ConnectProcessorTest {
statistics.scan_bytes = 0L;
statistics.scan_rows = 0L;
statistics.cpu_ms = 0L;
MetricRepo.init();
}