Skip to content

Commit e1a091f

Browse files
authored
Skip stacktrace for exceptions when stacktrace is not relevant. (#110785)
These exceptions are expected and don't imply bugs, their stacktrace isn't relevant and should not be logged. Relates to ES-7097
1 parent 384b6a9 commit e1a091f

File tree

8 files changed

+38
-5
lines changed

8 files changed

+38
-5
lines changed

server/src/main/java/org/elasticsearch/action/NoShardAvailableActionException.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
public final class NoShardAvailableActionException extends ElasticsearchException {
2020

21-
private static final StackTraceElement[] EMPTY_STACK_TRACE = new StackTraceElement[0];
22-
2321
// This is set so that no StackTrace is serialized in the scenario when we wrap other shard failures.
2422
// It isn't necessary to serialize this field over the wire as the empty stack trace is serialized instead.
2523
private final boolean onShardFailureWrapper;
@@ -57,8 +55,8 @@ public NoShardAvailableActionException(StreamInput in) throws IOException {
5755
}
5856

5957
@Override
60-
public StackTraceElement[] getStackTrace() {
61-
return onShardFailureWrapper ? EMPTY_STACK_TRACE : super.getStackTrace();
58+
public Throwable fillInStackTrace() {
59+
return this; // this exception doesn't imply a bug, no need for a stack trace
6260
}
6361

6462
@Override
@@ -67,7 +65,7 @@ public void printStackTrace(PrintWriter s) {
6765
super.printStackTrace(s);
6866
} else {
6967
// Override to simply print the first line of the trace, which is the current exception.
70-
// Since we aren't serializing the repetitive stacktrace onShardFailureWrapper, we shouldn't print it out either
68+
// Note: This will also omit the cause chain or any suppressed exceptions.
7169
s.println(this);
7270
}
7371
}

server/src/main/java/org/elasticsearch/action/UnavailableShardsException.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ public UnavailableShardsException(StreamInput in) throws IOException {
4545
public RestStatus status() {
4646
return RestStatus.SERVICE_UNAVAILABLE;
4747
}
48+
49+
@Override
50+
public Throwable fillInStackTrace() {
51+
return this; // this exception doesn't imply a bug, no need for a stack trace
52+
}
4853
}

server/src/main/java/org/elasticsearch/cluster/block/ClusterBlockException.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public ClusterBlockException(StreamInput in) throws IOException {
3838
this.blocks = in.readCollectionAsImmutableSet(ClusterBlock::new);
3939
}
4040

41+
@Override
42+
public Throwable fillInStackTrace() {
43+
return this; // this exception doesn't imply a bug, no need for a stack trace
44+
}
45+
4146
@Override
4247
protected void writeTo(StreamOutput out, Writer<Throwable> nestedExceptionsWriter) throws IOException {
4348
super.writeTo(out, nestedExceptionsWriter);

server/src/main/java/org/elasticsearch/common/util/concurrent/EsRejectedExecutionException.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public EsRejectedExecutionException() {
2727
this(null, false);
2828
}
2929

30+
@Override
31+
public Throwable fillInStackTrace() {
32+
return this; // this exception doesn't imply a bug, no need for a stack trace
33+
}
34+
3035
/**
3136
* Checks if the thread pool that rejected the execution was terminated
3237
* shortly after the rejection. Its possible that this returns false and the

server/src/main/java/org/elasticsearch/discovery/MasterNotDiscoveredException.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ public RestStatus status() {
3232
public MasterNotDiscoveredException(StreamInput in) throws IOException {
3333
super(in);
3434
}
35+
36+
@Override
37+
public Throwable fillInStackTrace() {
38+
return this; // this exception doesn't imply a bug, no need for a stack trace
39+
}
3540
}

server/src/main/java/org/elasticsearch/node/NodeClosedException.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ public NodeClosedException(DiscoveryNode node) {
2828
public NodeClosedException(StreamInput in) throws IOException {
2929
super(in);
3030
}
31+
32+
@Override
33+
public Throwable fillInStackTrace() {
34+
return this; // this exception doesn't imply a bug, no need for a stack trace
35+
}
3136
}

server/src/main/java/org/elasticsearch/search/aggregations/MultiBucketConsumerService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public TooManyBucketsException(StreamInput in) throws IOException {
6565
maxBuckets = in.readInt();
6666
}
6767

68+
@Override
69+
public Throwable fillInStackTrace() {
70+
return this; // this exception doesn't imply a bug, no need for a stack trace
71+
}
72+
6873
@Override
6974
protected void writeTo(StreamOutput out, Writer<Throwable> nestedExceptionsWriter) throws IOException {
7075
super.writeTo(out, nestedExceptionsWriter);

server/src/main/java/org/elasticsearch/transport/NodeNotConnectedException.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,9 @@ public NodeNotConnectedException(DiscoveryNode node, String msg) {
2727
public NodeNotConnectedException(StreamInput in) throws IOException {
2828
super(in);
2929
}
30+
31+
@Override
32+
public Throwable fillInStackTrace() {
33+
return this; // this exception doesn't imply a bug, no need for a stack trace
34+
}
3035
}

0 commit comments

Comments
 (0)