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

HLRC: add support for get license basic/trial status API #33176

Merged
merged 5 commits into from Nov 13, 2018

Conversation

javanna
Copy link
Member

@javanna javanna commented Aug 27, 2018

Relates to #29827

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

public GetBasicStatusResponse getBasicStatus(RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(Validatable.EMPTY,
request -> RequestConverters.getLicenseBasicStatus(), options, GetBasicStatusResponse::fromXContent, emptySet());
}
Copy link
Member Author

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 {
Copy link
Member Author

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?

Copy link
Contributor

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.

https://github.com/hub-cap/elasticsearch/blob/f06095cb29c72ade77dd51d62d75096071cd7619/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/watcher/DeleteWatchResponseTests.java

Copy link
Member Author

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?

@javanna
Copy link
Member Author

javanna commented Aug 29, 2018

@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.

@hub-cap
Copy link
Contributor

hub-cap commented Aug 29, 2018

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.

  1. Eventually the code should not depend on any of the server side bits
  2. It would be a lot easier to test the client against different versions of the server for BWC.

The second one is the bigger one, of course, because just the unit tests would not cover any changes in BWC.

@javanna
Copy link
Member Author

javanna commented Aug 29, 2018

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.

@javanna
Copy link
Member Author

javanna commented Sep 18, 2018

@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.

@javanna
Copy link
Member Author

javanna commented Sep 19, 2018

retest this please

Copy link
Contributor

@hub-cap hub-cap left a 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 {
Copy link
Contributor

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?
Copy link
Contributor

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.

Copy link
Member Author

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));
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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 {
Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member

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 {
Copy link
Member Author

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.

@javanna
Copy link
Member Author

javanna commented Sep 20, 2018

@hub-cap I pushed an update, let me know what you want me to do with the response unit tests.

@hub-cap
Copy link
Contributor

hub-cap commented Sep 28, 2018

Generally speaking I like the approach here. I want @nik9000 to have a look as well, as hes done similar stuff, but I think youve gone one step further to ensure we can use a common base class for these tests. So big +1 on that. If @nik9000 is good, i will finish the review.

@colings86 colings86 added v6.6.0 and removed v6.5.0 labels Oct 25, 2018
@javanna javanna force-pushed the enhancement/hlrc_get_license_status branch from eafecfd to e047f63 Compare November 8, 2018 13:09
@Override
protected T doParseInstance(XContentParser parser) throws IOException {
return convertHlrcToInternal(doHlrcParseInstance(parser));
}
Copy link
Member Author

Choose a reason for hiding this comment

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

@vladimirdolzhenko thoughts?

Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

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)

Copy link
Contributor

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

Copy link
Member Author

@javanna javanna Nov 8, 2018

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.

Copy link
Member Author

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).

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree - it's a big step forward. But we have to clean up many other leftovers in this case. @hub-cap @nik9000 your objections ?

Copy link
Member

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.

Copy link
Member Author

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.

@javanna
Copy link
Member Author

javanna commented Nov 8, 2018

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?

@javanna
Copy link
Member Author

javanna commented Nov 9, 2018

retest this please

@javanna
Copy link
Member Author

javanna commented Nov 9, 2018

retest this please1

@javanna
Copy link
Member Author

javanna commented Nov 10, 2018

@hub-cap tests are green, can you review this please?

@hub-cap hub-cap dismissed their stale review November 13, 2018 14:09

If Nik is ok with this then I am ok with this :)

@nik9000
Copy link
Member

nik9000 commented Nov 13, 2018 via email

@javanna javanna merged commit 0b7d18d into elastic:master Nov 13, 2018
@javanna
Copy link
Member Author

javanna commented Nov 13, 2018

backport blocked by #35202

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.

None yet

6 participants