Merge "Fix elasticsearch & opensearch requests"

This commit is contained in:
Zuul
2025-12-09 12:17:37 +00:00
committed by Gerrit Code Review
5 changed files with 25 additions and 0 deletions

View File

@@ -78,6 +78,9 @@ class ElasticsearchClient(object):
must.append({'term': {'type': filters['type']}})
if metric_types:
if type(metric_types) is not list:
metric_types = [metric_types]
must.append({"terms": {"type": metric_types}})
return must

View File

@@ -78,6 +78,9 @@ class OpenSearchClient(object):
must.append({'term': {'type': filters['type']}})
if metric_types:
if type(metric_types) is not list:
metric_types = [metric_types]
must.append({"terms": {"type": metric_types}})
return must

View File

@@ -53,6 +53,13 @@ class TestElasticsearchClient(unittest.TestCase):
[{'term': {'type': 'awesome'}}],
)
def test_build_must_with_metric_type(self):
types = 'awesome'
self.assertEqual(
self.client._build_must(None, None, types, None),
[{'terms': {'type': ['awesome']}}],
)
def test_build_must_with_metric_types(self):
types = ['awesome', 'amazing']
self.assertEqual(

View File

@@ -53,6 +53,13 @@ class TestOpenSearchClient(unittest.TestCase):
[{'term': {'type': 'awesome'}}],
)
def test_build_must_with_metric_type(self):
types = 'awesome'
self.assertEqual(
self.client._build_must(None, None, types, None),
[{'terms': {'type': ['awesome']}}],
)
def test_build_must_with_metric_types(self):
types = ['awesome', 'amazing']
self.assertEqual(

View File

@@ -0,0 +1,5 @@
---
fixes:
- |
Fix request to Elasticsearch/OpenSearch that has potentially not the
correct type.