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

Create a WatchStatus class for the high-level REST client. #33527

Merged
merged 11 commits into from
Sep 19, 2018

Conversation

jtibshirani
Copy link
Contributor

@jtibshirani jtibshirani commented Sep 7, 2018

This class will be used in a few of the watcher responses ('get watch', 'ack watch', etc.), so it's being introduced first in its own PR.

To create this PR, I first copied over all WatchStatus and its dependencies without modification, then iteratively cleaned them up. It's likely easiest to review by going through the commits separately.

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@jtibshirani jtibshirani force-pushed the watch-status-parsing branch 2 times, most recently from 8ec1fe1 to a72fa01 Compare September 7, 2018 23:20
@jtibshirani jtibshirani removed the WIP label Sep 8, 2018

import java.io.IOException;

public final class WatchStatusDateParser {
Copy link
Contributor Author

@jtibshirani jtibshirani Sep 8, 2018

Choose a reason for hiding this comment

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

Somewhat confusingly, the date parsing logic used in WatchStatus is different from that in ActionStatus. I've opted to maintain the logic while refactoring until we have more complete test coverage (hopefully against a live server) and can better understand the behavior.


public class WatchStatusTests extends ESTestCase {

public void testBasicParsing() throws IOException {
Copy link
Contributor Author

@jtibshirani jtibshirani Sep 8, 2018

Choose a reason for hiding this comment

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

In order to sanity check this PR, I manually added some parsing tests. One other option would be to keep the toXContent logic, and create a AbstractXContentTestCase. I decided against that approach because there was quite a bit of logic associated with toXContent, and this isn't the test direction we're ultimately aiming for.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can avoid that by overriding AbstractXContentTestCase#assertToXContentEquivalence? I think it's worth using AbstractXContentTestCase here, it's going to be much more thorough than hand-rolling parsing tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

we need to come to consensus on that, since we wont actually have the toXContent on a lot of classes, and i dont know if i want to add it solely for completing a test. Also, testing that the class can ser/deser the bytes is one thing, but testing that a server side response ser's into something that the client can deser is much more valuable, since thats the way we know the client actually works. After support summit ill have a few brain cells to devote to this as Id like to get an answer out sooner than later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks everyone for taking a look. I purposefully removed the toXContent method and stream serialization methods (in the commit “Remove logic related to writing xContent and stream serialization”) because in the high-level REST client, response classes are only ever deserialized from xContent. As @hub-cap mentioned, we expect this to be the case for most of the response classes.

In tests like AbstractXContentTestCase, we test parsing by creating an object, generating xContent, then parsing it back to an object and checking equality. So because we no longer have a toXContent method, this testing strategy doesn’t apply. My understanding was that we did not want to keep around toXContent just to help with testing, and would prefer to move in a direction where we’re testing against a live server (or some kind of API spec?)

@hub-cap do you have thoughts about the right testing approach for this PR? It would be nice make progress on getting this merged (even if the testing approach is temporary), so others can continue their watcher HLRC work.

Copy link
Contributor

Choose a reason for hiding this comment

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

I need to sit down to make a approach, ill finally have time early next week. Id prefer the manual parsing in order to test the fromXContents, for now.

Copy link
Contributor Author

@jtibshirani jtibshirani Sep 14, 2018

Choose a reason for hiding this comment

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

I clarified with @hub-cap and he thinks we should stick with the current testing approach for this PR + proceed with the code review (or as he says, :shipit: :) )

Copy link
Contributor

Choose a reason for hiding this comment

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

There are already a couple of actions implemented. For example this one which is the delete watcher action:

#32337

Responses extends the abstract class ActionResponse which seems to require serialisation/deserialisation. The responses classes implement ToXContentObject as well so no sure if for consistency we should do the same.

Copy link
Contributor Author

@jtibshirani jtibshirani Sep 17, 2018

Choose a reason for hiding this comment

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

Right, but looking at a more recent xpack HLRC PR (#32332), the responses no longer contain the extraneous serialization/ deserialization logic (see PutUserResponse). I assumed that this is the preferred way going forward, especially now that we are moving the client classes into a separate lightweight module. From the above comments, it sounds like @hub-cap is okay with this for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jtibshirani is correct

Copy link
Contributor

Choose a reason for hiding this comment

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

This other approach looks fine to me as well. Thanks for the clarification!

Copy link
Contributor

@romseygeek romseygeek left a comment

Choose a reason for hiding this comment

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

This looks a great start @jtibshirani, I left a couple of comments.


public class WatchStatusTests extends ESTestCase {

public void testBasicParsing() throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can avoid that by overriding AbstractXContentTestCase#assertToXContentEquivalence? I think it's worth using AbstractXContentTestCase here, it's going to be much more thorough than hand-rolling parsing tests.

}

public static ActionStatus parse(String actionId, XContentParser parser) throws IOException {
AckStatus ackStatus = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think using ConstructingObjectParser would make all these parse methods much clearer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @romseygeek -- I agree, but I opted not to make major refactors to the shared parsing logic to keep this PR focused. Maybe I could do a follow-up to clean up ActionStatus (both the HLRC version, and the core watcher version)?

Copy link
Contributor

@iverase iverase left a comment

Choose a reason for hiding this comment

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

Thanks Julie for this super effort. I am wondering if this classes should implement {toXContent} for Json serialisation and potentially {Writable} as well.

@romseygeek
Copy link
Contributor

I think this is ready to merge now? If there's consensus on the tests, then I'm +1

@jtibshirani
Copy link
Contributor Author

👍 I'll rebase and make sure the tests are green. It would be great to get a PR approval, if everyone is on board.

Copy link
Contributor

@iverase iverase left a comment

Choose a reason for hiding this comment

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

So here is my thumb up.

We agreed that implementation of request/response will follow the implementation of #32332 and therefore no need of serialisation/deserialisation of WatchStatus.
LGTM

@hub-cap
Copy link
Contributor

hub-cap commented Sep 19, 2018

:shipit:

@jtibshirani jtibshirani merged commit c764012 into elastic:master Sep 19, 2018
@jtibshirani jtibshirani deleted the watch-status-parsing branch September 19, 2018 19:17
jtibshirani added a commit that referenced this pull request Oct 4, 2018
This class will be used in a few of the watcher responses ('get watch', 'ack watch', etc.), so it's being introduced first in its own PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants