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 client to support node selectors like other language clients #21888

Closed
mikeh-elastic opened this issue Nov 30, 2016 · 2 comments
Closed
Assignees
Labels
:Clients/Java Low Level REST Client Minimal dependencies Java Client for Elasticsearch >enhancement

Comments

@mikeh-elastic
Copy link

Describe the feature:
Add option to use custom node selection logic for sending requests only to certain nodes like in the javascript, perl, etc clients. For example, allow sniffing of the cluster but send requests only to client nodes within the cluster.

@javanna javanna added the :Clients/Java Low Level REST Client Minimal dependencies Java Client for Elasticsearch label Nov 30, 2016
@javanna javanna self-assigned this Nov 30, 2016
@javanna
Copy link
Member

javanna commented Nov 30, 2016

Thanks for opening this @mikeh-elastic . It is not the first time that I hear this ask for the Java REST client, and I think it makes sense to add as the other language clients support this too.

As for the transport client part, I don't think we are going to add features to it, as we want to focus more and more on the Java REST client.

@javanna javanna changed the title java transport and rest client support node selectors like other clients such as javascript and perl REST client to support node selectors like other language clients Nov 30, 2016
@javanna javanna removed their assignment Feb 28, 2017
@gmoskovicz
Copy link
Contributor

Adding some more context from the recent linked issue:

Right now if you want to allow an application to use Client Nodes only, you need to define the nodes in the connection settings for the Client. If you add sniffing, you will be able to sniff any node and you could use the sniffHosts option to sniff just client nodes from an external source.

If you want to have a dynamic pool of nodes (client only nodes) that when you add a new client node to a cluster, that node is added to the connection pool, but when you add master or data nodes, those aren't used, one of the ways that people would do that is by using an external Load Balancer.

I think that it will be great for the Java REST client to be able to have a way to sniff client-only nodes.

The current Transport Client doesn't do that, and actually just retrieves a list of data nodes. The reason the transport client excludes non-data nodes is to avoid sending search traffic to master only nodes (from the docs).

@javanna javanna added the help wanted adoptme label Jan 16, 2018
@tlrx tlrx self-assigned this Jan 17, 2018
@tlrx tlrx removed their assignment Jan 26, 2018
@nik9000 nik9000 removed the help wanted adoptme label Mar 12, 2018
@nik9000 nik9000 self-assigned this Mar 12, 2018
nik9000 added a commit to nik9000/elasticsearch that referenced this issue May 10, 2018
Allows users of the Low Level REST client to specify which hosts a
request should be run on. They implement the  `NodeSelector` interface
or reuse a built in selector like `NOT_MASTER_ONLY` to chose which nodes
are valid. Using it looks like:
```
Request request = new Request("POST", "/foo/_search");
request.setNodeSelector(NodeSelector.NOT_MASTER_ONLY);
...
```

This introduces a new `Node` object which contains a `HttpHost` and the
metadata about the host. At this point that metadata is just `version`
and `roles` but I plan to add node attributes in a followup. The
canonical way to **get** this metadata is to use the `Sniffer` to pull
the information from the Elasticsearch cluster.

I've marked this as "breaking-java" because it breaks custom
implementations of `HostsSniffer` by renaming the interface to
`NodesSniffer` and by changing it from returning a `List<HttpHost>` to a
`List<Node>`. It *shouldn't* break anyone else though.

Because we expect to find it useful, this also implements `host_selector`
support to `do` statements in the yaml tests. Using it looks a little
like:

```
---
"example test":
  - skip:
      features: host_selector
  - do:
      host_selector:
        version: " - 7.0.0" # same syntax as skip
      apiname:
        something: true
```

The `do` section parses the `version` string into a host selector that
uses the same version comparison logic as the `skip` section. When the
`do` section is executed it passed the off to the `RestClient`, using
the `ElasticsearchHostsSniffer` to sniff the required metadata.

The idea is to use this in mixed version tests to target a specific
version of Elasticsearch so we can be sure about the deprecation
logging though we don't currently have any examples that need it. We do,
however, have at least one open pull request that requires something
like this to properly test it.

Closes elastic#21888 (kind of, it isn't in the high level client, but we'll do
that in a followup)
nik9000 added a commit that referenced this issue Jun 11, 2018
Allows users of the Low Level REST client to specify which hosts a
request should be run on. They implement the  `NodeSelector` interface
or reuse a built in selector like `NOT_MASTER_ONLY` to chose which nodes
are valid. Using it looks like:
```
Request request = new Request("POST", "/foo/_search");
RequestOptions options = request.getOptions().toBuilder();
options.setNodeSelector(NodeSelector.NOT_MASTER_ONLY);
request.setOptions(options);
...
```

This introduces a new `Node` object which contains a `HttpHost` and the
metadata about the host. At this point that metadata is just `version`
and `roles` but I plan to add node attributes in a followup. The
canonical way to **get** this metadata is to use the `Sniffer` to pull
the information from the Elasticsearch cluster.

I've marked this as "breaking-java" because it breaks custom
implementations of `HostsSniffer` by renaming the interface to
`NodesSniffer` and by changing it from returning a `List<HttpHost>` to a
`List<Node>`. It *shouldn't* break anyone else though.

Because we expect to find it useful, this also implements `host_selector`
support to `do` statements in the yaml tests. Using it looks a little
like:

```
---
"example test":
  - skip:
      features: host_selector
  - do:
      host_selector:
        version: " - 7.0.0" # same syntax as skip
      apiname:
        something: true
```

The `do` section parses the `version` string into a host selector that
uses the same version comparison logic as the `skip` section. When the
`do` section is executed it passed the off to the `RestClient`, using
the `ElasticsearchHostsSniffer` to sniff the required metadata.

The idea is to use this in mixed version tests to target a specific
version of Elasticsearch so we can be sure about the deprecation
logging though we don't currently have any examples that need it. We do,
however, have at least one open pull request that requires something
like this to properly test it.

Closes #21888
nik9000 added a commit that referenced this issue Jun 15, 2018
Allows users of the Low Level REST client to specify which hosts a
request should be run on. They implement the  `NodeSelector` interface
or reuse a built in selector like `NOT_MASTER_ONLY` to chose which nodes
are valid. Using it looks like:
```
Request request = new Request("POST", "/foo/_search");
RequestOptions options = request.getOptions().toBuilder();
options.setNodeSelector(NodeSelector.NOT_MASTER_ONLY);
request.setOptions(options);
...
```

This introduces a new `Node` object which contains a `HttpHost` and the
metadata about the host. At this point that metadata is just `version`
and `roles` but I plan to add node attributes in a followup. The
canonical way to **get** this metadata is to use the `Sniffer` to pull
the information from the Elasticsearch cluster.

I've marked this as "breaking-java" because it breaks custom
implementations of `HostsSniffer` by renaming the interface to
`NodesSniffer` and by changing it from returning a `List<HttpHost>` to a
`List<Node>`. It *shouldn't* break anyone else though.

Because we expect to find it useful, this also implements `host_selector`
support to `do` statements in the yaml tests. Using it looks a little
like:

```
---
"example test":
  - skip:
      features: host_selector
  - do:
      host_selector:
        version: " - 7.0.0" # same syntax as skip
      apiname:
        something: true
```

The `do` section parses the `version` string into a host selector that
uses the same version comparison logic as the `skip` section. When the
`do` section is executed it passed the off to the `RestClient`, using
the `ElasticsearchHostsSniffer` to sniff the required metadata.

The idea is to use this in mixed version tests to target a specific
version of Elasticsearch so we can be sure about the deprecation
logging though we don't currently have any examples that need it. We do,
however, have at least one open pull request that requires something
like this to properly test it.

Closes #21888
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Clients/Java Low Level REST Client Minimal dependencies Java Client for Elasticsearch >enhancement
Projects
None yet
Development

No branches or pull requests

5 participants