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

REST high-level client: add support for Rollover Index API #28698

Merged
merged 15 commits into from
Feb 20, 2018

Conversation

javanna
Copy link
Member

@javanna javanna commented Feb 15, 2018

Relates to #27205

…ded given that a CreateIndexRequest is internally created and can then be retrieved to set settings, mappings and aliases to it.
@cbuescher cbuescher self-assigned this Feb 16, 2018

highLevelClient().index(new IndexRequest("test", "type", "1").source("field", "value"));
highLevelClient().index(new IndexRequest("test", "type", "2").source("field", "value")
.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL));
Copy link
Member

Choose a reason for hiding this comment

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

Just curious why we need the refresh policy here. Maybe worth a comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

The rollover API doesn't see the proper number of docs otherwise. At least that's why I think the test fails without it.

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 add this explanation as a short comment then? Thanks.

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

@javanna I did a first round of review, left a couple of questions and small comments, but this looks like it's ready soon

<1> Timeout to wait for the all the nodes to acknowledge the index is opened
as a `TimeValue`
<2> Timeout to wait for the all the nodes to acknowledge the index is opened
as a `String`
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if it makes sense to add a note somewhere that these are alternatives. Maybe not needed though.

Copy link
Member Author

Choose a reason for hiding this comment

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

good one, we did it this way in every single docs page though, maybe if we want to change this we should do it as part of a different PR. Not sure, but I see why you ask this question.

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't need to be in this PR, it just occured to me when reading this docs page. Probably also not a big deal, for most people it should be obvious that these (and similar cases) contain two options

@@ -37,9 +37,8 @@
/**
* A response for a create index action.
*/
public class CreateIndexResponse extends AcknowledgedResponse implements ToXContentObject {
public class CreateIndexResponse extends ShardsAcknowledgedResponse implements ToXContentObject {
Copy link
Member

Choose a reason for hiding this comment

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

I have some compile problems after merging in current master that might be related to this. Can you rebase/merge to check before merging?

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 do not see these, let me know where you see problems.

Copy link
Member

Choose a reason for hiding this comment

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

updated my workspace, gone now. Sorry for the noise.

declareAcknowledgedField(objectParser);
objectParser.declareField(constructorArg(), (parser, context) -> parser.booleanValue(), SHARDS_ACKNOWLEDGED,
ObjectParser.ValueType.BOOLEAN);
declareAcknowledgedAndShardsAcknowledgedFields(objectParser);
objectParser.declareField(constructorArg(), (parser, context) -> parser.text(), INDEX, ObjectParser.ValueType.STRING);
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated to this PR, but can the "index" field be null? Looking at toXContent this can theoretically be the case, not sure if this is guarded against somewhere in CreateIndexResponse, but I couldn't find anything on a quick look.

Copy link
Member Author

Choose a reason for hiding this comment

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

good one, I didn't see this, it should not happen as we never parse something that was serialized through the wire, and it can only be null before 5.6 where the high-level client didn't even exist yet. But the code allows for this so I am fixing and adding a test for it.

return false;
}
Condition<?> condition = (Condition<?>) o;
return Objects.equals(name, condition.name);
Copy link
Member

Choose a reason for hiding this comment

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

Should condition equals() ignore the value? If so, why?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes. it was not ignored before but it's counter intuitive. Json doesn't allow for duplicated keys with same name, which is the only way you could end up with two conditions with same name. These conditions end up in a set, which is why I think it is important to properly implement equals and hashcode although before it was not.

Copy link
Member

Choose a reason for hiding this comment

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

I see, but it feels a bit strange. Maybe the way it is used in the set is a bit off then? Probably outside the scope of this PR though, but can you add this explanation as a javadoc comment to the equals method?

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 within the scope of this PR as I introduced these methods as part of this PR :) I am trying to think of how to improve this and make it less strange. Maybe having a set would not not be that important if things only came from the REST layer, but given that we are setting it also through transport client and high-level REST client, I think we need to make sure that a condition can only be set once. Would you prefer to have a Map<String, Condition> where the key is the name, rather than a Set and implement equals/hashcode this way?

Copy link
Member

Choose a reason for hiding this comment

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

+1, that would probably make things clearer. The set might not have been the best choice given we only want to assure each condition type is set once, as far as I understand 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.

Done.

return false;
}
Result result = (Result) o;
return Objects.equals(condition, result.condition);
Copy link
Member

Choose a reason for hiding this comment

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

Should "matched" be ignored in equal()? If so, why?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I think it should, whether a condition matched or not does not matter to identify which condition it is?

Copy link
Member

Choose a reason for hiding this comment

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

Same here, I see now why it doesn't matter for how we use the object, but if just looking at the object alone one could think it is part of the object. I think it would also be good to add this explanation as a javadoc comment to the equals method if we leave it like this.

}
if (request.param("index") == null) {
throw new IllegalArgumentException("no source index");
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this some sort of cleanup?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes that can't happen already as this is validated at the response level , no need to do it at the rest action level too.

rolloverRequest.getCreateIndexRequest().settings(RandomCreateIndexGenerator.randomIndexSettings());
}
int numConditions = randomIntBetween(0, 3);
Set<Consumer<RolloverRequest>> consumers = new HashSet<>();
Copy link
Member

Choose a reason for hiding this comment

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

While adding the random conditions here seems to work, it took me a while to understand the setup. Maybe this can be simlified a bit by e.g. sampling a random subset from the three options and then using a switch or something? Maybe less elegant but more readable?

Copy link
Member Author

Choose a reason for hiding this comment

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

right, I could have used randomSubsetOf and made things much simpler. Will do that.

expectThrows(ParsingException.class, () -> request.fromXContent(createParser(xContentType.xContent(), mutated)));
}

public void testAddConditions() {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a comment that this test is about failing when calling addXYZ twice, or rename the test method to reflect that better

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 am renaming to testSameConditionCanOnlyBeAddedOnce

RolloverRequest rolloverRequest = new RolloverRequest();
assertNotNull(rolloverRequest.getCreateIndexRequest());
ActionRequestValidationException validationException = rolloverRequest.validate();
assertNotNull(validationException);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a message explaining why this should not be null

Copy link
Member Author

Choose a reason for hiding this comment

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

isn't it self-explanatory given that we retrieve the expected error in the following lines?

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, one can read it like that.

import java.util.HashSet;
import java.util.Set;

public class RolloverResponseTests extends ESTestCase {
Copy link
Member

Choose a reason for hiding this comment

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

Should we also add serialization roundtrip tests to this new test class?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes it would be nice but I think it's besides the scope of this PR. I can add it but I must admit we didn't do it before for other responses and adding that may require adding equals/hashcode methods plus testing them etc. which becomes too time-consuming. There are enough tests added around the high-level REST client stuff already I think, and the main goal here is adding support for new APIs to the high-level REST client. If some important test is missing we should open separate issues for them and address them separately. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Np, was also more of a "nice to have" since we're introducing this new test here. Would you open a separate issue to improbe this at some point though?

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 couldn't help it, I didn't want to leave yet another issue behind, not knowing who and when would take care of it. I may go back and also look at some other response tests, given that implement a different base test class gives us almost all we need already.

@javanna
Copy link
Member Author

javanna commented Feb 19, 2018

@cbuescher I addressed your comments / replied to your questions.

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

@javanna thanks for the changes, I'm also agreeing with most of your comments. Left a few small requests to add comments or follow up PRs but other than that LGTM

@@ -463,6 +463,7 @@ public void testRollover() throws IOException {
highLevelClient().index(new IndexRequest("test", "type", "1").source("field", "value"));
highLevelClient().index(new IndexRequest("test", "type", "2").source("field", "value")
.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL));
//without the refresh the rollover may not happen as the number of docs seen may be off
Copy link
Member

Choose a reason for hiding this comment

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

thanks

import java.util.function.Predicate;
import java.util.function.Supplier;

public class RolloverResponseTests extends AbstractStreamableXContentTestCase<RolloverResponse> {
Copy link
Member

Choose a reason for hiding this comment

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

Probably it would be worth implementing AbstractStreamableTestCase#getMutateFunction in this case, so that the equals/hashCode tests are more complete. I think without it a part of them is skipped.

@cbuescher
Copy link
Member

@javanna I left a few more comments regarding the latest changes, nothing to hold back the PR though.

@javanna
Copy link
Member Author

javanna commented Feb 20, 2018

thanks a lot for your review @cbuescher

@javanna javanna merged commit 8bbb3c9 into elastic:master Feb 20, 2018
martijnvg added a commit that referenced this pull request Feb 22, 2018
* es/6.x: (140 commits)
  Remove AcknowledgedRestListener in favour of RestToXContentListener (#28724)
  Migrate some *ResponseTests to AbstractStreamableXContentTestCase (#28749)
  Revert "Disable BWC tests for build issues"
  Skip some plugins service tests on Windows
  Build: Consolidate archives and packages configuration (#28760)
  Ensure that azure stream has socket privileges (#28773)
  Disable BWC tests for build issues
  Pass InputStream when creating XContent parser (#28754)
  [DOCS] Fixed broken link.
  [DOCS] Changed to use transient setting to reenabled allocation. Closes #27677
  Delay path expansion on Windows
  [TEST] replace randomAsciiAlphanumOfLengthBetween with randomAsciiLettersOfLengthBetween
  REST high-level client: add support for Rollover Index API (#28698)
  [Tests] Extract the testing logic for Google Cloud Storage (#28576)
  Moved Grok helper code to a separate Gradle module and let ingest-common module depend on it.
  version set in ingest pipeline (#27573)
  [Docs] Update links to java9 docs (#28750)
  Revert "Add startup logging for standalone tests"
  Tests: don't wait for completion while trying to get completed task
  Add 5.6.9 snapshot version
  ...
sebasjm pushed a commit to sebasjm/elasticsearch that referenced this pull request Mar 10, 2018
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.

3 participants