Skip to content

Commit 52c8603

Browse files
committed
[XPACK] Adds searchable_snapshots/cache_stats endpoint, specs for searchable_snapshots
1 parent f9aa812 commit 52c8603

File tree

6 files changed

+287
-0
lines changed

6 files changed

+287
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 XPack
20+
module API
21+
module SearchableSnapshots
22+
module Actions
23+
# Retrieve node-level cache statistics about searchable snapshots.
24+
# This functionality is Experimental and may be changed or removed
25+
# completely in a future release. Elastic will take a best effort approach
26+
# to fix any issues, but experimental features are not subject to the
27+
# support SLA of official GA features.
28+
#
29+
# @option arguments [List] :node_id A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes
30+
# @option arguments [Hash] :headers Custom HTTP headers
31+
#
32+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.x/searchable-snapshots-apis.html
33+
#
34+
def cache_stats(arguments = {})
35+
headers = arguments.delete(:headers) || {}
36+
37+
arguments = arguments.clone
38+
39+
_node_id = arguments.delete(:node_id)
40+
41+
method = Elasticsearch::API::HTTP_GET
42+
path = if _node_id
43+
"_searchable_snapshots/#{Elasticsearch::API::Utils.__listify(_node_id)}/cache/stats"
44+
else
45+
"_searchable_snapshots/cache/stats"
46+
end
47+
params = {}
48+
49+
body = nil
50+
perform_request(method, path, params, body, headers).body
51+
end
52+
end
53+
end
54+
end
55+
end
56+
end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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#searchable_snapshots.cache_stats' do
21+
let(:expected_args) do
22+
[
23+
'GET',
24+
url,
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
31+
let(:url){ '_searchable_snapshots/cache/stats' }
32+
33+
it 'performs the request' do
34+
expect(client_double.searchable_snapshots.cache_stats).to eq({})
35+
end
36+
37+
context 'when using index' do
38+
let(:url){ '_searchable_snapshots/foo/cache/stats' }
39+
40+
it 'performs the request' do
41+
expect(client_double.searchable_snapshots.cache_stats(node_id: 'foo')).to eq({})
42+
end
43+
end
44+
end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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#searchable_snapshots.clear_cache' do
21+
let(:expected_args) do
22+
[
23+
'POST',
24+
url,
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
31+
let(:url){ '_searchable_snapshots/cache/clear' }
32+
33+
it 'performs the request' do
34+
expect(client_double.searchable_snapshots.clear_cache).to eq({})
35+
end
36+
37+
context 'when using index' do
38+
let(:url){ 'foo/_searchable_snapshots/cache/clear' }
39+
40+
it 'performs the request' do
41+
expect(client_double.searchable_snapshots.clear_cache(index: 'foo')).to eq({})
42+
end
43+
end
44+
end
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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#searchable_snapshots.mount' do
21+
let(:expected_args) do
22+
[
23+
'POST',
24+
'_snapshot/foo/bar/_mount',
25+
{},
26+
{},
27+
{}
28+
]
29+
end
30+
31+
it 'performs the request' do
32+
expect(client_double.searchable_snapshots.mount(body: {}, repository: 'foo', snapshot: 'bar')).to eq({})
33+
end
34+
35+
let(:client) do
36+
Class.new { include Elasticsearch::XPack::API }.new
37+
end
38+
39+
it 'requires the :body argument' do
40+
expect {
41+
client.searchable_snapshots.mount(repository: 'foo', snapshot: 'bar')
42+
}.to raise_exception(ArgumentError)
43+
end
44+
45+
it 'requires the :repository argument' do
46+
expect {
47+
client.searchable_snapshots.mount(body: {}, snapshot: 'bar')
48+
}.to raise_exception(ArgumentError)
49+
end
50+
51+
it 'requires the :snapshot argument' do
52+
expect {
53+
client.searchable_snapshots.mount(body: {}, repository: 'bar')
54+
}.to raise_exception(ArgumentError)
55+
end
56+
end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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#searchable_snapshots.repository_stats' do
21+
let(:expected_args) do
22+
[
23+
'GET',
24+
'_snapshot/foo/_stats',
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
31+
it 'performs the request' do
32+
expect(client_double.searchable_snapshots.repository_stats(repository: 'foo')).to eq({})
33+
end
34+
35+
let(:client) do
36+
Class.new { include Elasticsearch::XPack::API }.new
37+
end
38+
39+
it 'requires the :repository argument' do
40+
expect {
41+
client.searchable_snapshots.repository_stats
42+
}.to raise_exception(ArgumentError)
43+
end
44+
end
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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#searchable_snapshots.stats' do
21+
let(:expected_args) do
22+
[
23+
'GET',
24+
url,
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
let(:url) { '_searchable_snapshots/stats' }
31+
32+
it 'performs the request' do
33+
expect(client_double.searchable_snapshots.stats).to eq({})
34+
end
35+
36+
context 'using index' do
37+
let(:url) { 'foo/_searchable_snapshots/stats' }
38+
39+
it 'performs the request' do
40+
expect(client_double.searchable_snapshots.stats(index: 'foo')).to eq({})
41+
end
42+
end
43+
end

0 commit comments

Comments
 (0)