-
Notifications
You must be signed in to change notification settings - Fork 25.2k
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
Create set-based interface for NodesInfoRequest #53410
Conversation
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.
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) { |
There was a problem hiding this comment.
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.
@elasticmachine run elasticsearch-ci/bwc |
server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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
server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequest.java
Show resolved
Hide resolved
nodesInfoRequest.plugins(metrics.contains("plugins")); | ||
nodesInfoRequest.ingest(metrics.contains("ingest")); | ||
nodesInfoRequest.indices(metrics.contains("indices")); | ||
// disregard unknown metrics |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequest.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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
server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequest.java
Outdated
Show resolved
Hide resolved
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.
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.
Backported: #54223 |
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 ofNodesInfoRequest
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 callrequest.os(true)
. The new way of doing this is to callrequest.addMetric("os")
. For the time being, theNodesInfoRequest
has aMetric
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.