Improve fetch logging by adding replication task id and refs list Add replication task id and list of refs included in that replication fetch task. This allows better tracking of the replication fetch task steps. Change-Id: I929423f2a2db468f73f16a91b47e64ca27e94e29
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/FetchOne.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/FetchOne.java index 4fad8f9..1fc3613 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/FetchOne.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/FetchOne.java
@@ -92,6 +92,7 @@ private final int maxLockRetries; private int lockRetryCount; private final int id; + private String taskIdHex; private final long createdAt; private final FetchReplicationMetrics metrics; private final AtomicBoolean canceledWhileRunning; @@ -120,6 +121,7 @@ lockRetryCount = 0; maxLockRetries = pool.getLockErrorMaxRetries(); id = ig.next(); + taskIdHex = HexFormat.fromInt(id); stateLog = sl; createdAt = System.nanoTime(); metrics = m; @@ -159,7 +161,7 @@ @Override public String toString() { - String print = "[" + HexFormat.fromInt(id) + "] fetch " + uri; + String print = "[" + taskIdHex + "] fetch " + uri; if (retryCount > 0) { print = "(retry " + retryCount + ") " + print; @@ -289,13 +291,19 @@ if (!pool.requestRunway(this)) { if (!canceled) { repLog.info( - "Rescheduling replication to {} to avoid collision with an in-flight fetch.", uri); + "Rescheduling [{}] replication to {} to avoid collision with an in-flight fetch.", + taskIdHex, + uri); pool.reschedule(this, Source.RetryReason.COLLISION); } return; } - repLog.info("Replication from {} started...", uri); + repLog.info( + "Replication [{}] from {} started for refs [{}] ...", + taskIdHex, + uri, + String.join(",", getRefs())); Timer1.Context<String> context = metrics.start(config.getName()); try { long startedAt = context.getStartTime(); @@ -309,7 +317,8 @@ .flatMap(metrics -> metrics.stop(config.getName())) .map(NANOSECONDS::toMillis); repLog.info( - "Replication from {} completed in {}ms, {}ms delay, {} retries{}", + "Replication [{}] from {} completed in {}ms, {}ms delay, {} retries{}", + taskIdHex, uri, elapsed, delay, @@ -325,18 +334,19 @@ // does not exist. In this case NoRemoteRepositoryException is not // raised. String msg = e.getMessage(); - repLog.error("Cannot replicate {}; Remote repository error: {}", projectName, msg); + repLog.error( + "Cannot replicate [{}] {}; Remote repository error: {}", taskIdHex, projectName, msg); } catch (NotSupportedException e) { stateLog.error("Cannot replicate from " + uri, e, getStatesAsArray()); } catch (TransportException e) { Throwable cause = e.getCause(); if (cause instanceof JSchException && cause.getMessage().startsWith("UnknownHostKey:")) { - repLog.error("Cannot replicate from {}: {}", uri, cause.getMessage()); + repLog.error("Cannot replicate [{}] from {}: {}", taskIdHex, uri, cause.getMessage()); } else if (e instanceof LockFailureException) { lockRetryCount++; // The LockFailureException message contains both URI and reason // for this failure. - repLog.error("Cannot replicate from {}: {}", uri, e.getMessage()); + repLog.error("Cannot replicate [{}] from {}: {}", taskIdHex, uri, e.getMessage()); // The remote fetch operation should be retried. if (lockRetryCount <= maxLockRetries) { @@ -347,16 +357,17 @@ } } else { repLog.error( - "Giving up after {} occurrences of this error: {} during replication from {}", + "Giving up after {} occurrences of this error: {} during replication from [{}] {}", lockRetryCount, e.getMessage(), + taskIdHex, uri); } } else { if (canceledWhileRunning.get()) { logCanceledWhileRunningException(e); } else { - repLog.error("Cannot replicate from {}", uri, e); + repLog.error("Cannot replicate [{}] from {}", taskIdHex, uri, e); // The remote fetch operation should be retried. pool.reschedule(this, Source.RetryReason.TRANSPORT_ERROR); } @@ -374,7 +385,7 @@ } private void logCanceledWhileRunningException(TransportException e) { - repLog.info("Cannot replicate from {}. It was canceled while running", uri, e); + repLog.info("Cannot replicate [{}] from {}. It was canceled while running", taskIdHex, uri, e); } private void runImpl() throws IOException {