mneethiraj commented on code in PR #746:
URL: https://github.com/apache/ranger/pull/746#discussion_r2569640776
##########
agents-audit/dest-es/src/main/java/org/apache/ranger/audit/destination/ElasticSearchAuditDestination.java:
##########
@@ -300,7 +302,14 @@ Map<String, Object> toDoc(AuthzAuditEvent auditEvent) {
doc.put("resType", auditEvent.getResourceType());
doc.put("reason", auditEvent.getResultReason());
doc.put("action", auditEvent.getAction());
- doc.put("evtTime", auditEvent.getEventTime());
+ Date eventTime = auditEvent.getEventTime();
+ if (eventTime != null) {
+ SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
Review Comment:
I suggest to avoid instantiation of SimpleDateFormat for each audit log;
consider using a thread local as shown below:
```
public class ElasticSearchAuditDestination extends AuditDestination {
....
private static final ThreadLocal<DateFormat> DATE_FORMAT =
ThreadLocal.withInitial(() -> {
SimpleDateFormat format = new
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
return format;
});
....
Map<String, Object> toDoc(AuthzAuditEvent auditEvent) {
...
if (eventTime != null) {
doc.put("evtTime", DATE_FORMAT.get().format(eventTime));
}
...
}
```
--
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]