Skip to content

Conversation

@mamazzol
Copy link
Contributor

Added CAT Action to display Circuit Breakers stats for all nodes. The API supports pattern matching as a path parameter and the standard query parameters of CAT actions (help, format, h...).

  • The default call only prints node_id, breaker, limit, estimated and tripped as a minimal set of sufficient information.
  • The test uses action.handleRequest(restRequest, channel, nodeClient); to retrieve the response from the channel from the main thread. The flow executed from controller.dispatchRequest in RestActionTestCase chunks the response and the encoding is required to happen on a Transport thread.

Addresses: #132688

Added CAT Action to display Circuit Breakers stats for all nodes. The
API supports pattern matching as a path parameter and the standard query
parameters of CAT actions.

Addresses elastic#132688
@mamazzol mamazzol added >enhancement :Core/Infra/REST API REST infrastructure and utilities Team:Core/Infra Meta label for core/infra team Supportability Improve our (devs, SREs, support eng, users) ability to troubleshoot/self-service product better. labels Oct 21, 2025
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine elasticsearchmachine added external-contributor Pull request authored by a developer outside the Elasticsearch team v9.3.0 labels Oct 21, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @mamazzol, I've created a changelog YAML for you.

Copy link
Contributor

@ldematte ldematte 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 a couple of comments, more for discussion and learning really.

@Override
public void processResponse(final ClusterStateResponse clusterStateResponse) {
NodesStatsRequest nodesStatsRequest = new NodesStatsRequest(
clusterStateResponse.getState().nodes().stream().map(DiscoveryNode::getId).toArray(String[]::new)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's kind of a pity to have DiscoveryNode here, get the ID, and then have BaseNodeRequest#resolveNodes find the DiscoveryNode again

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a little subtle, but this should be unnecessary: AFAICT we're always getting these stats from all nodes, but that's the default behaviour, we can just pass the empty array. See org.elasticsearch.action.support.nodes.BaseNodesRequest#resolveNodes which calls org.elasticsearch.cluster.node.DiscoveryNodes#resolveNodes which does this:

if (nodes == null || nodes.length == 0) {
return stream().map(DiscoveryNode::getId).toArray(String[]::new);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! After looking through the code I saw what you were pointing at, it is indeed redundant to get the nodes from the ClusterState with a separate request. I have removed it

clusterStateResponse.getState().nodes().stream().map(DiscoveryNode::getId).toArray(String[]::new)
);
nodesStatsRequest.clear().addMetric(NodesStatsRequestParameters.Metric.BREAKER);
client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<>(channel) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to avoid this kind of nesting, and possibly generate better response in case of failure, you might consider ListenableFuture. It makes reasoning more complicated though (IMO). See RestShardsAction for an example.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please prefer SubscribableListener over ListenableFuture. They're basically the same, except ListenableFuture adds multiple layers of wrapping around the exceptions it encounters for largely-historical reasons.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the tip @DaveCTurner!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I'll keep that in mind for the future. For now, after removing the first request there's only 1 action executed so it shouldn't be needed.

@ldematte ldematte requested a review from a team October 22, 2025 07:36
@arpadkiraly arpadkiraly removed the external-contributor Pull request authored by a developer outside the Elasticsearch team label Oct 22, 2025
@mosche
Copy link
Contributor

mosche commented Oct 24, 2025

Looking good, @mamazzol !
I think the only thing missing for a new cat endpoint is a corresponding spec in rest-api-spec/src/main/resources/rest-api-spec.api and a corresponding very basic yamlRestTest similar to the other test for the cat api, see rest-api-spec/src/yamlRestTest/resources/rest-api-spec.test.

To skip the test when running backwards compatibility tests against older versions, you can use a capability (which is just the endpoint itself in this case, see https://github.com/elastic/elasticsearch/blob/main/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/README.asciidoc#require-or-skip-api-capabilities)

For examples you can have a look at cat.health/10_basic.yml or capabilities/10_basic.yml.

Copy link
Contributor

@mosche mosche left a comment

Choose a reason for hiding this comment

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

LGTM, @mamazzol, great work.
Just a tiny nit before merging.


@Override
public Set<String> supportedCapabilities() {
return Sets.union(Set.of("cat_circuit_breaker"), super.supportedCapabilities());
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be necessary, the pure existence of the REST endpoint should be enough

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you know how I can verify it?
I saw other tests added this capability filter, like cat_circuit_breaker in my case, but where does that get defined as a capability, if not in that method? ( I trust you, I am just curious :D )

capabilities:
- method: GET
path: /_cat/circuit_breaker
capabilities: [ cat_circuit_breaker ]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
capabilities: [ cat_circuit_breaker ]

As mentioned above, defining and checking for a capability shouldn't be needed here. Existence should do

@mosche mosche added auto-backport Automatically create backport pull requests when merged and removed auto-backport Automatically create backport pull requests when merged labels Oct 29, 2025
@mamazzol mamazzol enabled auto-merge (squash) October 29, 2025 11:27
@mamazzol mamazzol merged commit 52feb00 into elastic:main Oct 29, 2025
34 checks passed
@mamazzol mamazzol deleted the cat-circuit-breaker branch October 29, 2025 12:42
@ldematte
Copy link
Contributor

🥳

shmuelhanoch pushed a commit to shmuelhanoch/elasticsearch that referenced this pull request Oct 29, 2025
Added CAT Action to display Circuit Breakers stats for all nodes. The
API supports pattern matching as a path parameter and the standard query
parameters of CAT actions. This change includes spec and yamlRestTest.

Addresses elastic#132688
chrisparrinello pushed a commit to chrisparrinello/elasticsearch that referenced this pull request Nov 3, 2025
Added CAT Action to display Circuit Breakers stats for all nodes. The
API supports pattern matching as a path parameter and the standard query
parameters of CAT actions. This change includes spec and yamlRestTest.

Addresses elastic#132688
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Core/Infra/REST API REST infrastructure and utilities >enhancement Supportability Improve our (devs, SREs, support eng, users) ability to troubleshoot/self-service product better. Team:Core/Infra Meta label for core/infra team v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants