diff options
author | Jon Marius Venstad <jonmv@users.noreply.github.com> | 2019-03-11 10:10:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-11 10:10:05 +0100 |
commit | 4afbfdd7c56e38bad8ef1ea665d60563c209743c (patch) | |
tree | 5ed68081b1ef3f049350e09f88d166ff4bb17a0f | |
parent | 02e86a87894fa6312a88be9b00bd7f19740f25b1 (diff) | |
parent | c6f9d0931d5dccf636927085e9ec0a35b40a75cd (diff) |
Merge pull request #8726 from vespa-engine/mpolden/limit-total-entries
Prevent log from growing unbounded within expiry
2 files changed, 10 insertions, 2 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/auditlog/AuditLog.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/auditlog/AuditLog.java index 3190ce7d332..c467a4a0acd 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/auditlog/AuditLog.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/auditlog/AuditLog.java @@ -44,7 +44,13 @@ public class AuditLog { return new AuditLog(entries); } - /** Returns all entries in this. Entries are sorted descending by their timestamp */ + /** Returns the first n entries in this. Since entries are sorted descendingly, this will be the n newest entries */ + public AuditLog first(int n) { + if (entries.size() < n) return this; + return new AuditLog(entries.subList(0, n)); + } + + /** Returns all entries in this. Entries are sorted descendingly by their timestamp */ public List<Entry> entries() { return entries; } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/auditlog/AuditLogger.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/auditlog/AuditLogger.java index fcf33a92f79..7d8bbb17361 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/auditlog/AuditLogger.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/auditlog/AuditLogger.java @@ -25,6 +25,7 @@ public class AuditLogger { /** The TTL of log entries. Entries older than this will be removed when the log is updated */ private static final Duration entryTtl = Duration.ofDays(14); + private static final int maxEntries = 2000; private final CuratorDb db; private final Clock clock; @@ -71,7 +72,8 @@ public class AuditLogger { try (Lock lock = db.lockAuditLog()) { AuditLog auditLog = db.readAuditLog() .pruneBefore(now.minus(entryTtl)) - .with(entry); + .with(entry) + .first(maxEntries); db.writeAuditLog(auditLog); } |