-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Add REST API for cache directory stats #51815
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
Add REST API for cache directory stats #51815
Conversation
Pinging @elastic/es-distributed (:Distributed/Snapshot/Restore) |
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.
Before I get too far into this, are we sure about this being a TransportNodesAction
and not a TransportBroadcastByNodeAction
? I think the response from even a single node might be overwhelming if it holds a lot of indices, given the level of detail, and it would be better to be able to get the stats from a single index across the whole cluster.
Thanks @DaveCTurner. That sounds like the right thing to do, indeed. I'll update the PR. |
@DaveCTurner I've updated the code so that the transport action is now a If it appears to be a need we could also aggregate stats per index, per shard or per file but I haven't done this as it complicates things for now. We could change this later. |
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. I left only minor comments and questions.
.../src/main/java/org/elasticsearch/xpack/core/searchablesnapshots/SearchableSnapshotStats.java
Outdated
Show resolved
Hide resolved
.../src/main/java/org/elasticsearch/xpack/core/searchablesnapshots/SearchableSnapshotStats.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/searchable-snapshots/qa/rest/src/test/resources/rest-api-spec/test/stats.yml
Outdated
Show resolved
Hide resolved
x-pack/plugin/searchable-snapshots/qa/rest/src/test/resources/rest-api-spec/test/stats.yml
Show resolved
Hide resolved
x-pack/plugin/searchable-snapshots/qa/rest/src/test/resources/rest-api-spec/test/stats.yml
Outdated
Show resolved
Hide resolved
...napshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/CacheDirectory.java
Outdated
Show resolved
Hide resolved
"documentation": { | ||
"url": "https://www.elastic.co/guide/en/elasticsearch/reference/current/searchable-snapshots-get-stats.html //NORELEASE" | ||
}, | ||
"stability": "experimental", |
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.
We should at least mark this line as //NORELEASE
too, but really I think we should be bolder and say that by the time this is merged we expect this API not to be experimental any more, so there's no need for this.
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 agree. Sadly we can't mark this line as //NORELEASE
too as the stability
is checked against a specified set of values. We can't also comment this JSON file.
I think that experimental
reflects the current state of this API for now. I hooked on the //NORELEASE and add more documentation about the stability of the API (see fde0a86).
} | ||
} | ||
} | ||
return state.routingTable().allShards(searchableSnapshotIndices.toArray(new String[0])); |
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.
Ideally, we would throw an exception if the user specified an index (or pattern) which didn't match any searchable snapshots, but this would naturally fall to the IndexNameExpressionResolver
which doesn't seem to have a suitable extension point for this kind of logic.
However, what do you think about handling at least the case of a user specifying a single index with a typo, matching nothing, with an INFE? I.e. if request.indices()
is not empty or ["*"]
or ["_all"]
but searchableSnapshotIndices
is empty, then that's a bad request.
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.
That sounds like a good idea. I implemented it a bit differently though in c9468d1, by checking if one or more concrete indices were resolved (taking security into account) but none of them had a searchable
store type (searchableSnapshotIndices
is empty) which throws a resource not found exception. I've updated the REST API test for this.
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.
Hmm, this means that GET _searchable_snapshots/stats
returns 200 OK
in an empty cluster but 404 Not Found
if there are any indices at all but none of them are searchable snapshots. I think that'll be surprising. Maybe it'd be best always to throw a RNFE if searchableSnapshotIndices
is empty.
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'm not fully sure how it should behave, also because Security also has its specific behavior so I went with your suggestion in d1049a3 which has the advantage to be consistent.
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. Test failures are not obviously related, maybe we need to merge something?
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.
Yes, need to merge master but I'm waiting for bwc to be reenabled before.
@DaveCTurner I've updated the PR with your feedback. Let me know if you have more feedback, thanks! |
@elasticmachine run elasticsearch-ci/bwc |
@elasticmachine update branch |
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
Thanks David! |
Note: this pull request targets the
feature/searchable-snapshots
branchThis pull request adds a REST API that exposes the various
CacheDirectory
stats added in #51637. It adds the necessary action, transport action and request and response objects as well as a newqa:rest
project for REST tests.The REST endpoint is
_searchable_snapshots/stats
(as aTransportNodesAction
it can be filtered by nodes ids) and the response looks like: