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

Get data stream accepts single search parameter #54530

Merged
merged 10 commits into from
Apr 3, 2020

Conversation

danhermann
Copy link
Contributor

Changes the GET /_data_streams endpoint to accept a single search parameter.

If the search parameter contains wildcards, a list of matching data streams will be returned or the empty list if there are no matches. If the search parameter does not contain wildcards, the single matching data stream, if any, will be returned. If there are no matches, the response code of 404 will be returned.

The GET /_data_streams request without an explicit search parameter will be treated as GET /_data_streams/*.

Relates to #53100

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features (:Core/Features/Data streams)

@danhermann
Copy link
Contributor Author

@elasticmachine update branch

@elasticmachine
Copy link
Collaborator

merge conflict between base and head

Copy link
Member

@martijnvg martijnvg left a comment

Choose a reason for hiding this comment

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

Looks good. I left some comments.

@@ -72,26 +73,26 @@ public ActionRequestValidationException validate() {

public Request(StreamInput in) throws IOException {
super(in);
this.names = in.readStringArray();
this.name = in.readString();
Copy link
Member

Choose a reason for hiding this comment

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

This should be readOptionalString() instead of readString(), since the name maybe null.
This is also why I think the test fails.

}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeStringArray(names);
out.writeString(name);
Copy link
Member

Choose a reason for hiding this comment

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

This should be writeOptionalString() instead of writeString()

}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Request request = (Request) o;
return Arrays.equals(names, request.names);
return name.equals(request.name);
Copy link
Member

Choose a reason for hiding this comment

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

Objects.equals(...) should be used here.

}

@Override
public int hashCode() {
return Arrays.hashCode(names);
return name.hashCode();
Copy link
Member

Choose a reason for hiding this comment

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

Objects.hashCode(...) should be used here.

GetDataStreamsAction.Request req = new GetDataStreamsAction.Request(new String[]{});
ActionRequestValidationException e = req.validate();
assertNull(e);
return new Request(randomAlphaOfLength(8) + (randomBoolean() ? "*" : ""));
Copy link
Member

Choose a reason for hiding this comment

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

maybe also specify null as a value here?

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe also randomly specify just "*" here?

Copy link
Contributor

@henningandersen henningandersen left a comment

Choose a reason for hiding this comment

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

LGTM. I left a few comments to address, but no need for another round.


- do:
indices.get_data_streams:
name: null
Copy link
Contributor

Choose a reason for hiding this comment

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

I should think it works without this line too? I think I prefer to remove that line, we normally do not specify optional parameters as null in rest tests.


- do:
indices.get_data_streams:
name: get-data-stream1
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to also test that GET _data_stream/get-data-stream* works and returns both streams?

}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeStringArray(names);
out.writeString(name);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is a BWC issue here since the original code is in the 7.7 branch? Probably easiest to just make it 7.7 compatible here (and in the read above) rather than other workarounds.

GetDataStreamsAction.Request req = new GetDataStreamsAction.Request(new String[]{});
ActionRequestValidationException e = req.validate();
assertNull(e);
return new Request(randomAlphaOfLength(8) + (randomBoolean() ? "*" : ""));
}

public void testGetDataStreams() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
public void testGetDataStreams() {
public void testGetDataStream() {

GetDataStreamsAction.Request req = new GetDataStreamsAction.Request(new String[]{});
ActionRequestValidationException e = req.validate();
assertNull(e);
return new Request(randomAlphaOfLength(8) + (randomBoolean() ? "*" : ""));
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe also randomly specify just "*" here?

@@ -65,8 +60,9 @@ public void testGetDataStreams() {
public void testGetNonexistentDataStream() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add a bit more tests:

  1. Get non existent data stream based on wildcard (which should return empty array).
  2. Get data stream based on wildcard, returning multiple.

@danhermann
Copy link
Contributor Author

@elasticmachine update branch

@danhermann
Copy link
Contributor Author

@elasticmachine update branch

@danhermann
Copy link
Contributor Author

@elasticmachine update branch

@danhermann danhermann merged commit 959f41e into elastic:master Apr 3, 2020
@danhermann danhermann deleted the get_single_data_stream branch April 3, 2020 14:33
danhermann added a commit to danhermann/elasticsearch that referenced this pull request Apr 3, 2020
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.

5 participants