-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pending Audit Logs are sent in batches (#10918)
- Loading branch information
Showing
15 changed files
with
451 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 29 additions & 2 deletions
31
std-bits/base/src/main/java/org/enso/base/enso_cloud/audit/AuditLog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,42 @@ | ||
package org.enso.base.enso_cloud.audit; | ||
|
||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.Future; | ||
|
||
/** | ||
* The high-level API for logging audit events. | ||
* | ||
* <p>The messages are sent on a single background thread in batches, but also as soon as possible. | ||
* That means that we are never waiting for more messages to be batched to avoid delaying logs. | ||
* However, if sending the previous batch took enough time that many messages have been scheduled in | ||
* the meantime, all waiting messages (up to some limit) will be sent in a single request. | ||
*/ | ||
public final class AuditLog { | ||
/** Schedules the log message to be sent in the next batch, and returns immediately. */ | ||
public static void logAsync(String type, String message, ObjectNode metadata) { | ||
var event = new AuditLogMessage(type, message, metadata); | ||
AuditLogAPI.INSTANCE.logAsync(event); | ||
AuditLogApiAccess.INSTANCE.logWithoutConfirmation(event); | ||
} | ||
|
||
/** Schedules the log message to be sent in the next batch, and waits until it has been sent. */ | ||
public static void logSynchronously(String type, String message, ObjectNode metadata) { | ||
var event = new AuditLogMessage(type, message, metadata); | ||
AuditLogAPI.INSTANCE.logSync(event); | ||
Future<Void> future = AuditLogApiAccess.INSTANCE.logWithConfirmation(event); | ||
try { | ||
future.get(); | ||
} catch (ExecutionException | InterruptedException e) { | ||
throw new AuditLogError("Failed to send log message: " + e, e); | ||
} | ||
} | ||
|
||
public static class AuditLogError extends RuntimeException { | ||
public AuditLogError(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} | ||
|
||
public static void resetCache() { | ||
AuditLogApiAccess.INSTANCE.resetCache(); | ||
} | ||
} |
113 changes: 0 additions & 113 deletions
113
std-bits/base/src/main/java/org/enso/base/enso_cloud/audit/AuditLogAPI.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.