Skip to content

Commit 47c0e13

Browse files
authored
Stop returning "es." internal exception headers as http response headers (#22703)
move "es." internal headers to separate metadata set in ElasticsearchException and stop returning them as response headers Closes #17593 * [TEST] remove ESExceptionTests, move its methods to ElasticsearchExceptionTests or ExceptionSerializationTests
1 parent 12f5309 commit 47c0e13

File tree

13 files changed

+656
-565
lines changed

13 files changed

+656
-565
lines changed

buildSrc/src/main/resources/checkstyle_suppressions.xml

-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@
161161
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]ingest[/\\]SimulatePipelineRequestBuilder.java" checks="LineLength" />
162162
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]ingest[/\\]SimulatePipelineTransportAction.java" checks="LineLength" />
163163
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]search[/\\]MultiSearchRequestBuilder.java" checks="LineLength" />
164-
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]search[/\\]SearchPhaseExecutionException.java" checks="LineLength" />
165164
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]search[/\\]SearchResponse.java" checks="LineLength" />
166165
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]search[/\\]ShardSearchFailure.java" checks="LineLength" />
167166
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]search[/\\]TransportClearScrollAction.java" checks="LineLength" />
@@ -533,7 +532,6 @@
533532
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]threadpool[/\\]ThreadPool.java" checks="LineLength" />
534533
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]apache[/\\]lucene[/\\]queries[/\\]BlendedTermQueryTests.java" checks="LineLength" />
535534
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]apache[/\\]lucene[/\\]search[/\\]postingshighlight[/\\]CustomPostingsHighlighterTests.java" checks="LineLength" />
536-
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]ESExceptionTests.java" checks="LineLength" />
537535
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]NamingConventionTests.java" checks="LineLength" />
538536
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]VersionTests.java" checks="LineLength" />
539537
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]RejectionActionIT.java" checks="LineLength" />

core/src/main/java/org/elasticsearch/ElasticsearchException.java

+112-47
Large diffs are not rendered by default.

core/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ protected void metadataToXContent(XContentBuilder builder, Params params) throws
138138
builder.field("grouped", group); // notify that it's grouped
139139
builder.field("failed_shards");
140140
builder.startArray();
141-
ShardOperationFailedException[] failures = params.paramAsBoolean("group_shard_failures", true) ? ExceptionsHelper.groupBy(shardFailures) : shardFailures;
141+
ShardOperationFailedException[] failures = params.paramAsBoolean("group_shard_failures", true) ?
142+
ExceptionsHelper.groupBy(shardFailures) : shardFailures;
142143
for (ShardOperationFailedException failure : failures) {
143144
builder.startObject();
144145
failure.toXContent(builder, params);
@@ -156,7 +157,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
156157
// We don't have a cause when all shards failed, but we do have shards failures so we can "guess" a cause
157158
// (see {@link #getCause()}). Here, we use super.getCause() because we don't want the guessed exception to
158159
// be rendered twice (one in the "cause" field, one in "failed_shards")
159-
innerToXContent(builder, params, this, getExceptionName(), getMessage(), getHeaders(), super.getCause());
160+
innerToXContent(builder, params, this, getExceptionName(), getMessage(), getHeaders(), getMetadata(), super.getCause());
160161
}
161162
return builder;
162163
}

core/src/main/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeAction.java

-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,6 @@ private void onShardOperation(final NodeRequest request, final Object[] shardRes
438438
} catch (Exception e) {
439439
BroadcastShardOperationFailedException failure =
440440
new BroadcastShardOperationFailedException(shardRouting.shardId(), "operation " + actionName + " failed", e);
441-
failure.setIndex(shardRouting.getIndexName());
442441
failure.setShard(shardRouting.shardId());
443442
shardResults[shardIndex] = failure;
444443
if (TransportActions.isShardNotAvailableException(e)) {

core/src/main/java/org/elasticsearch/common/io/stream/NotSerializableExceptionWrapper.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public final class NotSerializableExceptionWrapper extends ElasticsearchExceptio
3838
private final RestStatus status;
3939

4040
public NotSerializableExceptionWrapper(Throwable other) {
41-
super(ElasticsearchException.getExceptionName(other) +
42-
": " + other.getMessage(), other.getCause());
41+
super(ElasticsearchException.getExceptionName(other) + ": " + other.getMessage(), other.getCause());
4342
this.name = ElasticsearchException.getExceptionName(other);
4443
this.status = ExceptionsHelper.status(other);
4544
setStackTrace(other.getStackTrace());
@@ -51,6 +50,9 @@ public NotSerializableExceptionWrapper(Throwable other) {
5150
for (String key : ex.getHeaderKeys()) {
5251
this.addHeader(key, ex.getHeader(key));
5352
}
53+
for (String key : ex.getMetadataKeys()) {
54+
this.addMetadata(key, ex.getMetadata(key));
55+
}
5456
}
5557
}
5658

0 commit comments

Comments
 (0)