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

High level REST client parameters look wrong due indirectness and side effects #39666

Closed
jasontedor opened this issue Mar 4, 2019 · 8 comments · Fixed by #42128
Closed

High level REST client parameters look wrong due indirectness and side effects #39666

jasontedor opened this issue Mar 4, 2019 · 8 comments · Fixed by #42128
Labels

Comments

@jasontedor
Copy link
Member

Using the high-level request client, this is how code to build a request with parameters appears today:

        final Request request = new Request(HttpPut.METHOD_NAME, endpoint);
        final RequestConverters.Params parameters = new RequestConverters.Params(request);
        parameters.withWaitForActiveShards(putFollowRequest.waitForActiveShards());
        request.setEntity(createEntity(putFollowRequest, REQUEST_BODY_CONTENT_TYPE));

This looks wrong because parameters appears to be unused. That is, we create a RequestConverter.Params object, mutate it, and then it appears nothing happens to it. This code is not broken though, because what is happening behind the scenes is that request is being mutated when methods on parameters are invoked. This indirectness and methods having side effects on another object lead to code that does not appear correct at first glance, and is more confusing than it should be; it looks wrong. Instead, I propose an alternative like:

        final Request request = new Request(HttpPut.METHOD_NAME, endpoint);
        RequestConverters.Params parameters = new RequestConverters.Params();
        parameters.withWaitForActiveShards(putFollowRequest.waitForActiveShards());
        request.setParameters(parameters);
        request.setEntity(createEntity(putFollowRequest, REQUEST_BODY_CONTENT_TYPE));

This makes apparent that the parameters are actually used, and that they have an effect on the request object through explicit invocation. I believe this makes it more transparent what is occurring.

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features

@hub-cap hub-cap added the good first issue low hanging fruit label Mar 8, 2019
@hub-cap
Copy link
Contributor

hub-cap commented Mar 8, 2019

This makes way more sense. Ive added good first issue to this in case someone wants to pick it up. Feel free to assign me to a PR if anyone does pick it up.

@vedantseta
Copy link

@hub-cap I am on it. Will be sending a PR soon.

@kutty-kumar
Copy link

@vedantseta have you started working on this yet? if not i would like to pick this up.

@kutty-kumar
Copy link

@jasontedor please check the above merge request.

@dwlizlo
Copy link

dwlizlo commented Apr 26, 2019

@kutty-kumar are you still working on this? Are you good with me picking this one up?

@ojasgulati
Copy link
Contributor

@jasontedor @hub-cap Hello is anyone working on this issue? if not I would like to work on this. Also could you please guide me a little bit how should I get started? 😃

@jasontedor
Copy link
Member Author

@ojasgulati There is a PR in progress; let us give the author of that PR a chance to bring it to completion.

ojasgulati added a commit to ojasgulati/elasticsearch that referenced this issue May 29, 2019
This commit will use parameters in request object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants