Skip to content

Commit 92e37b4

Browse files
author
slfan1989
committed
YARN-11239. Optimize FederationClientInterceptor audit log.
1 parent 5bb11ce commit 92e37b4

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/RouterAuditLogger.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public static class AuditConstants {
5151
public static final String GET_APP_REPORT = "Get Application Report";
5252
public static final String TARGET_CLIENT_RM_SERVICE = "RouterClientRMService";
5353
public static final String UNKNOWN = "UNKNOWN";
54+
public static final String GET_APPLICATIONS = "Get Applications";
55+
public static final String GET_CLUSTERMETRICS = "Get ClusterMetrics";
56+
public static final String GET_CLUSTERNODES = "Get ClusterNodes";
57+
public static final String GET_QUEUEINFO = "Get QueueInfo";
58+
public static final String GET_QUEUE_USER_ACLS = "Get QueueUserAcls";
5459
}
5560

5661
/**

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,7 @@
141141

142142
import org.apache.hadoop.classification.VisibleForTesting;
143143

144-
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.GET_NEW_APP;
145-
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.SUBMIT_NEW_APP;
146-
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.GET_APP_REPORT;
147-
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.FORCE_KILL_APP;
148-
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.TARGET_CLIENT_RM_SERVICE;
149-
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.UNKNOWN;
144+
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.*;
150145

151146
/**
152147
* Extends the {@code AbstractRequestInterceptorClient} class and provides an
@@ -811,6 +806,8 @@ public GetApplicationsResponse getApplications(GetApplicationsRequest request)
811806
throws YarnException, IOException {
812807
if (request == null) {
813808
routerMetrics.incrMultipleAppsFailedRetrieved();
809+
RouterAuditLogger.logFailure(user.getShortUserName(), GET_APPLICATIONS, UNKNOWN,
810+
TARGET_CLIENT_RM_SERVICE, "Missing getApplications request.");
814811
RouterServerUtil.logAndThrowException("Missing getApplications request.", null);
815812
}
816813
long startTime = clock.getTime();
@@ -834,6 +831,8 @@ public GetClusterMetricsResponse getClusterMetrics(
834831
GetClusterMetricsRequest request) throws YarnException, IOException {
835832
if (request == null) {
836833
routerMetrics.incrGetClusterMetricsFailedRetrieved();
834+
RouterAuditLogger.logFailure(user.getShortUserName(), GET_CLUSTERMETRICS, UNKNOWN,
835+
TARGET_CLIENT_RM_SERVICE, "Missing getApplications request.");
837836
RouterServerUtil.logAndThrowException("Missing getClusterMetrics request.", null);
838837
}
839838
long startTime = clock.getTime();
@@ -888,7 +887,7 @@ <R> Collection<R> invokeConcurrent(ClientMethod request, Class<R> clazz)
888887
results.put(subClusterId, clazz.cast(result));
889888
} catch (InterruptedException | ExecutionException e) {
890889
Throwable cause = e.getCause();
891-
LOG.error("Cannot execute {} on {}: {}", request.getMethodName(),
890+
LOG.error("Cannot execute {} on {} : {}", request.getMethodName(),
892891
subClusterId.getId(), cause.getMessage());
893892
exceptions.put(subClusterId, e);
894893
}
@@ -914,6 +913,8 @@ public GetClusterNodesResponse getClusterNodes(GetClusterNodesRequest request)
914913
throws YarnException, IOException {
915914
if (request == null) {
916915
routerMetrics.incrClusterNodesFailedRetrieved();
916+
RouterAuditLogger.logFailure(user.getShortUserName(), GET_CLUSTERNODES, UNKNOWN,
917+
TARGET_CLIENT_RM_SERVICE, "Missing getClusterNodes request.");
917918
RouterServerUtil.logAndThrowException("Missing getClusterNodes request.", null);
918919
}
919920
long startTime = clock.getTime();
@@ -937,6 +938,8 @@ public GetQueueInfoResponse getQueueInfo(GetQueueInfoRequest request)
937938
throws YarnException, IOException {
938939
if (request == null || request.getQueueName() == null) {
939940
routerMetrics.incrGetQueueInfoFailedRetrieved();
941+
RouterAuditLogger.logFailure(user.getShortUserName(), GET_QUEUEINFO, UNKNOWN,
942+
TARGET_CLIENT_RM_SERVICE, "Missing getQueueInfo request or queueName.");
940943
RouterServerUtil.logAndThrowException("Missing getQueueInfo request or queueName.", null);
941944
}
942945

@@ -962,6 +965,8 @@ public GetQueueUserAclsInfoResponse getQueueUserAcls(
962965
GetQueueUserAclsInfoRequest request) throws YarnException, IOException {
963966
if(request == null){
964967
routerMetrics.incrQueueUserAclsFailedRetrieved();
968+
RouterAuditLogger.logFailure(user.getShortUserName(), GET_QUEUE_USER_ACLS, UNKNOWN,
969+
TARGET_CLIENT_RM_SERVICE, "Missing getQueueUserAcls request.");
965970
RouterServerUtil.logAndThrowException("Missing getQueueUserAcls request.", null);
966971
}
967972
long startTime = clock.getTime();
@@ -986,6 +991,9 @@ public MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues(
986991
throws YarnException, IOException {
987992
if (request == null || request.getApplicationId() == null || request.getTargetQueue() == null) {
988993
routerMetrics.incrMoveApplicationAcrossQueuesFailedRetrieved();
994+
RouterAuditLogger.logFailure(user.getShortUserName(), GET_QUEUE_USER_ACLS, UNKNOWN,
995+
TARGET_CLIENT_RM_SERVICE, "Missing moveApplicationAcrossQueues request or " +
996+
"applicationId or target queue.");
989997
RouterServerUtil.logAndThrowException("Missing moveApplicationAcrossQueues request or " +
990998
"applicationId or target queue.", null);
991999
}
@@ -999,8 +1007,8 @@ public MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues(
9991007
.getApplicationHomeSubCluster(applicationId);
10001008
} catch (YarnException e) {
10011009
routerMetrics.incrMoveApplicationAcrossQueuesFailedRetrieved();
1002-
RouterServerUtil.logAndThrowException("Application " +
1003-
applicationId + " does not exist in FederationStateStore.", e);
1010+
RouterServerUtil.logAndThrowException(e, "Application %s does not exist in FederationStateStore.",
1011+
applicationId);
10041012
}
10051013

10061014
ApplicationClientProtocol clientRMProxy = getClientRMProxyForSubCluster(subClusterId);
@@ -1009,8 +1017,9 @@ public MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues(
10091017
response = clientRMProxy.moveApplicationAcrossQueues(request);
10101018
} catch (Exception e) {
10111019
routerMetrics.incrMoveApplicationAcrossQueuesFailedRetrieved();
1012-
RouterServerUtil.logAndThrowException("Unable to moveApplicationAcrossQueues for " +
1013-
applicationId + " to SubCluster " + subClusterId.getId(), e);
1020+
RouterServerUtil.logAndThrowException(e,
1021+
"Unable to moveApplicationAcrossQueues for %s to SubCluster %s.", applicationId,
1022+
subClusterId.getId());
10141023
}
10151024

10161025
if (response == null) {

0 commit comments

Comments
 (0)