Skip to content

Commit

Permalink
Fix log format and swallow exception (apache#10252)
Browse files Browse the repository at this point in the history
Co-authored-by: linjunhua <[email protected]>
  • Loading branch information
linlinnn and linjunhua authored Apr 18, 2021
1 parent ce42e5b commit f6b0293
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -772,11 +772,10 @@ public Boolean get() {
}

// Start the task to publish resource usage, if necessary
if (config.getResourceUsageTransportClassName() != null
&& config.getResourceUsageTransportClassName() != "") {
if (isNotBlank(config.getResourceUsageTransportClassName())) {
Class<?> clazz = Class.forName(config.getResourceUsageTransportClassName());
Constructor<?> ctor = clazz.getConstructor(PulsarService.class);
Object object = ctor.newInstance(new Object[] { this });
Object object = ctor.newInstance(new Object[]{this});
this.resourceUsageTransportManager = (ResourceUsageTransportManager) object;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public boolean incrementUsage(String tenantName, String nsName,

// Expect stats to increase monotonically.
if (incStats.bytes < 0 || incStats.messages < 0) {
String errMesg = String.format("incrementUsage on tenant={}, NS={}: bytes ({}) or mesgs ({}) is negative",
String errMesg = String.format("incrementUsage on tenant=%s, NS=%s: bytes (%s) or mesgs (%s) is negative",
tenantName, nsName, incStats.bytes, incStats.messages);
throw new PulsarAdminException(errMesg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void run() {
byte[] bytes = buf.array();
producer.sendAsync(bytes).whenComplete((id, ex) -> {
if (null != ex) {
LOG.error("Resource usage publisher: sending message ID {} error {}", id, ex);
LOG.error("Resource usage publisher: sending message ID {} error", id, ex);
}
buf.release();
});
Expand Down Expand Up @@ -152,9 +152,11 @@ public void received(Reader<byte[]> reader, Message<byte[]> msg) {
});

} catch (IllegalStateException exception) {
LOG.error("Resource usage reader: Error parsing incoming message {}", exception);
LOG.error("Resource usage reader: Error parsing incoming message", exception);
throw exception;
} catch (Exception exception) {
LOG.error("Resource usage reader: Unknown exception while parsing message {}", exception);
LOG.error("Resource usage reader: Unknown exception while parsing message", exception);
throw exception;
}
}

Expand Down Expand Up @@ -192,8 +194,8 @@ private void createTenantAndNamespace() throws PulsarServerException, PulsarAdmi
} catch (PulsarAdminException ex1) {
if (!(ex1 instanceof PulsarAdminException.ConflictException)) {
LOG.error("Unexpected exception {} when creating tenant {}", ex1, tenant);
throw ex1;
}
throw ex1;
}
}
List<String> nsList = admin.namespaces().getNamespaces(tenant);
Expand All @@ -203,8 +205,8 @@ private void createTenantAndNamespace() throws PulsarServerException, PulsarAdmi
} catch (PulsarAdminException ex1) {
if (!(ex1 instanceof PulsarAdminException.ConflictException)) {
LOG.error("Unexpected exception {} when creating namespace {}", ex1, namespace);
throw ex1;
}
throw ex1;
}
}
}
Expand All @@ -218,7 +220,7 @@ public ResourceUsageTransportManager(PulsarService pulsarService) throws Excepti
consumer = new ResourceUsageReader();
pTask = new ResourceUsageWriterTask();
} catch (Exception ex) {
LOG.error("Error initializing resource usage transport manager: {}", ex);
LOG.error("Error initializing resource usage transport manager", ex);
throw ex;
}
}
Expand Down Expand Up @@ -265,7 +267,8 @@ public void close() throws Exception {
pTask.close();
consumer.close();
} catch (Exception ex1) {
LOG.error("Error closing producer/consumer for resource-usage topic {}", ex1);
LOG.error("Error closing producer/consumer for resource-usage topic", ex1);
throw ex1;
}
}
}

0 comments on commit f6b0293

Please sign in to comment.