jay_api 28.0.0 → 28.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 641132f73f359c5e49bff17518040894399eb1396e5c17b629ae91f44007c702
4
- data.tar.gz: 5c309039f6ce9ab628632624ebd6cfe542995ecd772dfad834a21fea799d5005
3
+ metadata.gz: 60468cdd7dbfd248e2ca373126f6d3f3a0e9c0d23d169a7e9d98aebe9de3d91d
4
+ data.tar.gz: 58ad9adc3a1f77139660338f213a9c835d935fc7a968f5971fe900904c1ba649
5
5
  SHA512:
6
- metadata.gz: 89eeffecce6f605111ea8fc641b287022b636ea06304d7932d9297777c68ecf3e1e65c76ede81876e9dc1d0f06bd4969e80e29d0f75b8da1a85acab95971f9eb
7
- data.tar.gz: 9505af9f03871fea1f9ceae6ace4718100ac2921c5ec04b17a65769f91dbcd0c2b951a3f38473b3b5186ccf00d70b3add50cc334a47e703eb2a3641f07ea7bdf
6
+ metadata.gz: 9a4c5a8ee131631eb7220b2c2cbf5eb4d9a081b3a0d817647c09d4027311629b78262b35707d8288418da5395d5bebdea11855d9a7f81b81f3d2566cc6156852
7
+ data.tar.gz: f596eeb92e9cecc97ffd2dccb9e93a2dfcf82524bd9bbed43b86ff2d3e60b011e6d9239923b2a4030ea1f0ab67c644028c3178c483de40455c2058c311e38e88
data/CHANGELOG.md CHANGED
@@ -8,6 +8,19 @@ Please mark backwards incompatible changes with an exclamation mark at the start
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [28.2.0] - 2025-05-30
12
+
13
+ ### Added
14
+ - The `#nodes` method to the `Elasticsearch::Stats` class. This method gives the
15
+ user access to the node-related statistics of the Elasticsearch cluster.
16
+
17
+ ## [28.1.0] - 2025-05-19
18
+
19
+ ### Added
20
+ - The `#stats` method to the `Elasticsearch::Client` class. The method returns
21
+ an object that can be used to retrieve statistics about the Cluster. For the
22
+ moment only `#indices` is available, which returns index-related statistics.
23
+
11
24
  ## [28.0.0] - 2025-05-09
12
25
 
13
26
  ### Added
@@ -6,6 +6,7 @@ require 'faraday/error'
6
6
  require 'forwardable'
7
7
 
8
8
  require_relative '../abstract/connection'
9
+ require_relative 'stats'
9
10
 
10
11
  module JayAPI
11
12
  module Elasticsearch
@@ -91,6 +92,12 @@ module JayAPI
91
92
  retry_request { transport_client.tasks.get(**args) }
92
93
  end
93
94
 
95
+ # @return [JayAPI::Elasticsearch::Stats] An instance of the +Stats+ class,
96
+ # which gives the caller access to Elasticsearch's Statistics API.
97
+ def stats
98
+ @stats ||= ::JayAPI::Elasticsearch::Stats.new(transport_client)
99
+ end
100
+
94
101
  private
95
102
 
96
103
  # @param [Proc] block The block to execute.
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../errors/error'
4
+
5
+ module JayAPI
6
+ module Elasticsearch
7
+ class Stats
8
+ module Errors
9
+ # An error to be raised when a particular Stats element is requested for
10
+ # which there is no data in the response received from the cluster.
11
+ class StatsDataNotAvailable < ::JayAPI::Errors::Error; end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JayAPI
4
+ module Elasticsearch
5
+ class Stats
6
+ # Holds information about an Elasticsearch Index.
7
+ class Index
8
+ attr_reader :name
9
+
10
+ # @param [String] name The name of the index.
11
+ # @param [Hash] data Information about the index.
12
+ def initialize(name, data)
13
+ @name = name
14
+ @data = data
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'index'
4
+
5
+ module JayAPI
6
+ module Elasticsearch
7
+ class Stats
8
+ # Provides access to the list of indices returned by Elasticsearch's
9
+ # Stats API
10
+ class Indices
11
+ # A lambda used to select / reject system indices (indices whose name
12
+ # starts with dot).
13
+ SYSTEM_SELECTOR = ->(name, _data) { name.starts_with?('.') }
14
+
15
+ # @param [Hash{String=>Hash}] indices A +Hash+ with the information
16
+ # about the indices. Its keys are the names of the indices, its values
17
+ # hashes with information about each of the indices.
18
+ def initialize(indices)
19
+ @indices = indices
20
+ end
21
+
22
+ # @return [Enumerator::Lazy<JayAPI::Elasticsearch::Stats::Index>] A lazy
23
+ # enumerator of +Index+ objects, one for each of the indexes. All
24
+ # indices (system and user-defined are included).
25
+ def all
26
+ @all ||= with_lazy_instantiation { indices }
27
+ end
28
+
29
+ # @return [Enumerator::Lazy<JayAPI::Elasticsearch::Stats::Index>] A lazy
30
+ # enumerator of +Index+ objects. Includes only the system indices.
31
+ def system
32
+ @system ||= with_lazy_instantiation { indices.select(&SYSTEM_SELECTOR) }
33
+ end
34
+
35
+ # @return [Enumerator::Lazy<JayAPI::Elasticsearch::Stats::Index>] A lazy
36
+ # enumerator of +Index+ objects. Includes only the user-defined
37
+ # indices.
38
+ def user
39
+ @user ||= with_lazy_instantiation { indices.reject(&SYSTEM_SELECTOR) }
40
+ end
41
+
42
+ private
43
+
44
+ attr_reader :indices
45
+
46
+ # @param [Array(String, Hash)] args An array with two elements, the name
47
+ # of the index and its information.
48
+ # @return [JayAPI::Elasticsearch::Stats::Index] An +Index+ object
49
+ # representing the given index.
50
+ def build_index(args)
51
+ JayAPI::Elasticsearch::Stats::Index.new(*args)
52
+ end
53
+
54
+ # Calls the given block and turns its return value into a lazy
55
+ # enumerator that instantiates an +Index+ object for each of the
56
+ # elements of the collection returned by block.
57
+ # @return [Enumerator::Lazy<JayAPI::Elasticsearch::Stats::Index>]
58
+ def with_lazy_instantiation(&block)
59
+ block.call.lazy.map(&method(:build_index))
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JayAPI
4
+ module Elasticsearch
5
+ class Stats
6
+ class Node
7
+ # Holds storage information related to one of the nodes in the
8
+ # Elasticsearch cluster.
9
+ class Storage
10
+ TOTAL_KEY = 'total_in_bytes'
11
+ FREE_KEY = 'free_in_bytes'
12
+ AVAILABLE_KEY = 'available_in_bytes'
13
+
14
+ # @param [Hash] data Data about the Node's storage.
15
+ def initialize(data)
16
+ @data = data
17
+ end
18
+
19
+ # @return [Integer] The total size of the storage (in bytes)
20
+ def total
21
+ @total ||= data[TOTAL_KEY]
22
+ end
23
+
24
+ # @return [Integer] The total number of bytes that are free on the
25
+ # node.
26
+ def free
27
+ @free ||= data[FREE_KEY]
28
+ end
29
+
30
+ # @return [Integer] The total number of bytes that are available on
31
+ # the node. In general this is equal to #free, but not always.
32
+ def available
33
+ @available ||= data[AVAILABLE_KEY]
34
+ end
35
+
36
+ # @return [self] A new instance of the class with the added storage of
37
+ # the receiver and +other+.
38
+ def +(other)
39
+ raise ArgumentError, "Cannot add #{self.class} and #{other.class} together" unless other.is_a?(self.class)
40
+
41
+ self.class.new(
42
+ TOTAL_KEY => total + other.total,
43
+ FREE_KEY => free + other.free,
44
+ AVAILABLE_KEY => available + other.available
45
+ )
46
+ end
47
+
48
+ private
49
+
50
+ attr_reader :data
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'errors/stats_data_not_available'
4
+ require_relative 'node/storage'
5
+
6
+ module JayAPI
7
+ module Elasticsearch
8
+ class Stats
9
+ # Holds information about one of the nodes in the Elasticsearch cluster.
10
+ class Node
11
+ attr_reader :name
12
+
13
+ # @param [String] name The name of the node.
14
+ # @param [Hash] data Information about the node.
15
+ def initialize(name, data)
16
+ @name = name
17
+ @data = data
18
+ end
19
+
20
+ # @return [JayAPI::Elasticsearch::Stats::Node::Storage] Storage
21
+ # information about the node.
22
+ # @raise [JayAPI::Elasticsearch::Stats::Errors::StatsDataNotAvailable]
23
+ # If there is no storage information for the node.
24
+ def storage
25
+ @storage ||= ::JayAPI::Elasticsearch::Stats::Node::Storage.new(fs_totals)
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :data
31
+
32
+ # @return [Hash] Aggregated information about the +Node+'s
33
+ # filesystem.
34
+ # @raise [JayAPI::Elasticsearch::Stats::Errors::StatsDataNotAvailable]
35
+ # If there is no filesystem information for the node.
36
+ def fs_totals
37
+ @fs_totals ||= data.dig('fs', 'total') || raise(
38
+ ::JayAPI::Elasticsearch::Stats::Errors::StatsDataNotAvailable,
39
+ "Filesystem data not available for node #{name}"
40
+ )
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ require_relative 'node'
6
+
7
+ module JayAPI
8
+ module Elasticsearch
9
+ class Stats
10
+ # Provides access to the list of nodes returned by Elasticsearch's Stats API
11
+ class Nodes
12
+ extend Forwardable
13
+
14
+ def_delegator :nodes, :size
15
+
16
+ # @param [Hash] nodes Information about the nodes in the Elasticsearch
17
+ # cluster.
18
+ def initialize(nodes)
19
+ @nodes = nodes
20
+ end
21
+
22
+ # @return [Enumerator::Lazy<JayAPI::Elasticsearch::Stats::Node>] A lazy
23
+ # enumerator of +Node+ objects, one for each of the nodes.
24
+ def all
25
+ @all ||= with_lazy_instantiation { nodes }
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :nodes
31
+
32
+ def build_node(args)
33
+ ::JayAPI::Elasticsearch::Stats::Node.new(*args)
34
+ end
35
+
36
+ # Calls the given block and turns its return value into a lazy
37
+ # enumerator that instantiates a +Node+ object for each of the
38
+ # elements of the collection returned by the block.
39
+ # @return [Enumerator::Lazy<JayAPI::Elasticsearch::Stats::Node>]
40
+ def with_lazy_instantiation(&block)
41
+ block.call.lazy.map(&method(:build_node))
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'stats/index'
4
+ require_relative 'stats/indices'
5
+ require_relative 'stats/node'
6
+ require_relative 'stats/nodes'
7
+
8
+ module JayAPI
9
+ module Elasticsearch
10
+ # This class provides access to Elasticsearch's Cluster Statistic API.
11
+ class Stats
12
+ attr_reader :transport_client, :logger
13
+
14
+ # @param [Elasticsearch::Transport::Client] transport_client The transport
15
+ # client to use to make requests to the cluster.
16
+ def initialize(transport_client)
17
+ @transport_client = transport_client
18
+ end
19
+
20
+ # @return [JayAPI::Elasticsearch::Stats::Indices] Information about the
21
+ # indices that exist in the Elasticsearch cluster.
22
+ # @raise [Elasticsearch::Transport::Transport::ServerError] If the request
23
+ # to the Statistics API endpoint fails.
24
+ def indices
25
+ # DO NOT MEMOIZE! Leave it to the caller.
26
+ ::JayAPI::Elasticsearch::Stats::Indices.new(indices_stats['indices'])
27
+ end
28
+
29
+ # @return [JayAPI::Elasticsearch::Stats::Nodes] Information about the
30
+ # nodes that make up the Elasticsearch cluster.
31
+ # @raise [Elasticsearch::Transport::Transport::ServerError] If the request
32
+ # to the Statistics API endpoint fails.
33
+ def nodes
34
+ # DO NOT MEMOIZE! Leave it to the caller.
35
+ ::JayAPI::Elasticsearch::Stats::Nodes.new(nodes_stats['nodes'])
36
+ end
37
+
38
+ private
39
+
40
+ # @return [Hash] The Hash with the index-related statistics returned by
41
+ # the Elasticsearch cluster.
42
+ # @raise [Elasticsearch::Transport::Transport::ServerError] If the
43
+ # request fails.
44
+ def indices_stats
45
+ # DO NOT MEMOIZE! Leave it to the caller.
46
+ transport_client.indices.stats
47
+ end
48
+
49
+ # @return [Hash] The Hash with the node-related statistics returned by the
50
+ # Elasticsearch cluster.
51
+ # @raise [Elasticsearch::Transport::Transport::ServerError] If the
52
+ # request fails.
53
+ def nodes_stats
54
+ # DO NOT MEMOIZE! Leave it to the caller.
55
+ transport_client.nodes.stats
56
+ end
57
+ end
58
+ end
59
+ end
@@ -10,6 +10,7 @@ require_relative 'elasticsearch/query_builder'
10
10
  require_relative 'elasticsearch/query_results'
11
11
  require_relative 'elasticsearch/response'
12
12
  require_relative 'elasticsearch/search_after_results'
13
+ require_relative 'elasticsearch/stats'
13
14
  require_relative 'elasticsearch/tasks'
14
15
  require_relative 'elasticsearch/time'
15
16
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  module JayAPI
4
4
  # JayAPI gem's semantic version
5
- VERSION = '28.0.0'
5
+ VERSION = '28.2.0'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jay_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 28.0.0
4
+ version: 28.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Accenture-Industry X
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-05-09 00:00:00.000000000 Z
12
+ date: 2025-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -171,6 +171,13 @@ files:
171
171
  - lib/jay_api/elasticsearch/query_results.rb
172
172
  - lib/jay_api/elasticsearch/response.rb
173
173
  - lib/jay_api/elasticsearch/search_after_results.rb
174
+ - lib/jay_api/elasticsearch/stats.rb
175
+ - lib/jay_api/elasticsearch/stats/errors/stats_data_not_available.rb
176
+ - lib/jay_api/elasticsearch/stats/index.rb
177
+ - lib/jay_api/elasticsearch/stats/indices.rb
178
+ - lib/jay_api/elasticsearch/stats/node.rb
179
+ - lib/jay_api/elasticsearch/stats/node/storage.rb
180
+ - lib/jay_api/elasticsearch/stats/nodes.rb
174
181
  - lib/jay_api/elasticsearch/tasks.rb
175
182
  - lib/jay_api/elasticsearch/time.rb
176
183
  - lib/jay_api/errors/configuration_error.rb