Skip to content

Commit 647941c

Browse files
committed
[API] Adds ml.get_memory_stats
1 parent 57ba44a commit 647941c

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module API
20+
module MachineLearning
21+
module Actions
22+
# Returns information on how ML is using memory.
23+
#
24+
# @option arguments [String] :node_id Specifies the node or nodes to retrieve stats for.
25+
# @option arguments [Time] :master_timeout Explicit operation timeout for connection to master node
26+
# @option arguments [Time] :timeout Explicit operation timeout
27+
# @option arguments [Hash] :headers Custom HTTP headers
28+
#
29+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/get-ml-memory.html
30+
#
31+
def get_memory_stats(arguments = {})
32+
headers = arguments.delete(:headers) || {}
33+
34+
body = nil
35+
36+
arguments = arguments.clone
37+
38+
_node_id = arguments.delete(:node_id)
39+
40+
method = Elasticsearch::API::HTTP_GET
41+
path = if _node_id
42+
"_ml/memory/#{Utils.__listify(_node_id)}/_stats"
43+
else
44+
"_ml/memory/_stats"
45+
end
46+
params = Utils.process_params(arguments)
47+
48+
Elasticsearch::API::Response.new(
49+
perform_request(method, path, params, body, headers)
50+
)
51+
end
52+
end
53+
end
54+
end
55+
end
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'spec_helper'
19+
20+
describe 'client#ml.get_memory_stats' do
21+
22+
let(:expected_args) do
23+
[
24+
'GET',
25+
url,
26+
{},
27+
nil,
28+
{}
29+
]
30+
end
31+
32+
context 'without a node id' do
33+
let(:url) { '_ml/memory/_stats' }
34+
35+
it 'performs the request' do
36+
expect(client_double.ml.get_memory_stats).to be_a Elasticsearch::API::Response
37+
end
38+
end
39+
40+
context 'with a node id' do
41+
let(:url) { '_ml/memory/foo/_stats' }
42+
43+
it 'performs the request' do
44+
expect(client_double.ml.get_memory_stats(node_id: 'foo')).to be_a Elasticsearch::API::Response
45+
end
46+
end
47+
end

0 commit comments

Comments
 (0)