Skip to content

[JAY-655] Add a way to get statistics about the Elasticsearch cluster#28

Merged
sergio-bobillier merged 5 commits into
masterfrom
sb-indices
May 19, 2025
Merged

[JAY-655] Add a way to get statistics about the Elasticsearch cluster#28
sergio-bobillier merged 5 commits into
masterfrom
sb-indices

Conversation

@sergio-bobillier

Copy link
Copy Markdown
Collaborator

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::Stats class, which can be retrieved by calling the #stats method on an instance of the Elasticsearch::Client class. 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.

@sergio-bobillier sergio-bobillier self-assigned this May 16, 2025
@sergio-bobillier sergio-bobillier marked this pull request as ready for review May 16, 2025 13:34

@albertoberto albertoberto left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I assume this is a github UI issue, but I'm not seeing newlines at the end of any file you added

Comment thread documentation/source/user_guidelines/elasticsearch/stats.rst
Comment thread lib/jay_api/elasticsearch/stats.rb Outdated
# @raise [Elasticsearch::Transport::Transport::ServerError] If the request
# to the Statistics API endpoint fails.
def indices
# DO NOT MEMOIZE!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Because the ES response may change, right? IMO it could be worth to mention. Same thing for line 34.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No attr_reader for this bad boy? Also, why the name difference json - data?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

  • 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nitpick: consider def to_index(args) to make which object extra clear

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Comment thread spec/jay_api/elasticsearch/stats/indices_spec.rb Outdated
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.
@sergio-bobillier sergio-bobillier merged commit 26d22e2 into master May 19, 2025
3 checks passed
@sergio-bobillier sergio-bobillier deleted the sb-indices branch May 19, 2025 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants