Skip to content

Commit

Permalink
YARN-11239. Optimize FederationClientInterceptor audit log. (apache#5127
Browse files Browse the repository at this point in the history
)
  • Loading branch information
slfan1989 authored and ferdelyi committed May 26, 2023
1 parent eb8b11d commit 0b5292c
Show file tree
Hide file tree
Showing 4 changed files with 484 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* Manages Router audit logs.
* Audit log format is written as key=value pairs. Tab separated.
*/
public class RouterAuditLogger {
public final class RouterAuditLogger {
private static final Logger LOG =
LoggerFactory.getLogger(RouterAuditLogger.class);

Expand All @@ -51,6 +51,43 @@ public static class AuditConstants {
public static final String GET_APP_REPORT = "Get Application Report";
public static final String TARGET_CLIENT_RM_SERVICE = "RouterClientRMService";
public static final String UNKNOWN = "UNKNOWN";
public static final String GET_APPLICATIONS = "Get Applications";
public static final String GET_CLUSTERMETRICS = "Get ClusterMetrics";
public static final String GET_CLUSTERNODES = "Get ClusterNodes";
public static final String GET_QUEUEINFO = "Get QueueInfo";
public static final String GET_QUEUE_USER_ACLS = "Get QueueUserAcls";
public static final String MOVE_APPLICATION_ACROSS_QUEUES = "Move ApplicationAcrossQueues";
public static final String GET_NEW_RESERVATION = "Get NewReservation";
public static final String SUBMIT_RESERVATION = "Submit Reservation";
public static final String LIST_RESERVATIONS = "List Reservations";
public static final String UPDATE_RESERVATION = "Update Reservation";
public static final String DELETE_RESERVATION = "Delete Reservation";
public static final String GET_NODETOLABELS = "Get NodeToLabels";
public static final String GET_LABELSTONODES = "Get LabelsToNodes";
public static final String GET_CLUSTERNODELABELS = "Get ClusterNodeLabels";
public static final String GET_APPLICATION_ATTEMPT_REPORT = "Get ApplicationAttemptReport";
public static final String GET_APPLICATION_ATTEMPTS = "Get ApplicationAttempts";
public static final String GET_CONTAINERREPORT = "Get ContainerReport";
public static final String GET_CONTAINERS = "Get Containers";
public static final String GET_DELEGATIONTOKEN = "Get DelegationToken";
public static final String RENEW_DELEGATIONTOKEN = "Renew DelegationToken";
public static final String CANCEL_DELEGATIONTOKEN = "Cancel DelegationToken";
public static final String FAIL_APPLICATIONATTEMPT = "Fail ApplicationAttempt";
public static final String UPDATE_APPLICATIONPRIORITY = "Update ApplicationPriority";
public static final String SIGNAL_TOCONTAINER = "Signal ToContainer";
public static final String UPDATE_APPLICATIONTIMEOUTS = "Update ApplicationTimeouts";
public static final String GET_RESOURCEPROFILES = "Get ResourceProfiles";
public static final String GET_RESOURCEPROFILE = "Get ResourceProfile";
public static final String GET_RESOURCETYPEINFO = "Get ResourceTypeInfo";
public static final String GET_ATTRIBUTESTONODES = "Get AttributesToNodes";
public static final String GET_CLUSTERNODEATTRIBUTES = "Get ClusterNodeAttributes";
public static final String GET_NODESTOATTRIBUTES = "Get NodesToAttributes";
}

public static void logSuccess(String user, String operation, String target) {
if (LOG.isInfoEnabled()) {
LOG.info(createSuccessLog(user, operation, target, null, null));
}
}

/**
Expand Down Expand Up @@ -146,6 +183,28 @@ public static void logFailure(String user, String operation, String perm,
}
}

/**
* Create a readable and parseable audit log string for a failed event.
*
* @param user User who made the service request.
* @param operation Operation requested by the user.
* @param perm Target permissions.
* @param target The target on which the operation is being performed.
* @param descriptionFormat the description message format string.
* @param args format parameter.
*
* <br><br>
* Note that the {@link RouterAuditLogger} uses tabs ('\t') as a key-val
* delimiter and hence the value fields should not contains tabs ('\t').
*/
public static void logFailure(String user, String operation, String perm,
String target, String descriptionFormat, Object... args) {
if (LOG.isInfoEnabled()) {
String description = String.format(descriptionFormat, args);
LOG.info(createFailureLog(user, operation, perm, target, description, null, null));
}
}

/**
* Create a readable and parseable audit log string for a failed event.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ public static void logAndThrowException(String errMsg, Throwable t)
}
}

/**
* Throws an exception due to an error.
*
* @param errMsg the error message
* @throws YarnException on failure
*/
@Public
@Unstable
public static void logAndThrowException(String errMsg) throws YarnException {
LOG.error(errMsg);
throw new YarnException(errMsg);
}

public static <R> R createRequestInterceptorChain(Configuration conf, String pipeLineClassName,
String interceptorClassName, Class<R> clazz) {

Expand Down
Loading

0 comments on commit 0b5292c

Please sign in to comment.