diff --git a/cloudkitty/storage/v2/elasticsearch/client.py b/cloudkitty/storage/v2/elasticsearch/client.py index 7716f039..01bdb500 100644 --- a/cloudkitty/storage/v2/elasticsearch/client.py +++ b/cloudkitty/storage/v2/elasticsearch/client.py @@ -76,6 +76,9 @@ def _build_must(start, end, metric_types, filters): 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 diff --git a/cloudkitty/storage/v2/opensearch/client.py b/cloudkitty/storage/v2/opensearch/client.py index d5757c9b..e15bf77e 100644 --- a/cloudkitty/storage/v2/opensearch/client.py +++ b/cloudkitty/storage/v2/opensearch/client.py @@ -76,6 +76,9 @@ def _build_must(start, end, metric_types, filters): 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 diff --git a/cloudkitty/tests/storage/v2/elasticsearch/test_client.py b/cloudkitty/tests/storage/v2/elasticsearch/test_client.py index 5d3158b4..c3493574 100644 --- a/cloudkitty/tests/storage/v2/elasticsearch/test_client.py +++ b/cloudkitty/tests/storage/v2/elasticsearch/test_client.py @@ -53,6 +53,13 @@ def test_build_must_with_filters(self): [{'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( diff --git a/cloudkitty/tests/storage/v2/opensearch/test_client.py b/cloudkitty/tests/storage/v2/opensearch/test_client.py index b33515c6..b3c2ae7a 100644 --- a/cloudkitty/tests/storage/v2/opensearch/test_client.py +++ b/cloudkitty/tests/storage/v2/opensearch/test_client.py @@ -53,6 +53,13 @@ def test_build_must_with_filters(self): [{'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( diff --git a/releasenotes/notes/fix-elasticsearch-a9a37443f81b3a79.yaml b/releasenotes/notes/fix-elasticsearch-a9a37443f81b3a79.yaml new file mode 100644 index 00000000..7568dbfb --- /dev/null +++ b/releasenotes/notes/fix-elasticsearch-a9a37443f81b3a79.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fix request to Elasticsearch/OpenSearch that has potentially not the + correct type. diff --git a/tox.ini b/tox.ini index a51a6542..2524e72b 100644 --- a/tox.ini +++ b/tox.ini @@ -15,6 +15,7 @@ usedevelop = True deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/2024.1} -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt + setuptools<82.0.0 commands = find . -type f -name "*.py[co]" -delete @@ -55,6 +56,7 @@ commands = oslopolicy-sample-generator --config-file=etc/oslo-policy-generator/c deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/2024.1} -r{toxinidir}/requirements.txt -r{toxinidir}/doc/requirements.txt + setuptools<82.0.0 commands = sphinx-build -W --keep-going -b html doc/source doc/build/html # TODO(smcginnis) Temporarily disabling this as it fails. Error is that @@ -71,6 +73,7 @@ commands = sphinx-build -W --keep-going -b html doc/source doc/build/html # This environment is called from CI scripts to test and publish # the API Ref to docs.openstack.org. deps = -r{toxinidir}/doc/requirements.txt + setuptools<82.0.0 allowlist_externals = rm commands = rm -rf api-ref/build