-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Create a WatchStatus class for the high-level REST client. #33527
Conversation
Pinging @elastic/es-core-infra |
8ec1fe1
to
a72fa01
Compare
|
||
import java.io.IOException; | ||
|
||
public final class WatchStatusDateParser { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, :) )
There was a problem hiding this comment.
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:
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jtibshirani is correct
There was a problem hiding this comment.
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!
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)?
There was a problem hiding this 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.
I think this is ready to merge now? If there's consensus on the tests, then I'm +1 |
👍 I'll rebase and make sure the tests are green. It would be great to get a PR approval, if everyone is on board. |
Also fix the following issues it uncovered: * Make sure that parsing is robust to unknown fields. * Add the missing method WatchStatus#lastMetCondition. * Remove the headers parameter, as headers should not be visible in the REST API.
This will simplify the parsing of responses, especially in the case of acks where the watch ID is not available.
a72fa01
to
5cae92f
Compare
There was a problem hiding this 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
|
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.
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.