somandal commented on code in PR #10534:
URL: https://github.com/apache/pinot/pull/10534#discussion_r1159053741
##########
pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/MultiStageBrokerRequestHandler.java:
##########
@@ -169,6 +185,36 @@ private BrokerResponse handleRequest(long requestId,
String query,
return new
BrokerResponseNative(QueryException.getException(QueryException.SQL_PARSING_ERROR,
e));
}
+ QueryPlan queryPlan = queryPlanResult.getQueryPlan();
+ Set<String> tableNames =
getTableNamesFromRelRoot(queryPlanResult.getRelRoot());
+
+ // Compilation Time. This includes the time taken for parsing, compiling,
create stage plans and assigning workers.
+ long compilationEndTimeNs = System.nanoTime();
+ long compilationTime = (compilationEndTimeNs - compilationStartTimeNs) +
sqlNodeAndOptions.getParseTimeNs();
+ updatePhaseTimingForTables(tableNames,
BrokerQueryPhase.REQUEST_COMPILATION, compilationTime);
+
+ // Validate table access.
+ if (!hasTableAccess(requesterIdentity, tableNames)) {
+
_brokerMetrics.addMeteredGlobalValue(BrokerMeter.REQUEST_DROPPED_DUE_TO_ACCESS_ERROR,
1);
+ LOGGER.info("Access denied for requestId {}", requestId);
+ requestContext.setErrorCode(QueryException.ACCESS_DENIED_ERROR_CODE);
+ return new BrokerResponseNative(QueryException.ACCESS_DENIED_ERROR);
+ }
+ updatePhaseTimingForTables(tableNames, BrokerQueryPhase.AUTHORIZATION,
System.nanoTime() - compilationEndTimeNs);
+
+ // Validate QPS quota
+ for (String tableName : tableNames) {
+ if (!_queryQuotaManager.acquire(tableName)) {
+ String errorMessage =
+ String.format("Request %d: %s exceeds query quota for table: %s",
requestId, query, tableName);
+ LOGGER.info(errorMessage);
+
requestContext.setErrorCode(QueryException.TOO_MANY_REQUESTS_ERROR_CODE);
+ String rawTableName = TableNameBuilder.extractRawTableName(tableName);
+ _brokerMetrics.addMeteredTableValue(rawTableName,
BrokerMeter.QUERY_QUOTA_EXCEEDED, 1);
+ return new
BrokerResponseNative(QueryException.getException(QueryException.QUOTA_EXCEEDED_ERROR,
errorMessage));
+ }
Review Comment:
can you create a function to validate quotas? will make the code easier to
read here
##########
pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/MultiStageBrokerRequestHandler.java:
##########
@@ -169,6 +185,36 @@ private BrokerResponse handleRequest(long requestId,
String query,
return new
BrokerResponseNative(QueryException.getException(QueryException.SQL_PARSING_ERROR,
e));
}
+ QueryPlan queryPlan = queryPlanResult.getQueryPlan();
+ Set<String> tableNames =
getTableNamesFromRelRoot(queryPlanResult.getRelRoot());
+
+ // Compilation Time. This includes the time taken for parsing, compiling,
create stage plans and assigning workers.
+ long compilationEndTimeNs = System.nanoTime();
+ long compilationTime = (compilationEndTimeNs - compilationStartTimeNs) +
sqlNodeAndOptions.getParseTimeNs();
+ updatePhaseTimingForTables(tableNames,
BrokerQueryPhase.REQUEST_COMPILATION, compilationTime);
+
+ // Validate table access.
+ if (!hasTableAccess(requesterIdentity, tableNames)) {
+
_brokerMetrics.addMeteredGlobalValue(BrokerMeter.REQUEST_DROPPED_DUE_TO_ACCESS_ERROR,
1);
+ LOGGER.info("Access denied for requestId {}", requestId);
+ requestContext.setErrorCode(QueryException.ACCESS_DENIED_ERROR_CODE);
Review Comment:
nit: Since this code is reused in two places, can you make a function?
--
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]