-
Notifications
You must be signed in to change notification settings - Fork 25.2k
HLRC: add support for get license basic/trial status API #33176
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
HLRC: add support for get license basic/trial status API #33176
Conversation
Pinging @elastic/es-core-infra |
public GetBasicStatusResponse getBasicStatus(RequestOptions options) throws IOException { | ||
return restHighLevelClient.performRequestAndParseEntity(Validatable.EMPTY, | ||
request -> RequestConverters.getLicenseBasicStatus(), options, GetBasicStatusResponse::fromXContent, emptySet()); | ||
} |
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.
Here I went for exposing only sync versions of these two methods, I don't see how they would be used in an async fashion. Also, I went for not adding an empty request and mimic what we already did with ping and info, which are somehow an exception when you look at the method argument.
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) 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.
this is only here for testing, and it's duplicated in the original transport client class. The problem is that AbstractXContentTestCase
requires a type that extends ToXContent
, and we need to test the parsing code from the client response. Do you have something in mind to be able to test the parsing code using the rendering code from Elasticsearch?
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.
Here is the first incarnation of what I wanted to do, and I feel like we can make this more generic but I wanted to just get it done in an idea before going crazy on a generic impl for these 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.
that looks good, I am tweaking AbstractXContentTestCase
to be able to support this scenario (especially to make sure that we don't lose testing support for unknown fields etc), but my problem is that I don't have the org.elasticsearch.license.GetTrialStatusResponse
in the test classpath. Should I move it somewhere else? Or add the plugin to the test classpath? how did you do that in your branch?
@hub-cap I pushed my changes where I add streamlined support for testing when the server class is ToXContent and the client class only does the parsing. I cannot use it yet entirely as I cannot add xpack core as a dependency (it causes jar hell) but it gives you an idea. |
Thanks @javanna. ill have a look at what we can do here, testing wise. I discussed it with @jasontedor and we came to the conclusion it would be best to test against a live server instead of unit testing. It will be much easier for a few reasons.
The second one is the bigger one, of course, because just the unit tests would not cover any changes in BWC. |
ok @hub-cap I agree on proper live testing. One reason for unit tests may be forward compatibility (the supportsUnknownFields bit) of the client, that may not be extensively tested, as we can only test up to some point in the (known) future. Let me know what I need to do with this PR once you know more. |
@hub-cap I have merged master in. I have left the additional testing (with still the same issues as before) in the PR for you to look at, although you mentioned we may want to remove that part from this PR and look at testing later. Let me know. |
retest this please |
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.
Left some comments. Good general direction. thank you immensely for pointing out the request converter tests and IT tests, somehow these had previously slipped thru the cracks.
|
||
import java.io.IOException; | ||
|
||
public class LicenseIT extends ESRestHighLevelClientTestCase { |
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.
ty for adding this here. Ive also pinged a few other license pull requests to do the same. Somehow it got missed by me in other PRs
|
||
public class LicenseRequestConvertersTests extends ESTestCase{ | ||
|
||
//TODO other existing methods don't have unit 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.
nope. Also noted on other reviews.
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.
cool I will remove the TODO then
} | ||
}); | ||
protected RestChannelConsumer doPrepareRequest(RestRequest request, XPackClient client) { | ||
return channel -> client.licensing().prepareGetStartTrial().execute(new RestToXContentListener<>(channel)); |
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.
ty for doing this on these responses. Does it need to be part of this PR any more now that we are not using the server libs for testing the client?
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.
it is not necessary as part of this PR, just a nice to have while I was at it.
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 is now necessary in order to use AbstractHlrcStreamableXContentTestCase
assertEquals(expectedInstance.eligibleToStartBasic, newInstance.isEligibleToStartBasic()); | ||
} | ||
|
||
static class TestResponse implements ToXContentObject { |
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.
if we want to keep on unit testing the responses using the existing test infra, there has got to be somewhere a ToXContent. I take it that we don't want to (and we can't at the moment) depend on core and reuse the toXContent from core, then this is the easiest way I could find. Obviously it duplicates code. Let me know what you think.
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.
@nik9000 also did soemthing like this in #33921 if you want to have a look. I think this makes more sense than putting them on the response, just because they are never used. And like we said previously, the client ToXContent -> client FromXContent
is much less useful then server ToXContent -> client fromXContent
, so I dont consider it a bad thing to move them here, its just making life easier than manually writing a parser.
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 #33921 I did the refactoring to not need a ToXContent
and instead pass in a method that does the writing. I figured that that would be a thing we could build off of later if we wanted to add tests on the server side that assert that the server side responses generate xcontent that is parsable by the clients.
import java.util.function.Predicate; | ||
import java.util.function.Supplier; | ||
|
||
public abstract class AbstractToFromXContentTestCase<T extends ToXContent, P> extends ESTestCase { |
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 new test class is like the previous AbstractXContentTestCase
but it supports two types, one for outputting to Xcontent, and one for parsing the output. AbstractXContentTestCase
can become a specialization of this that uses the same class for both.
@hub-cap I pushed an update, let me know what you want me to do with the response unit tests. |
eafecfd
to
e047f63
Compare
@Override | ||
protected T doParseInstance(XContentParser parser) throws IOException { | ||
return convertHlrcToInternal(doHlrcParseInstance(parser)); | ||
} |
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.
@vladimirdolzhenko thoughts?
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 this case you hide xpack-parsing-to-xpack-instance functionality that I don't want to drop.
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.
but isn't it there only for testing? And isn't it a duplicate of the parsing code that is already under client?
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 see your point.
Usually we have both toXContent
and fromXContent
in xpack request/response and fromXContent
only on HLRC side. I'd like to keep fromXContent
on a server side (maybe another clean up iteration is required)
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.
anyway - I would not go with this change on a level of AbstractHlrcStreamableXContentTestCase
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 this is a mistake. To me, the main point of having such a test class under xpack is to avoid code duplication. Otherwise it would be easy to have tests under client that rely on e.g. toXContent copy-pasted from xpack that's not needed in client. Given where tests currently are (under x-pack), code duplication would not be required, but we end up duplicating parsing code under x-pack and client. I don't think we should maintain this moving forward. Why keep functionality that is not needed?
This change in my PR does not affect existing tests that override this method, as the test method is not yet made final. I think though that this is a better default behaviour than asking people to duplicate fromXContent: less code to maintain, and less hassle in writing 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.
I'd like to keep fromXContent on a server side (maybe another clean up iteration is required)
How can we do that? Response parsing is needed in the client only, which should not depend on server (at least ideally).
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 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.
Maybe we're extending the wrong test class here. That is why I built that fluent testing thingy - I figured we'd want to be fairly surgical in what we tested. I don't think we should maintain response parsing in the server. If we can get away with dropping it. I don't like keeping it just for testing.
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.
maybe the problem here, and where the confusion comes from, is that requests need parsing in server, and toXContent in client, while responses need parsing in client and toXContent in server. I guess we can't have a single test class that works well for both requests and responses? And my change here is only addressing responses although the test is meant to be more generic though it is used at the moment only for responses.
I have brought this PR up-to-date. Much easier to test things with the recent changes. @vladimirdolzhenko maybe you want to have a look? |
retest this please |
retest this please1 |
@hub-cap tests are green, can you review this please? |
If Nik is ok with this then I am ok with this :)
Lgtm!
…On Sat, Nov 10, 2018, 09:12 Luca Cavanna ***@***.*** wrote:
@hub-cap <https://github.com/hub-cap> tests are green, can you review
this please?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#33176 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AANLouYzX0sGe2wQVSWJF83Tcjpdc3f9ks5utt7FgaJpZM4WODpq>
.
|
backport blocked by #35202 |
Relates to #29827