Skip to content

Create set-based interface for NodesInfoRequest #53410

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

Merged

Conversation

williamrandolph
Copy link
Contributor

This is another refactoring PR to move the Nodes Information endpoint in the direction of pluggability (see #52975). In #53140, we changed the NodesInfoRequest class so that it serializes as a set of strings rather than a fixed list of booleans. In this PR, we update the interface of NodesInfoRequest so that it uses getters and setters that are more appropriate to this internal structure. For example, the old way of adding "os" metrics to a request would be to call request.os(true). The new way of doing this is to call request.addMetric("os"). For the time being, the NodesInfoRequest has a Metric enum that serves as the source of truth for allowed metrics. I plan to replace this eventually with a pluggable solution.

The follow-up step for this PR is to update the NodesInfoRequestBuilder to have a matching set-based interface, but I am putting that off to another PR in order to keep the diff small and to avoid confusion between the two classes.

This commit begins the work of removing the "hard-coded" metric getters
and setters from the NodesInfoRequest classes. We start by providing new
flexible getters and setters. We then update the test classes to remove
the old getters, and then remove those getters.
Throw an IllegalStateException if an unknown metric is added or removed.

Replace some of the infrequently used setters.
Based on some of the refactoring I'm doing, it seems like it's
convenient to be have an addMetrics(String ...) method.

Also add some more test coverage.
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (:Core/Infra/Plugins)

* @param metricName Name of the metric to include or remove.
*/
private void addOrRemoveMetric(boolean includeMetric, String metricName) {
if (includeMetric) {
private void optionallyAddMetric(boolean addMetric, String metricName) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method is now only used for backwards-compatible deserialization, and doesn't need to be able to remove metrics anymore.

@williamrandolph
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/bwc
@elasticmachine run elasticsearch-ci/default-distro

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

I have a couple questions

nodesInfoRequest.plugins(metrics.contains("plugins"));
nodesInfoRequest.ingest(metrics.contains("ingest"));
nodesInfoRequest.indices(metrics.contains("indices"));
// disregard unknown metrics
Copy link
Member

Choose a reason for hiding this comment

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

Aren't unknown metrics an error case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current behavior of the Nodes Info API is to silently disregard invalid metrics (or node ids). The Nodes Stats endpoint, on the other hand, will return an error if you request an unknown metric.

Arguably, the Nodes Info API should return an error for unknown metrics, but that would go beyond just refactoring.

Copy link
Member

@rjernst rjernst 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, just one more request.

@williamrandolph williamrandolph requested a review from rjernst March 24, 2020 18:42
Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

LGTM, one last request

@bpintea bpintea added v7.8.0 and removed v7.7.0 labels Mar 25, 2020
@williamrandolph williamrandolph merged commit 6d6227a into elastic:master Mar 25, 2020
@williamrandolph williamrandolph deleted the nodes-info-request-refactor-2 branch March 25, 2020 18:12
williamrandolph added a commit to williamrandolph/elasticsearch that referenced this pull request Mar 25, 2020
This commit begins the work of removing the "hard-coded" metric getters
and setters from the NodesInfoRequest classes. We start by providing new
flexible getters and setters. We then update the test classes to remove
the old getters, and then remove those getters.
williamrandolph added a commit that referenced this pull request Mar 26, 2020
This commit begins the work of removing the "hard-coded" metric getters
and setters from the NodesInfoRequest classes. We start by providing new
flexible getters and setters. We then update the test classes to remove
the old getters, and then remove those getters.
@williamrandolph
Copy link
Contributor Author

Backported: #54223

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