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

removing background state update of Request object by RequestConverte… #40156

Closed
wants to merge 1 commit into from
Closed

removing background state update of Request object by RequestConverte… #40156

wants to merge 1 commit into from

Conversation

kutty-kumar
Copy link

Changes required for removing background state update of request object by RequestConverters.Params object
#39666

@javanna
Copy link
Member

javanna commented Mar 18, 2019

jenkins test this please

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features

builder.addCommaSeparatedPathParts(clearRealmCacheRequest.getRealms().toArray(Strings.EMPTY_ARRAY));
} else {
builder.addPathPart("_all");
}
final String endpoint = builder.addPathPartAsIs("_clear_cache").build();
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
if (clearRealmCacheRequest.getUsernames().isEmpty() == false) {
RequestConverters.Params params = new RequestConverters.Params(request);
if (!clearRealmCacheRequest.getUsernames().isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

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

can you please revert this change and all the similar ones? we tend to prefer the boolean == false over !boolean as the exclamation mark can easily be missed.

Copy link
Member

Choose a reason for hiding this comment

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

can you please revert this?

@@ -50,6 +49,14 @@ public Request(String method, String endpoint) {
this.endpoint = Objects.requireNonNull(endpoint, "endpoint cannot be null");
}

/**
* Copy the parameters from {@literal RequestConverters.Params} into {@linkplain Request}.
Copy link
Member

Choose a reason for hiding this comment

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

I think that we should just say "Set the parameters" , who sets them may change in the future

Copy link
Member

Choose a reason for hiding this comment

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

Also, note that RequestConverters are part of the high-level REST client while Request is part of the low-level REST client which is used independently.

private final Map<String, String> requestParamsMap;

Params() {
this.requestParamsMap = new HashMap<>();
Copy link
Member

Choose a reason for hiding this comment

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

nit: you could initialize the map above and remove the default constructor.

@@ -50,6 +49,14 @@ public Request(String method, String endpoint) {
this.endpoint = Objects.requireNonNull(endpoint, "endpoint cannot be null");
}

/**
* Copy the parameters from {@literal RequestConverters.Params} into {@linkplain Request}.
* @param requestConverterParams the request converter parameter map
Copy link
Member

Choose a reason for hiding this comment

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

can we remove the mention of request converters here?

* Copy the parameters from {@literal RequestConverters.Params} into {@linkplain Request}.
* @param requestConverterParams the request converter parameter map
*/
public void setParameters(Map<String, String> requestConverterParams){
Copy link
Member

Choose a reason for hiding this comment

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

and rename the argument to not refer to request converters?

}

Params putParam(String name, String value) {
if (Strings.hasLength(value)) {
request.addParameter(name, value);
requestParamsMap.put(name, value);
Copy link
Member

Choose a reason for hiding this comment

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

with this change we lose two checks that we were previously performing by calling Request#addParameter:

  • check that the key is not null
  • check that the param has not already been set (it would get overridden by default, but we prefer to throw error)

I think that we would want to keep these two checks.

Copy link
Author

@kutty-kumar kutty-kumar Mar 19, 2019

Choose a reason for hiding this comment

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

@javanna what error should i throw? i think that check would move to the copy method of Request class

Suggested change
requestParamsMap.put(name, value);
public void setParameters(Map<String, String> paramSource){
paramSource.keySet().forEach(key -> {
if(this.parameters.get(key) != null){
throw new Error(String.format("%s is already set", key));
}
});
this.parameters.putAll(paramSource);
}

does this look good?

Copy link
Member

Choose a reason for hiding this comment

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

can you throw the same error that we throw in the Request class please? IllegalArgumentException?

@javanna
Copy link
Member

javanna commented Mar 18, 2019

thanks @kutty-kumar for opening this PR! I just did a first quick review and left some comments, also I started tests which are running. Let me know if you have any question on addressing the comments.

@javanna javanna self-assigned this Mar 18, 2019
@javanna
Copy link
Member

javanna commented Mar 18, 2019

@kutty-kumar it seems like there's a couple of failing tests. It's fine not to run all of our tests before submitting a PR, but in your case, could you run ../../gradlew check from client/rest-high-level directory please? that should help you reproduce the problem. Let me know if you need help fixing those failures.

@kutty-kumar
Copy link
Author

@javanna thanks for the initial review, i will work on resolving them and update the PR.

@kutty-kumar
Copy link
Author

@javanna i have made the required changes please review them also i am currently fixing the tests, will update here once done. Thanks

Copy link
Member

@javanna javanna 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 some more comments, let me know if you need help with the test failures.

builder.addCommaSeparatedPathParts(clearRealmCacheRequest.getRealms().toArray(Strings.EMPTY_ARRAY));
} else {
builder.addPathPart("_all");
}
final String endpoint = builder.addPathPartAsIs("_clear_cache").build();
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
if (clearRealmCacheRequest.getUsernames().isEmpty() == false) {
RequestConverters.Params params = new RequestConverters.Params(request);
if (!clearRealmCacheRequest.getUsernames().isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

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

can you please revert this?

@kutty-kumar
Copy link
Author

@javanna yes i need some help in fixing the tests, not able to figure out where exactly they are failing, please direct me towards that, i will take care of the changes
Thanks

@javanna
Copy link
Member

javanna commented Mar 21, 2019

retest this please

@kutty-kumar
Copy link
Author

jenkins test this please

@javanna
Copy link
Member

javanna commented Mar 21, 2019

@kutty-kumar the magic jenkins commands work only if you are part of the Elastic organization, for security reasons, I will run the tests again.

@javanna
Copy link
Member

javanna commented Mar 21, 2019

retest this please

@kutty-kumar
Copy link
Author

@javanna i have started the gradle check process, its still running, doesn't seem to have any failures. Hence i wanted to test it on jenkins, thanks for the info :)

@javanna
Copy link
Member

javanna commented Mar 25, 2019

@kutty-kumar there are still two failures:

org.elasticsearch.client.IndicesRequestConvertersTests.testExistsAlias
org.elasticsearch.client.SecurityRequestConvertersTests.testDeleteUser

would you mind having a look at those? You can run client tests only by executing ../../gradlew check from client/rest-high-level folder. Thanks

@kutty-kumar
Copy link
Author

done @javanna, please rebuild the source.
Thanks

@javanna
Copy link
Member

javanna commented Mar 26, 2019

retest this please

@kutty-kumar
Copy link
Author

`➜ rest-high-level git:(refactoring/requestConverterParams) ✗ ../../gradlew check

Configure project :benchmarks
=======================================
Elasticsearch Build Hamster says Hello!
Gradle Version : 5.2.1
OS Info : Mac OS X 10.14.3 (x86_64)
JDK Version : 11 (Oracle Corporation 11.0.2 [Java HotSpot(TM) 64-Bit Server VM 11.0.2+9-LTS])
JAVA_HOME : /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home
Random Testing Seed : 5FC48F357ECA8590
=======================================

Task :client:rest-high-level:unitTest
==> Test Info: seed=5FC48F357ECA8590; jvms=4; suites=275

[ant:junit4] JVM J0: stderr was not empty, see: /Users/halodoc/Projects/elasticsearch1/client/rest-high-level/build/testrun/unitTest/temp/junit4-J0-20190326_162010_90016372490423214617704.syserr
[ant:junit4] JVM J2: stderr was not empty, see: /Users/halodoc/Projects/elasticsearch1/client/rest-high-level/build/testrun/unitTest/temp/junit4-J2-20190326_162010_90018010291334947152229.syserr
[ant:junit4] JVM J3: stderr was not empty, see: /Users/halodoc/Projects/elasticsearch1/client/rest-high-level/build/testrun/unitTest/temp/junit4-J3-20190326_162010_9011526902967533266904.syserr

Task :client:rest-high-level:unitTest
==> Test Summary: 275 suites, 870 tests

Task :client:rest-high-level:integTestRunner
==> Test Info: seed=5FC48F357ECA8590; jvm=1; suites=45

HEARTBEAT J0 PID(12684@Kumards-MacBook-Pro.local): 2019-03-26T16:27:33, stalled for 10.7s at: SecurityDocumentationIT.testInvalidateToken

Task :client:rest-high-level:integTestRunner
Slow Tests Summary:
102.99s | org.elasticsearch.client.SearchIT
93.71s | org.elasticsearch.client.MachineLearningIT
89.45s | org.elasticsearch.client.documentation.MlClientDocumentationIT
50.11s | org.elasticsearch.client.documentation.SecurityDocumentationIT
45.63s | org.elasticsearch.client.IndicesClientIT

==> Test Summary: 45 suites, 490 tests

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.2.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 13m 16s
273 actionable tasks: 56 executed, 217 up-to-date`
Did that @javanna

@javanna
Copy link
Member

javanna commented Mar 26, 2019

can you please merge master in @kutty-kumar ?

@kutty-kumar
Copy link
Author

@javanna its already up to date with master, please let me know what exactly i should do.
Thanks

@javanna
Copy link
Member

javanna commented Mar 26, 2019

retest this please

@javanna
Copy link
Member

javanna commented Mar 26, 2019

@kutty-kumar it does not look up-to-date to me, could you pull latest master (doing git checkout master, then git pull origin master) and then merge it in your branch (by doing git checkout refactoring/requestConverterParams, then git merge master) and then push your updated branch to your remote?

@kutty-kumar
Copy link
Author

@javanna can you please check now, my fork was behind the actual repository, hence the branch was behind, i have taken the changes from the actual repository and force pushed.

Thanks

@javanna
Copy link
Member

javanna commented Mar 26, 2019

retest this please

@javanna
Copy link
Member

javanna commented Mar 26, 2019

@kutty-kumar some code needs updating now, as there are more users of the internal API that you have modified in your change. It should be straight-forward to address.

@javanna
Copy link
Member

javanna commented Apr 8, 2019

hi @kutty-kumar have you had a chance to look into the needed changes? Do you need help with this?

@kutty-kumar
Copy link
Author

Hi @javanna i thought that i had to refactor a lot, hence i wanted your suggestions on doing this the right way. Please add in some thoughts which i could use to refine the code.

@javanna
Copy link
Member

javanna commented Apr 8, 2019

@kutty-kumar as far as I can see, while you PR was getting reviewed, new API were added to the high-level REST client which use the mechanism that you were refactoring. You need to make the same changes to those newly added API.

@jasontedor
Copy link
Member

@kutty-kumar Are you interested in bringing this PR to completion?

@kutty-kumar
Copy link
Author

@jasontedor yes i will complete the PR by this weekend, sorry for the delay!

@jakelandis jakelandis added v7.3.0 and removed v7.2.0 labels Jun 17, 2019
@jpountz jpountz added v7.4.0 and removed v7.3.0 labels Jul 3, 2019
@javanna
Copy link
Member

javanna commented Aug 6, 2019

This has stalled as no work has been done on it for a couple of months. Feel free to reopen or open a new PR when/if you get the time to work on it again.

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