TransientCodeOwnerConfigCache: Log warning if the limit has been reached

We want to know when the cache limit is reached so that we address the
issue (e.g. reduce number of owners file in the project).

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I77efaf89e91abef7ac3634c9a5c26b388363634e
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/TransientCodeOwnerConfigCache.java b/java/com/google/gerrit/plugins/codeowners/backend/TransientCodeOwnerConfigCache.java
index 81eea89..65ec308 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/TransientCodeOwnerConfigCache.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/TransientCodeOwnerConfigCache.java
@@ -15,6 +15,7 @@
 package com.google.gerrit.plugins.codeowners.backend;
 
 import com.google.auto.value.AutoValue;
+import com.google.common.flogger.FluentLogger;
 import com.google.gerrit.common.Nullable;
 import com.google.gerrit.entities.BranchNameKey;
 import com.google.gerrit.plugins.codeowners.backend.config.CodeOwnersPluginConfiguration;
@@ -24,6 +25,7 @@
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Optional;
+import java.util.concurrent.TimeUnit;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.Ref;
 import org.eclipse.jgit.lib.Repository;
@@ -37,6 +39,8 @@
  * <p><strong>Note</strong>: This class is not thread-safe.
  */
 public class TransientCodeOwnerConfigCache implements CodeOwnerConfigLoader {
+  private static final FluentLogger logger = FluentLogger.forEnclosingClass();
+
   private final GitRepositoryManager repoManager;
   private final CodeOwners codeOwners;
   private final Optional<Integer> maxCacheSize;
@@ -97,6 +101,10 @@
     }
     if (!maxCacheSize.isPresent() || cache.size() < maxCacheSize.get()) {
       cache.put(cacheKey, codeOwnerConfig);
+    } else if (maxCacheSize.isPresent()) {
+      logger.atWarning().atMostEvery(1, TimeUnit.DAYS).log(
+          "exceeded limit of %s (project = %s)",
+          getClass().getSimpleName(), cacheKey.codeOwnerConfigKey().project());
     }
     return codeOwnerConfig;
   }