Add REST API for cache directory stats#51815
Add REST API for cache directory stats#51815tlrx merged 14 commits intoelastic:feature/searchable-snapshotsfrom
Conversation
|
Pinging @elastic/es-distributed (:Distributed/Snapshot/Restore) |
DaveCTurner
left a comment
There was a problem hiding this comment.
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. |
DaveCTurner
left a comment
There was a problem hiding this comment.
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
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.
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.
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.
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.
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.
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.
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.
Looks good. Test failures are not obviously related, maybe we need to merge something?
There was a problem hiding this comment.
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 |
|
Thanks David! |
Note: this pull request targets the
feature/searchable-snapshotsbranchThis pull request adds a REST API that exposes the various
CacheDirectorystats added in #51637. It adds the necessary action, transport action and request and response objects as well as a newqa:restproject for REST tests.The REST endpoint is
_searchable_snapshots/stats(as aTransportNodesActionit can be filtered by nodes ids) and the response looks like:Details
{ "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "indices" : { "index" : { "shards" : { "0" : [ { "snapshot_uuid" : "CJ95kbqcSYCu5wBAiUDDNA", "index_uuid" : "dllhcZ7kSai9XeBhVjEhIg", "shard" : { "state" : "STARTED", "primary" : true, "node" : "Zpw8ZgeqT9mCmmfRA1feNw" }, "files" : [ { "name" : "_0.cfe", "length" : 405, "open_count" : 6, "inner_count" : 1, "close_count" : 6, "contiguous_bytes_read" : { "count" : 5, "sum" : 2025, "min" : 405, "max" : 405 }, "non_contiguous_bytes_read" : { "count" : 1, "sum" : 16, "min" : 16, "max" : 16 }, "cached_bytes_read" : { "count" : 6, "sum" : 2041, "min" : 16, "max" : 405 }, "cached_bytes_written" : { "count" : 1, "sum" : 405, "min" : 405, "max" : 405 }, "direct_bytes_read" : { "count" : 0, "sum" : 0, "min" : 0, "max" : 0 }, "forward_seeks" : { "small" : { "count" : 0, "sum" : 0, "min" : 0, "max" : 0 }, "large" : { "count" : 0, "sum" : 0, "min" : 0, "max" : 0 } }, "backward_seeks" : { "small" : { "count" : 0, "sum" : 0, "min" : 0, "max" : 0 }, "large" : { "count" : 0, "sum" : 0, "min" : 0, "max" : 0 } } }, ... }