This is an automated email from the ASF dual-hosted git repository.
tmaret pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-journal.git
The following commit(s) were added to refs/heads/master by this push:
new 479dcb4 SLING-10066 - Align the package logs with the
PackageMessage#toString method
479dcb4 is described below
commit 479dcb4f9784a152ebcc3a37fa6e172544754911
Author: tmaret <[email protected]>
AuthorDate: Fri Mar 12 18:08:35 2021 +0100
SLING-10066 - Align the package logs with the PackageMessage#toString method
---
.../distribution/journal/bookkeeper/BookKeeper.java | 15 +++------------
.../impl/publisher/DistributionPublisher.java | 21 ++++++++++++---------
.../shared/DistributionLogEventListener.java | 2 +-
.../shared/DistributionLogEventListenerTest.java | 2 +-
4 files changed, 17 insertions(+), 23 deletions(-)
diff --git
a/src/main/java/org/apache/sling/distribution/journal/bookkeeper/BookKeeper.java
b/src/main/java/org/apache/sling/distribution/journal/bookkeeper/BookKeeper.java
index 5120d08..f8a6b18 100644
---
a/src/main/java/org/apache/sling/distribution/journal/bookkeeper/BookKeeper.java
+++
b/src/main/java/org/apache/sling/distribution/journal/bookkeeper/BookKeeper.java
@@ -28,7 +28,6 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
@@ -140,9 +139,7 @@ public class BookKeeper implements Closeable {
* once, thanks to the order in which the content updates are applied.
*/
public void importPackage(PackageMessage pkgMsg, long offset, long
createdTime) throws DistributionException {
- String firstPath = getFirstPath(pkgMsg);
- log.info("Importing distribution package {} of type {} at offset {}
first path {} url {}",
- pkgMsg.getPkgId(), pkgMsg.getReqType(), offset, firstPath,
pkgMsg.getPkgBinaryRef());
+ log.info("Importing distribution package {} at offset {}", pkgMsg,
offset);
addPackageMDC(pkgMsg);
try (Timer.Context context =
distributionMetricsService.getImportedPackageDuration().time();
ResourceResolver importerResolver =
getServiceResolver(SUBSERVICE_IMPORTER)) {
@@ -194,9 +191,8 @@ public class BookKeeper implements Closeable {
int retries = packageRetries.get(pubAgentName);
boolean giveUp = errorQueueEnabled && retries >=
config.getMaxRetries();
String retriesSt = errorQueueEnabled ?
Integer.toString(config.getMaxRetries()) : "infinite";
- String action = giveUp ? "removing the package" : "retrying";
- String firstPath = getFirstPath(pkgMsg);
- String msg = format("Error processing distribution package %s at
offset %d first path %s. Retry attempts %s/%s. Url: %s, %s, Message: %s",
pkgMsg.getPkgId(), offset, firstPath, retries, retriesSt,
pkgMsg.getPkgBinaryRef(), action, e.getMessage());
+ String action = giveUp ? "skip the package" : "retry later";
+ String msg = format("Failed attempt (%s/%s) to import the distribution
package %s at offset %d because of '%s', the importer will %s", retries,
retriesSt, pkgMsg, offset, e.getMessage(), action);
try {
LogMessage logMessage = getLogMessage(pubAgentName, msg, e);
logSender.accept(logMessage);
@@ -346,11 +342,6 @@ public class BookKeeper implements Closeable {
private ResourceResolver getServiceResolver(String subService) throws
LoginException {
return
resolverFactory.getServiceResourceResolver(singletonMap(SUBSERVICE,
subService));
}
-
- private String getFirstPath(PackageMessage pkg) {
- Iterator<String> it = pkg.getPaths().iterator();
- return it.hasNext() ? it.next() : "";
- }
static void retryDelay() {
try {
diff --git
a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DistributionPublisher.java
b/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DistributionPublisher.java
index e453b40..4645474 100644
---
a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DistributionPublisher.java
+++
b/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DistributionPublisher.java
@@ -265,22 +265,25 @@ public class DistributionPublisher implements
DistributionAgent {
DistributionRequest request,
Consumer<PackageMessage> sender)
throws DistributionException {
+ final PackageMessage pkg;
try {
- PackageMessage pkg =
timed(distributionMetricsService.getBuildPackageDuration(),
- () -> factory.create(packageBuilder, resourceResolver,
pubAgentName, request)
- );
- timed(distributionMetricsService.getEnqueuePackageDuration(),
- () -> sender.accept(pkg)
- );
+ pkg = timed(distributionMetricsService.getBuildPackageDuration(),
() -> factory.create(packageBuilder, resourceResolver, pubAgentName, request));
+ } catch (Exception e) {
+ distributionMetricsService.getDroppedRequests().mark();
+ log.error("Failed to create content package for requestType={},
paths={}", request.getRequestType(), request.getPaths(), e);
+ throw new DistributionException(e);
+ }
+
+ try {
+ timed(distributionMetricsService.getEnqueuePackageDuration(), ()
-> sender.accept(pkg));
distributionMetricsService.getExportedPackageSize().update(pkg.getPkgLength());
distributionMetricsService.getAcceptedRequests().mark();
- String firstPath = pkg.getPaths().iterator().next();
- String msg = String.format("Distribution request accepted with
type %s paths %s, package id %s, url %s", request.getRequestType(), firstPath,
pkg.getPkgId(), pkg.getPkgBinaryRef());
+ String msg = String.format("Distribution request accepted with
%s", pkg);
log.info(msg);
return new SimpleDistributionResponse(ACCEPTED, msg);
} catch (Throwable e) {
distributionMetricsService.getDroppedRequests().mark();
- String msg = String.format("Failed to queue distribution request
%s", e.getMessage());
+ String msg = String.format("Failed to append %s to the journal",
pkg);
log.error(msg, e);
if (e instanceof Error) {
throw (Error) e;
diff --git
a/src/main/java/org/apache/sling/distribution/journal/shared/DistributionLogEventListener.java
b/src/main/java/org/apache/sling/distribution/journal/shared/DistributionLogEventListener.java
index a077df6..015f2c1 100644
---
a/src/main/java/org/apache/sling/distribution/journal/shared/DistributionLogEventListener.java
+++
b/src/main/java/org/apache/sling/distribution/journal/shared/DistributionLogEventListener.java
@@ -79,7 +79,7 @@ public class DistributionLogEventListener implements
EventHandler, Closeable {
String[] paths =
(String[])event.getProperty(DistributionEventProperties.DISTRIBUTION_PATHS);
String type =
(String)event.getProperty(DistributionEventProperties.DISTRIBUTION_TYPE);
String packageId =
(String)event.getProperty(DistributionEvent.PACKAGE_ID);
- log.info("Succesfully applied package with id {}, type {}, paths {}",
packageId, type, paths);
+ log.info("Successfully applied package with id {}, type {}, paths {}",
packageId, type, paths);
}
@Override
diff --git
a/src/test/java/org/apache/sling/distribution/journal/shared/DistributionLogEventListenerTest.java
b/src/test/java/org/apache/sling/distribution/journal/shared/DistributionLogEventListenerTest.java
index f2d4370..dc23d29 100644
---
a/src/test/java/org/apache/sling/distribution/journal/shared/DistributionLogEventListenerTest.java
+++
b/src/test/java/org/apache/sling/distribution/journal/shared/DistributionLogEventListenerTest.java
@@ -83,7 +83,7 @@ public class DistributionLogEventListenerTest {
Event event = new
Event(DistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED, props);
listener.handleEvent(event);
String line = log.getLines().iterator().next();
- assertThat(line, endsWith("Succesfully applied package with id
packageId, type Add, paths [/test]"));
+ assertThat(line, endsWith("Successfully applied package with id
packageId, type Add, paths [/test]"));
}
@Test