Skip to content

Use status code 500 for errors if no shard failed #88551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

salvatore-campagna
Copy link
Contributor

If there is no shard failure we would like to use a generic
Internal Server Error other than a Service Unavailable.
Moreover, if the cause is known we use a status code that
reflects the cause.

Resolves #20004

If there is no shard failure we would like to use a generic
Internal Server Error other than a Service Unavailable.
Moreover, if the cause is known we use a status code that
reflects the cause.

Resolves elastic#20004
@salvatore-campagna salvatore-campagna added >bug :Search/Search Search-related issues that do not fall into other categories labels Jul 14, 2022
@elasticmachine elasticmachine added the Team:Search Meta label for search team label Jul 14, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@elasticsearchmachine
Copy link
Collaborator

Hi @salvatore-campagna, I've created a changelog YAML for you.

@salvatore-campagna salvatore-campagna changed the title fix: use status code 500 for errors if no shard failed Use status code 500 for errors if no shard failed Jul 22, 2022
Copy link
Contributor

@csoulios csoulios left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally the code looks good. I have left a minor comment.

However, I must admit I am not an expert on the related code. So @nik9000 or @not-napoleon could have a better opinion here.

RestStatus status = shardFailures[0].status();
if (shardFailures.length > 1) {
for (int i = 1; i < shardFailures.length; i++) {
if (shardFailures[i].status().getStatus() >= 500) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a big fan of the hardcoded 500 value here.
Is there any way to add a constant such as RestStatus.INTERNAL_SERVER_ERROR.getStatus()

Also, should you perhaps delegate this to the RestStatus.status() method?

Would running something like RestStatus.status(0, shardFailures.length, shardFailures) return the same result? Again, I am not an expert on this part of the code, so take this with a grain of salt.

Copy link
Member

@not-napoleon not-napoleon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Left a couple of nits, but I think this is a fine approach.

@@ -161,4 +161,8 @@ public String toString() {
public String getPhaseName() {
return phaseName;
}

public ShardSearchFailure[] getShardFailures() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be package scoped?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there is already a method shardFailures() which I didn't see...so I will use the existing one and get rid of the one I added.

}
}
return status;
return super.status();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's much better :)

@salvatore-campagna salvatore-campagna merged commit 9e0cd2f into elastic:master Jul 22, 2022
@javanna
Copy link
Member

javanna commented Aug 9, 2022

Heya, have we thought about possible consequences in clients code around changing the status code here? I've seen this is marked bug hence it is not considered a breaking change, I assume. But was this discussed before merging?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team v8.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search reduce failures map to 503 status code
6 participants