From 9c992d7cb8b461dd081d7c3405a0ad0dfa0fc843 Mon Sep 17 00:00:00 2001 From: David Turner Date: Mon, 31 Jan 2022 10:16:15 +0000 Subject: [PATCH] Simplify logging in InternalClusterInfoService (#82673) In [1] we decided that the logging introduced in #66993 was a bit sneaky and not really the pattern we want to follow. We want to hide stack traces for boring network errors but in practice that means `NodeDisconnectedException` and `ReceiveTimeoutTransportException` whose stack traces are already suppressed (see #75671) so really it's fine to log the full exception at `WARN` level in all cases. This commit does that. [1] https://github.com/elastic/elasticsearch/pull/75544/files#r675113968 --- .../cluster/InternalClusterInfoService.java | 32 +++++++------------ 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/InternalClusterInfoService.java b/server/src/main/java/org/elasticsearch/cluster/InternalClusterInfoService.java index e60bf54c6e51..57980ec033f8 100644 --- a/server/src/main/java/org/elasticsearch/cluster/InternalClusterInfoService.java +++ b/server/src/main/java/org/elasticsearch/cluster/InternalClusterInfoService.java @@ -177,12 +177,10 @@ public void onResponse(NodesStatsResponse nodesStatsResponse) { logger.trace("received node stats response"); for (final FailedNodeException failure : nodesStatsResponse.failures()) { - final Throwable cause = failure.getCause(); - if (logger.isDebugEnabled()) { - logger.warn(new ParameterizedMessage("failed to retrieve stats for node [{}]", failure.nodeId()), cause); - } else { - logger.warn("failed to retrieve stats for node [{}]: {}", failure.nodeId(), cause.getMessage()); - } + logger.warn( + new ParameterizedMessage("failed to retrieve stats for node [{}]", failure.nodeId()), + failure.getCause() + ); } ImmutableOpenMap.Builder leastAvailableUsagesBuilder = ImmutableOpenMap.builder(); @@ -223,21 +221,13 @@ public void onResponse(IndicesStatsResponse indicesStatsResponse) { for (final DefaultShardOperationFailedException shardFailure : indicesStatsResponse.getShardFailures()) { if (shardFailure.getCause()instanceof final FailedNodeException failedNodeException) { if (failedNodeIds.add(failedNodeException.nodeId())) { - if (logger.isDebugEnabled()) { - logger.warn( - new ParameterizedMessage( - "failed to retrieve shard stats from node [{}]", - failedNodeException.nodeId() - ), - failedNodeException - ); - } else { - logger.warn( - "failed to retrieve shard stats from node [{}]: {}", - failedNodeException.nodeId(), - failedNodeException.getCause().getMessage() - ); - } + logger.warn( + new ParameterizedMessage( + "failed to retrieve shard stats from node [{}]", + failedNodeException.nodeId() + ), + failedNodeException.getCause() + ); } logger.trace( new ParameterizedMessage(