diff options
author | David Pursehouse <dpursehouse@collab.net> | 2020-03-11 10:59:21 +0900 |
---|---|---|
committer | David Ostrovsky <david@ostrovsky.org> | 2020-03-15 09:49:28 +0100 |
commit | 425f4f20218986615593da1a9319466743ee12eb (patch) | |
tree | 83aa5b2a98003e0d6c8951fa6626b425346273ee | |
parent | 04bbb43e28f14b61412b71ecae19921ab67d62cc (diff) |
ReplicationQueue: Migrate to Floggerv2.16.17
ReplicationQueue uses a named logger which is not directly supported
by FluentLogger. Use Gerrit's own NamedFluentLogger instead.
Change-Id: I3ed0244a517d51a349182b34b67202efb3d0ba83
6 files changed, 77 insertions, 93 deletions
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java index 36960a1..2c6bc5e 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java @@ -52,6 +52,7 @@ import com.google.gerrit.server.project.NoSuchProjectException; import com.google.gerrit.server.project.ProjectCache; import com.google.gerrit.server.project.ProjectState; import com.google.gerrit.server.util.RequestContext; +import com.google.gerrit.util.logging.NamedFluentLogger; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Provider; @@ -81,10 +82,9 @@ import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RemoteConfig; import org.eclipse.jgit.transport.RemoteRefUpdate; import org.eclipse.jgit.transport.URIish; -import org.slf4j.Logger; public class Destination { - private static final Logger repLog = ReplicationQueue.repLog; + private static final NamedFluentLogger repLog = ReplicationQueue.repLog; public interface Factory { Destination create(DestinationConfiguration config); @@ -152,7 +152,7 @@ public class Destination { builder.add(g.getUUID()); addRecursiveParents(g.getUUID(), builder, groupIncludeCache); } else { - repLog.warn("Group \"{}\" not recognized, removing from authGroup", name); + repLog.atWarning().log("Group \"%s\" not recognized, removing from authGroup", name); } } remoteUser = new RemoteSiteUser(new ListGroupMembership(builder.build())); @@ -229,7 +229,7 @@ public class Destination { public int shutdown() { int cnt = 0; if (pool != null) { - repLog.warn("Cancelling replication events"); + repLog.atWarning().log("Cancelling replication events"); foreachPushOp( pending, @@ -361,7 +361,7 @@ public class Destination { void schedule( Project.NameKey project, String ref, URIish uri, ReplicationState state, boolean now) { - repLog.info("scheduling replication {}:{} => {}", project, ref, uri); + repLog.atInfo().log("scheduling replication %s:%s => %s", project, ref, uri); if (!shouldReplicate(project, ref, state)) { return; } @@ -406,7 +406,8 @@ public class Destination { task.addState(ref, state); } state.increasePushTaskCount(project.get(), ref); - repLog.info("scheduled {}:{} => {} to run after {}s", project, ref, task, config.getDelay()); + repLog.atInfo().log( + "scheduled %s:%s => %s to run after %ds", project, ref, task, config.getDelay()); } } @@ -642,7 +643,8 @@ public class Destination { } else if (remoteNameStyle.equals("basenameOnly")) { name = FilenameUtils.getBaseName(name); } else if (!remoteNameStyle.equals("slash")) { - repLog.debug("Unknown remoteNameStyle: {}, falling back to slash", remoteNameStyle); + repLog.atFine().log( + "Unknown remoteNameStyle: %s, falling back to slash", remoteNameStyle); } String replacedPath = ReplicationQueue.replaceName(uri.getPath(), name, isSingleProjectMatch()); @@ -731,7 +733,7 @@ public class Destination { try { eventDispatcher.get().postEvent(new Branch.NameKey(project, ref), event); } catch (PermissionBackendException e) { - repLog.error("error posting event", e); + repLog.atSevere().withCause(e).log("error posting event"); } } } @@ -745,7 +747,7 @@ public class Destination { try { eventDispatcher.get().postEvent(new Branch.NameKey(project, ref), event); } catch (PermissionBackendException e) { - repLog.error("error posting event", e); + repLog.atSevere().withCause(e).log("error posting event"); } } } diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/LocalFS.java b/src/main/java/com/googlesource/gerrit/plugins/replication/LocalFS.java index aa6e16c..8efe4bc 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/LocalFS.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/LocalFS.java @@ -43,9 +43,9 @@ public class LocalFS implements AdminApi { u.disableRefLog(); u.link(head); } - repLog.info("Created local repository: {}", uri); + repLog.atInfo().log("Created local repository: %s", uri); } catch (IOException e) { - repLog.error("Error creating local repository {}", uri.getPath(), e); + repLog.atSevere().withCause(e).log("Error creating local repository %s", uri.getPath()); return false; } return true; @@ -55,9 +55,9 @@ public class LocalFS implements AdminApi { public boolean deleteProject(Project.NameKey project) { try { recursivelyDelete(new File(uri.getPath())); - repLog.info("Deleted local repository: {}", uri); + repLog.atInfo().log("Deleted local repository: %s", uri); } catch (IOException e) { - repLog.error("Error deleting local repository {}:\n", uri.getPath(), e); + repLog.atSevere().withCause(e).log("Error deleting local repository %s:\n", uri.getPath()); return false; } return true; @@ -71,7 +71,8 @@ public class LocalFS implements AdminApi { u.link(newHead); } } catch (IOException e) { - repLog.error("Failed to update HEAD of repository {} to {}", uri.getPath(), newHead, e); + repLog.atSevere().withCause(e).log( + "Failed to update HEAD of repository %s to %s", uri.getPath(), newHead); return false; } return true; diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java b/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java index 5794f6e..1838e5c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java @@ -161,17 +161,16 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { @Override public void cancel() { - repLog.info("Replication [{}] to {} was canceled", HexFormat.fromInt(id), getURI()); + repLog.atInfo().log("Replication [%s] to %s was canceled", HexFormat.fromInt(id), getURI()); canceledByReplication(); pool.pushWasCanceled(this); } @Override public void setCanceledWhileRunning() { - repLog.info( - "Replication [{}] to {} was canceled while being executed", - HexFormat.fromInt(id), - getURI()); + repLog.atInfo().log( + "Replication [%s] to %s was canceled while being executed", + HexFormat.fromInt(id), getURI()); canceledWhileRunning.set(true); } @@ -226,10 +225,10 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { if (ALL_REFS.equals(ref)) { delta.clear(); pushAllRefs = true; - repLog.trace("Added all refs for replication to {}", uri); + repLog.atFinest().log("Added all refs for replication to %s", uri); } else if (!pushAllRefs) { delta.add(ref); - repLog.trace("Added ref {} for replication to {}", ref, uri); + repLog.atFinest().log("Added ref %s for replication to %s", ref, uri); } } @@ -317,18 +316,18 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { RunwayStatus status = pool.requestRunway(this); if (!status.isAllowed()) { if (status.isCanceled()) { - repLog.info("PushOp for replication to {} was canceled and thus won't be rescheduled", uri); + repLog.atInfo().log( + "PushOp for replication to %s was canceled and thus won't be rescheduled", uri); } else { - repLog.info( - "Rescheduling replication to {} to avoid collision with the in-flight push [{}].", - uri, - HexFormat.fromInt(status.getInFlightPushId())); + repLog.atInfo().log( + "Rescheduling replication to %s to avoid collision with the in-flight push [%s].", + uri, HexFormat.fromInt(status.getInFlightPushId())); pool.reschedule(this, Destination.RetryReason.COLLISION); } return; } - repLog.info("Replication to {} started...", uri); + repLog.atInfo().log("Replication to %s started...", uri); Timer1.Context context = metrics.start(config.getName()); try { long startedAt = context.getStartTime(); @@ -337,12 +336,9 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { git = gitManager.openRepository(projectName); runImpl(); long elapsed = NANOSECONDS.toMillis(context.stop()); - repLog.info( - "Replication to {} completed in {}ms, {}ms delay, {} retries", - uri, - elapsed, - delay, - retryCount); + repLog.atInfo().log( + "Replication to %s completed in %dms, %dms delay, %d retries", + uri, elapsed, delay, retryCount); } catch (RepositoryNotFoundException e) { stateLog.error( "Cannot replicate " + projectName + "; Local repository error: " + e.getMessage(), @@ -359,7 +355,7 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { || msg.contains("unavailable")) { createRepository(); } else { - repLog.error("Cannot replicate {}; Remote repository error: {}", projectName, msg); + repLog.atSevere().log("Cannot replicate %s; Remote repository error: %s", projectName, msg); } } catch (NoRemoteRepositoryException e) { @@ -369,12 +365,12 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { } catch (TransportException e) { Throwable cause = e.getCause(); if (cause instanceof JSchException && cause.getMessage().startsWith("UnknownHostKey:")) { - repLog.error("Cannot replicate to {}: {}", uri, cause.getMessage()); + repLog.atSevere().log("Cannot replicate to %s: %s", uri, cause.getMessage()); } else if (e instanceof LockFailureException) { lockRetryCount++; // The LockFailureException message contains both URI and reason // for this failure. - repLog.error("Cannot replicate to {}: {}", uri, e.getMessage()); + repLog.atSevere().log("Cannot replicate to %s: %s", uri, e.getMessage()); // The remote push operation should be retried. if (lockRetryCount <= maxLockRetries) { @@ -384,17 +380,15 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { pool.reschedule(this, Destination.RetryReason.TRANSPORT_ERROR); } } else { - repLog.error( - "Giving up after {} occurrences of this error: {} during replication to {}", - lockRetryCount, - e.getMessage(), - uri); + repLog.atSevere().log( + "Giving up after %d occurrences of this error: %s during replication to %s", + lockRetryCount, e.getMessage(), uri); } } else { if (canceledWhileRunning.get()) { logCanceledWhileRunningException(e); } else { - repLog.error("Cannot replicate to {}", uri, e); + repLog.atSevere().withCause(e).log("Cannot replicate to %s", uri); // The remote push operation should be retried. pool.reschedule(this, Destination.RetryReason.TRANSPORT_ERROR); } @@ -412,7 +406,7 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { } private void logCanceledWhileRunningException(TransportException e) { - repLog.info("Cannot replicate to {}. It was canceled while running", uri, e); + repLog.atInfo().withCause(e).log("Cannot replicate to %s. It was canceled while running", uri); } private void createRepository() { @@ -421,10 +415,11 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { Ref head = git.exactRef(Constants.HEAD); if (replicationQueue.createProject( config.getName(), projectName, head != null ? getName(head) : null)) { - repLog.warn("Missing repository created; retry replication to {}", uri); + repLog.atWarning().log("Missing repository created; retry replication to %s", uri); pool.reschedule(this, Destination.RetryReason.REPOSITORY_MISSING); } else { - repLog.warn("Missing repository could not be created when replicating {}", uri); + repLog.atWarning().log( + "Missing repository could not be created when replicating %s", uri); } } catch (IOException ioe) { stateLog.error( @@ -467,7 +462,7 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning { return new PushResult(); } - repLog.info("Push to {} references: {}", uri, todo); + repLog.atSevere().log("Push to %s references: %s", uri, todo); return tn.push(NullProgressMonitor.INSTANCE, todo); } diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/RemoteSsh.java b/src/main/java/com/googlesource/gerrit/plugins/replication/RemoteSsh.java index ee9d4c0..e313079 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/RemoteSsh.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/RemoteSsh.java @@ -42,18 +42,14 @@ public class RemoteSsh implements AdminApi { OutputStream errStream = sshHelper.newErrorBufferStream(); try { sshHelper.executeRemoteSsh(uri, cmd, errStream); - repLog.info("Created remote repository: {}", uri); + repLog.atInfo().log("Created remote repository: %s", uri); } catch (IOException e) { - repLog.error( - "Error creating remote repository at {}:\n" - + " Exception: {}\n" - + " Command: {}\n" - + " Output: {}", - uri, - e, - cmd, - errStream, - e); + repLog.atSevere().withCause(e).log( + "Error creating remote repository at %s:\n" + + " Exception: %s\n" + + " Command: %s\n" + + " Output: %s", + uri, e, cmd, errStream); return false; } return true; @@ -66,18 +62,14 @@ public class RemoteSsh implements AdminApi { OutputStream errStream = sshHelper.newErrorBufferStream(); try { sshHelper.executeRemoteSsh(uri, cmd, errStream); - repLog.info("Deleted remote repository: {}", uri); + repLog.atInfo().log("Deleted remote repository: %s", uri); } catch (IOException e) { - repLog.error( - "Error deleting remote repository at {}:\n" - + " Exception: {}\n" - + " Command: {}\n" - + " Output: {}", - uri, - e, - cmd, - errStream, - e); + repLog.atSevere().withCause(e).log( + "Error deleting remote repository at %s}:\n" + + " Exception: %s\n" + + " Command: %s\n" + + " Output: %s", + uri, e, cmd, errStream); return false; } return true; @@ -92,17 +84,12 @@ public class RemoteSsh implements AdminApi { try { sshHelper.executeRemoteSsh(uri, cmd, errStream); } catch (IOException e) { - repLog.error( - "Error updating HEAD of remote repository at {} to {}:\n" - + " Exception: {}\n" - + " Command: {}\n" - + " Output: {}", - uri, - newHead, - e, - cmd, - errStream, - e); + repLog.atSevere().withCause(e).log( + "Error updating HEAD of remote repository at %s to %s:\n" + + " Exception: %s\n" + + " Command: %s\n" + + " Output: %s", + uri, newHead, e, cmd, errStream); return false; } return true; diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java index 0f03e57..ca8001a 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java @@ -31,6 +31,7 @@ import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.server.UsedAt; import com.google.gerrit.server.events.EventDispatcher; import com.google.gerrit.server.git.WorkQueue; +import com.google.gerrit.util.logging.NamedFluentLogger; import com.google.inject.Inject; import com.googlesource.gerrit.plugins.replication.PushResultProcessing.GitUpdateProcessing; import com.googlesource.gerrit.plugins.replication.ReplicationConfig.FilterType; @@ -42,8 +43,6 @@ import java.util.Optional; import java.util.Queue; import java.util.Set; import org.eclipse.jgit.transport.URIish; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** Manages automatic replication to remote repositories. */ public class ReplicationQueue @@ -52,7 +51,7 @@ public class ReplicationQueue ProjectDeletedListener, HeadUpdatedListener { static final String REPLICATION_LOG_NAME = "replication_log"; - static final Logger repLog = LoggerFactory.getLogger(REPLICATION_LOG_NAME); + static final NamedFluentLogger repLog = NamedFluentLogger.forName(REPLICATION_LOG_NAME); private final ReplicationStateListener stateLog; @@ -109,7 +108,7 @@ public class ReplicationQueue running = false; int discarded = config.shutdown(); if (discarded > 0) { - repLog.warn("Canceled {} replication events during shutdown", discarded); + repLog.atWarning().log("Canceled %d replication events during shutdown", discarded); } } @@ -199,7 +198,7 @@ public class ReplicationQueue for (ReplicationTasksStorage.ReplicateRefUpdate t : replicationTasksStorage.list()) { String eventKey = String.format("%s:%s", t.project, t.ref); if (!eventsReplayed.contains(eventKey)) { - repLog.info("Firing pending task {}", eventKey); + repLog.atInfo().log("Firing pending task %s", eventKey); onGitReferenceUpdated(t.project, t.ref); eventsReplayed.add(eventKey); } @@ -230,7 +229,7 @@ public class ReplicationQueue for (ReferenceUpdatedEvent event : beforeStartupEventsQueue) { String eventKey = String.format("%s:%s", event.getProjectName(), event.getRefName()); if (!eventsReplayed.contains(eventKey)) { - repLog.info("Firing pending task {}", event); + repLog.atInfo().log("Firing pending task %s", event); onGitReferenceUpdated(event.getProjectName(), event.getRefName()); eventsReplayed.add(eventKey); } @@ -243,7 +242,7 @@ public class ReplicationQueue return Collections.emptySet(); } if (!running) { - repLog.error("Replication plugin did not finish startup before event"); + repLog.atSevere().log("Replication plugin did not finish startup before event"); return Collections.emptySet(); } @@ -268,7 +267,7 @@ public class ReplicationQueue try { uri = new URIish(url); } catch (URISyntaxException e) { - repLog.warn("adminURL '{}' is invalid: {}", url, e.getMessage()); + repLog.atWarning().log("adminURL '%s' is invalid: %s", url, e.getMessage()); continue; } @@ -276,13 +275,13 @@ public class ReplicationQueue String path = replaceName(uri.getPath(), projectName.get(), config.isSingleProjectMatch()); if (path == null) { - repLog.warn("adminURL {} does not contain ${name}", uri); + repLog.atWarning().log("adminURL %s does not contain ${name}", uri); continue; } uri = uri.setPath(path); if (!isSSH(uri)) { - repLog.warn("adminURL '{}' is invalid: only SSH is supported", uri); + repLog.atWarning().log("adminURL '%s' is invalid: only SSH is supported", uri); continue; } } @@ -338,7 +337,7 @@ public class ReplicationQueue } private void warnCannotPerform(String op, URIish uri) { - repLog.warn("Cannot {} on remote site {}.", op, uri); + repLog.atWarning().log("Cannot %s on remote site %s.", op, uri); } private static class ReferenceUpdatedEvent { diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationStateLogger.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationStateLogger.java index f2d55de..3e73033 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationStateLogger.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationStateLogger.java @@ -31,19 +31,19 @@ public class ReplicationStateLogger implements ReplicationStateListener { @Override public void warn(String msg, ReplicationState... states) { stateWriteErr("Warning: " + msg, states); - repLog.warn(msg); + repLog.atWarning().log(msg); } @Override public void error(String msg, ReplicationState... states) { stateWriteErr("Error: " + msg, states); - repLog.error(msg); + repLog.atSevere().log(msg); } @Override public void error(String msg, Throwable t, ReplicationState... states) { stateWriteErr("Error: " + msg, states); - repLog.error(msg, t); + repLog.atSevere().withCause(t).log(msg); } private void stateWriteErr(String msg, ReplicationState[] states) { |