Skip to content
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

Raise a 404 exception when document source is not found (#33384) #34083

Merged
merged 15 commits into from Nov 27, 2018
Merged

Raise a 404 exception when document source is not found (#33384) #34083

merged 15 commits into from Nov 27, 2018

Conversation

cbismuth
Copy link
Contributor

This pull request makes the RestGetSourceAction return a ResourceNotFoundException with a proper JSON response when source or document itself is missing (see issue #33384).

Here is below a sample JSON output:

{
  "error": {
    "root_cause": [
      {
        "type": "resource_not_found_exception",
        "reason": "Document or source not found [index1]/[_doc]/[1]"
      }
    ],
    "type": "resource_not_found_exception",
    "reason": "Document or source not found [index1]/[_doc]/[1]"
  },
  "status": 404
}

@markharwood markharwood added >bug :Data Management/Indices APIs APIs to create and manage indices and templates labels Sep 27, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@cbismuth
Copy link
Contributor Author

Hi, this PR is synced with master and tests are all green, it's ready for review. I stay available for any further change, thank you.

@cbismuth
Copy link
Contributor Author

Hi, this PR is synced with master and tests are all green, it's ready for review. I stay available for any further change, thank you.

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

I left a couple of inline comments. One for a slightly better result and a couple of small ones about hte test. Thanks @cbismuth!

assertThat(restResponse.content(), equalTo(new BytesArray("{\"foo\": \"bar\"}")));
}

public void testRestGetSourceAction_withNullSource() {
Copy link
Member

Choose a reason for hiding this comment

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

I don't tend to like the _ in the method name. I'd just keep the camel case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries, let's keep the camel case, fixed in 40a59bc.

}

public void testRestGetSourceAction() throws Exception {
// GIVEN a REST Get Source action response with an existing result and a non-null source
Copy link
Member

Choose a reason for hiding this comment

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

I don't think the GIVEN, WHEN, THEN comments buy much here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you're right, fixed in c168b67.

final String type = response.getType();
final String id = response.getId();

throw new ResourceNotFoundException("Document or source not found [" + index + "]/[" + type + "]/[" + id + "]");
Copy link
Member

Choose a reason for hiding this comment

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

If you check the exists flag then is set the we could return "document not found" rather than "source not found".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Fixed in 3fac7c9, thank you 👍

@nik9000
Copy link
Member

nik9000 commented Oct 30, 2018

@elasticmachine, test this please

@cbismuth
Copy link
Contributor Author

Hi @nik9000, thank you for you review, I've updated this PR and synced it with master, it's ready for review again 👍

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

I left a small thing. Could you fix it for my own paranoia?

* @throws ResourceNotFoundException if source or doc itself is missing
*/
private void checkIfSourceEmpty(final GetResponse response) {
if (response.isSourceEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to check isExists first because, at least in my head, isSourceEmpty doesn't really make sense if the document doesn't exist. I know it works to do it this way, but it'd make me feel better to switch the order.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're totally right.

@nik9000
Copy link
Member

nik9000 commented Oct 31, 2018

@elasticmachine, test this please

@nik9000
Copy link
Member

nik9000 commented Oct 31, 2018

@elasticmachine, test this please

@nik9000 nik9000 added the v7.0.0 label Oct 31, 2018
@cbismuth
Copy link
Contributor Author

No paranoia at all, you're totally right, the validation workflow is better now (see c3c9be0), thank you @nik9000 👍

@nik9000 nik9000 added the v6.6.0 label Oct 31, 2018
@nik9000
Copy link
Member

nik9000 commented Oct 31, 2018

Thanks for iterating on it with me @cbismuth! I've kicked off a CI build for it. When it passes I'll merge it and backport it to 6.x. I wasn't 100% convinced that backporting to 6.x is appropriate because it is technically breaking, but empty string is already invalid JSON so I'm fine with declaring this a bug in the 6.x series and worth of this minor break.

@nik9000
Copy link
Member

nik9000 commented Oct 31, 2018

@elasticmachine, retest this please

@cbismuth
Copy link
Contributor Author

You're welcome @nik9000. I've just fixed Netty4HeadBodyIsEmptyIT#testGetSourceAction which failed because REST response is no longer an empty JSON (i.e. content length is now greater than 0).

Could you please trigger a CI build? Thanks you.

@nik9000
Copy link
Member

nik9000 commented Nov 2, 2018

@elasticmachine, test this please

@nik9000
Copy link
Member

nik9000 commented Nov 2, 2018

@elasticmachine retest this please

@nik9000
Copy link
Member

nik9000 commented Nov 2, 2018

Lets give that another shot. If that doesn't pass I'd merge master in again.

@cbismuth
Copy link
Contributor Author

cbismuth commented Nov 2, 2018

Alright thanks @nik9000 👍

@nik9000
Copy link
Member

nik9000 commented Nov 2, 2018

@cbismuth it looks like this needs master merged in because we're now depending on a different lucene snapshot. Would you like to do it?

@cbismuth
Copy link
Contributor Author

cbismuth commented Nov 2, 2018

Sure, I’ll be back home on Monday, I’ll do it and let you know, thank you @nik9000.

@cbismuth
Copy link
Contributor Author

cbismuth commented Nov 5, 2018

Hi @nik9000, PR is rebased with latest master, could you please trigger a CI build? Thanks 👍

@cbismuth
Copy link
Contributor Author

Hi, PR is up-to-date with latest master and ready for merge 👍

@cbismuth
Copy link
Contributor Author

PR is up-to-date with latest master and ready for build & merge, I stay available for any further change 👍

@cbismuth
Copy link
Contributor Author

cbismuth commented Nov 23, 2018

Hi @nik9000, I have not doubt you're hard working on many other things, so here is quick follow up:

  • This PR raises a 404 exception when document source is not found,
  • We've fixed the validation logic to check document first and then its source,
  • You've kindly approved this PR,
  • We had bad luck with bwc tests 😅

So, this PR has just been updated with master and it would be really great if we could have a build triggered again to get it merged, thanks a lot 👍

EDIT: build has started all by itself due to merge commit, I'll track this and let you know 😉

@cbismuth
Copy link
Contributor Author

I've merged master into current to fix the build. Could someone please trigger another CI build? Thanks a lot 👍

@nik9000
Copy link
Member

nik9000 commented Nov 26, 2018

@elasticmachine, test this please.

@cbismuth, sorry I dropped this one. I've had a rough past two weeks. I'm back now.

@cbismuth
Copy link
Contributor Author

No worries @nik9000, I'm glad you're doing well 👍

@cbismuth
Copy link
Contributor Author

We have a green build 👍

@nik9000 nik9000 merged commit adc0b56 into elastic:master Nov 27, 2018
@nik9000
Copy link
Member

nik9000 commented Nov 27, 2018

OK @cbismuth! I've merged to master and backported to 6.x and am running integration tests for that locally. I'll let you know once they pass and I've pushed to 6.x.

Thanks again!

nik9000 pushed a commit that referenced this pull request Nov 27, 2018
)

This pull request makes the `RestGetSourceAction` return a `ResourceNotFoundException` with a proper JSON response when source or document itself is missing (see issue #33384).

Here is below a sample JSON output:

```
{
  "error": {
    "root_cause": [
      {
        "type": "resource_not_found_exception",
        "reason": "Source not found [index1]/[_doc]/[1]"
      }
    ],
    "type": "resource_not_found_exception",
    "reason": "Source not found [index1]/[_doc]/[1]"
  },
  "status": 404
}
```
@cbismuth
Copy link
Contributor Author

That is really nice, thanks a lot @nik9000 for your help and support 👍

@cbismuth cbismuth deleted the 33384_raise_resource_not_found_when_no_doc_found branch November 28, 2018 11:43
@nik9000
Copy link
Member

nik9000 commented Nov 28, 2018

That backport wasn't 100% clean, but I got it! 6.x had a lot of the same warning infrastructure, but build in slightly different ways. Anyway, it is in! Thanks for sticking with this @cbismuth! It was quite a trip.

@nik9000
Copy link
Member

nik9000 commented Nov 28, 2018

That backport wasn't 100% clean, but I got it! 6.x had a lot of the same warning infrastructure, but build in slightly different ways. Anyway, it is in! Thanks for sticking with this @cbismuth! It was quite a trip.

Woops, wrong issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Data Management/Indices APIs APIs to create and manage indices and templates v6.6.0 v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants