[JAY-655] Add a way to get statistics about the Elasticsearch cluster#28
Conversation
albertoberto
left a comment
There was a problem hiding this comment.
I assume this is a github UI issue, but I'm not seeing newlines at the end of any file you added
| # @raise [Elasticsearch::Transport::Transport::ServerError] If the request | ||
| # to the Statistics API endpoint fails. | ||
| def indices | ||
| # DO NOT MEMOIZE! |
There was a problem hiding this comment.
Because the ES response may change, right? IMO it could be worth to mention. Same thing for line 34.
There was a problem hiding this comment.
Yes, but also not. I just did not want to add memoization here and instead opted to leave that to the caller. The instance of Stats is being memoized in Client so, calls to its methods should not have a second layer of memoization.
| # @param [Hash] data Information about the index. | ||
| def initialize(name, data) | ||
| @name = name | ||
| @json = data |
There was a problem hiding this comment.
No attr_reader for this bad boy? Also, why the name difference json - data?
There was a problem hiding this comment.
- Regarding the name:
Probably just a left over from a previous implementation. - Regarding the lack of an
attr_reader:
For the moment this is not being used, I do not want to add methods / readers at the moment. Most likely this is not going to be accessed directly, specific methods will be added later.
| # of the index and its information. | ||
| # @return [JayAPI::Elasticsearch::Stats::Index] An +Index+ object | ||
| # representing the given index. | ||
| def to_object(args) |
There was a problem hiding this comment.
Nitpick: consider def to_index(args) to make which object extra clear
There was a problem hiding this comment.
I decided to change the name of the method since to_object and to_index are both misleading, since you could assume that they work on the receiver instead of the argument.
The class holds information about an Elasticsearch index. It is meant to be used by the Elasticsearch::Stats class, which for the moment is just an stub. In an upcoming commit the class will be filled with the needed logic to retrieve information about the indices in the Elasticsearch cluster.
The class holds information about the Indices Statistics returned by Elasticsearch's Stats API. The class has a little bit of logic to separate system and user-defined indices. It also relies on lazy enumerators to avoid instantiating too many objects when they aren't needed. In an upcoming commit the class will be used by the Elasticsearch::Stats class, which at the time of writing it's only a stub.
Implement the logic inside the class. The class gives the user access to Elasticsearch's Statistics API. For the moment only one method is available: #indices, which returns an object with information about the indices available on the cluster.
The method returns an object with statistics about the Elasticsearch cluster.
299327c to
b632b33
Compare
This Pull Request adds a set of classes and method to allow the user to get statistics about the Elasticsearch cluster.
The main entry point is the
Elasticsearch::Statsclass, which can be retrieved by calling the#statsmethod on an instance of theElasticsearch::Clientclass. For the moment only one method is available:#indices, which gives access to the index-related statistics of the cluster.At the moment this can only be used to enumerate the indices, making the distinction between system (starting with
.) and user-created indices.For the task that triggered these changes all that is needed is the number of user-created indices on the cluster, so the implementation includes only the bare-minimum changes needed to achieve that objective. More features will be added in the future as the need arises.