This is an automated email from the ASF dual-hosted git repository.

penghui pushed a commit to branch branch-2.11
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/branch-2.11 by this push:
     new 1984fd64fcd [improve][schema] Do not print error log with stacktrace 
for 404 (#19130)
1984fd64fcd is described below

commit 1984fd64fcd8f07f8c6df50b3955595a11a869ad
Author: Penghui Li <[email protected]>
AuthorDate: Thu Jan 5 10:12:39 2023 +0800

    [improve][schema] Do not print error log with stacktrace for 404 (#19130)
    
    (cherry picked from commit 3afc29186a3532f1cd2e50aa2caf42facaaafe5c)
---
 .../apache/pulsar/broker/admin/AdminResource.java    |  7 +++++++
 .../broker/admin/impl/SchemasResourceBase.java       |  5 +++++
 .../pulsar/broker/admin/v2/SchemasResource.java      | 20 ++++++++++----------
 3 files changed, 22 insertions(+), 10 deletions(-)

diff --git 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java
index ad0564b33a8..79002bbdc6a 100644
--- 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java
+++ 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java
@@ -838,6 +838,13 @@ public abstract class AdminResource extends 
PulsarWebResource {
                 == Status.TEMPORARY_REDIRECT.getStatusCode();
     }
 
+    protected static boolean isNotFoundException(Throwable ex) {
+        Throwable realCause = FutureUtil.unwrapCompletionException(ex);
+        return realCause instanceof WebApplicationException
+                && ((WebApplicationException) 
realCause).getResponse().getStatus()
+                == Status.NOT_FOUND.getStatusCode();
+    }
+
     protected static String getTopicNotFoundErrorMessage(String topic) {
         return String.format("Topic %s not found", topic);
     }
diff --git 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/SchemasResourceBase.java
 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/SchemasResourceBase.java
index 3295d12cff5..55fa5296c35 100644
--- 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/SchemasResourceBase.java
+++ 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/SchemasResourceBase.java
@@ -434,5 +434,10 @@ public class SchemasResourceBase extends AdminResource {
                 .thenCompose(__ -> validateTopicOperationAsync(topicName, 
operation));
     }
 
+
+    protected boolean shouldPrintErrorLog(Throwable ex) {
+        return !isRedirectException(ex) && !isNotFoundException(ex);
+    }
+
     private static final Logger log = 
LoggerFactory.getLogger(SchemasResourceBase.class);
 }
diff --git 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/SchemasResource.java
 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/SchemasResource.java
index 335510f0893..aaaf865dd5d 100644
--- 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/SchemasResource.java
+++ 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/SchemasResource.java
@@ -89,10 +89,10 @@ public class SchemasResource extends SchemasResourceBase {
             @Suspended final AsyncResponse response) {
         validateTopicName(tenant, namespace, topic);
         getSchemaAsync(authoritative)
-                .thenApply(schemaAndMetadata -> 
convertToSchemaResponse(schemaAndMetadata))
+                .thenApply(this::convertToSchemaResponse)
                 .thenApply(response::resume)
                 .exceptionally(ex -> {
-                    if (!isRedirectException(ex)) {
+                    if (shouldPrintErrorLog(ex)) {
                         log.error("[{}] Failed to get schema for topic {}", 
clientAppId(), topicName, ex);
                     }
                     resumeAsyncResponseExceptionally(response, ex);
@@ -122,10 +122,10 @@ public class SchemasResource extends SchemasResourceBase {
             @Suspended final AsyncResponse response) {
         validateTopicName(tenant, namespace, topic);
         getSchemaAsync(authoritative, version)
-                .thenApply(schemaAndMetadata -> 
convertToSchemaResponse(schemaAndMetadata))
+                .thenApply(this::convertToSchemaResponse)
                 .thenAccept(response::resume)
                 .exceptionally(ex -> {
-                    if (!isRedirectException(ex)) {
+                    if (shouldPrintErrorLog(ex)) {
                         log.error("[{}] Failed to get schema for topic {} with 
version {}",
                                 clientAppId(), topicName, version, ex);
                     }
@@ -155,10 +155,10 @@ public class SchemasResource extends SchemasResourceBase {
             @Suspended final AsyncResponse response) {
         validateTopicName(tenant, namespace, topic);
         getAllSchemasAsync(authoritative)
-                .thenApply(schemaAndMetadata -> 
convertToAllVersionsSchemaResponse(schemaAndMetadata))
+                .thenApply(this::convertToAllVersionsSchemaResponse)
                 .thenAccept(response::resume)
                 .exceptionally(ex -> {
-                    if (!isRedirectException(ex)) {
+                    if (shouldPrintErrorLog(ex)) {
                         log.error("[{}] Failed to get all schemas for topic 
{}", clientAppId(), topicName, ex);
                     }
                     resumeAsyncResponseExceptionally(response, ex);
@@ -191,7 +191,7 @@ public class SchemasResource extends SchemasResourceBase {
                     
response.resume(DeleteSchemaResponse.builder().version(getLongSchemaVersion(version)).build());
                 })
                 .exceptionally(ex -> {
-                    if (!isRedirectException(ex)) {
+                    if (shouldPrintErrorLog(ex)) {
                         log.error("[{}] Failed to delete schemas for topic 
{}", clientAppId(), topicName, ex);
                     }
                     resumeAsyncResponseExceptionally(response, ex);
@@ -238,7 +238,7 @@ public class SchemasResource extends SchemasResourceBase {
                         response.resume(Response.status(422, /* Unprocessable 
Entity */
                                 root.getMessage()).build());
                     } else {
-                        if (!isRedirectException(ex)) {
+                        if (shouldPrintErrorLog(ex)) {
                             log.error("[{}] Failed to post schemas for topic 
{}", clientAppId(), topicName, root);
                         }
                         resumeAsyncResponseExceptionally(response, ex);
@@ -278,7 +278,7 @@ public class SchemasResource extends SchemasResourceBase {
                                 
.schemaCompatibilityStrategy(pair.getRight().name()).build())
                         .build()))
                 .exceptionally(ex -> {
-                    if (!isRedirectException(ex)) {
+                    if (shouldPrintErrorLog(ex)) {
                         log.error("[{}] Failed to test compatibility for topic 
{}", clientAppId(), topicName, ex);
                     }
                     resumeAsyncResponseExceptionally(response, ex);
@@ -315,7 +315,7 @@ public class SchemasResource extends SchemasResourceBase {
         getVersionBySchemaAsync(payload, authoritative)
                 .thenAccept(version -> 
response.resume(LongSchemaVersionResponse.builder().version(version).build()))
                 .exceptionally(ex -> {
-                    if (!isRedirectException(ex)) {
+                    if (shouldPrintErrorLog(ex)) {
                         log.error("[{}] Failed to get version by schema for 
topic {}", clientAppId(), topicName, ex);
                     }
                     resumeAsyncResponseExceptionally(response, ex);

Reply via email to