Skip to content

Commit a4e866b

Browse files
THEBATTEURpriteau
authored andcommitted
Fix elasticsearch & opensearch requests
Using list for metric_types in _build_must, in case it was not. The APIs expects a list for "type" in "terms". Story: 2011541 Task: 52868 Signed-off-by: Nicolas Maillet-Contoz <nicolas.maillet-contoz@infomaniak.com> Change-Id: Ia57e81dade3f54383d66a27c6935dda3779b090a (cherry picked from commit 677fc28)
1 parent 26dcd53 commit a4e866b

5 files changed

Lines changed: 25 additions & 0 deletions

File tree

cloudkitty/storage/v2/elasticsearch/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ def _build_must(start, end, metric_types, filters):
7676
must.append({'term': {'type': filters['type']}})
7777

7878
if metric_types:
79+
if type(metric_types) is not list:
80+
metric_types = [metric_types]
81+
7982
must.append({"terms": {"type": metric_types}})
8083

8184
return must

cloudkitty/storage/v2/opensearch/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ def _build_must(start, end, metric_types, filters):
7676
must.append({'term': {'type': filters['type']}})
7777

7878
if metric_types:
79+
if type(metric_types) is not list:
80+
metric_types = [metric_types]
81+
7982
must.append({"terms": {"type": metric_types}})
8083

8184
return must

cloudkitty/tests/storage/v2/elasticsearch/test_client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ def test_build_must_with_filters(self):
5353
[{'term': {'type': 'awesome'}}],
5454
)
5555

56+
def test_build_must_with_metric_type(self):
57+
types = 'awesome'
58+
self.assertEqual(
59+
self.client._build_must(None, None, types, None),
60+
[{'terms': {'type': ['awesome']}}],
61+
)
62+
5663
def test_build_must_with_metric_types(self):
5764
types = ['awesome', 'amazing']
5865
self.assertEqual(

cloudkitty/tests/storage/v2/opensearch/test_client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ def test_build_must_with_filters(self):
5353
[{'term': {'type': 'awesome'}}],
5454
)
5555

56+
def test_build_must_with_metric_type(self):
57+
types = 'awesome'
58+
self.assertEqual(
59+
self.client._build_must(None, None, types, None),
60+
[{'terms': {'type': ['awesome']}}],
61+
)
62+
5663
def test_build_must_with_metric_types(self):
5764
types = ['awesome', 'amazing']
5865
self.assertEqual(
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
Fix request to Elasticsearch/OpenSearch that has potentially not the
5+
correct type.

0 commit comments

Comments
 (0)