From e4164241a32a0b349384a2e1c2524559965e84a3 Mon Sep 17 00:00:00 2001 From: Pierre Riteau Date: Fri, 26 Apr 2024 09:14:45 +0200 Subject: [PATCH] Fix API report requests when using opensearch Change-Id: I68a5297ab71c616856230000f1718ff72d25883d (cherry picked from commit 03d508b746a0ce33bc86676ebc5d8baf23f18143) --- cloudkitty/storage/v2/opensearch/client.py | 5 +++-- cloudkitty/tests/storage/v2/opensearch/test_client.py | 6 +++--- .../notes/fix-opensearch-report-344508dd4e3d0ccc.yaml | 6 ++++++ 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/fix-opensearch-report-344508dd4e3d0ccc.yaml diff --git a/cloudkitty/storage/v2/opensearch/client.py b/cloudkitty/storage/v2/opensearch/client.py index 0b929552..d5757c9b 100644 --- a/cloudkitty/storage/v2/opensearch/client.py +++ b/cloudkitty/storage/v2/opensearch/client.py @@ -98,14 +98,15 @@ class OpenSearchClient(object): sources = [] for elem in groupby: if elem == 'type': - sources.append({'type': {'terms': {'field': 'type'}}}) + sources.append({'type': {'terms': {'field': 'type.keyword'}}}) elif elem == 'time': # Not doing a date_histogram aggregation because we don't know # the period sources.append({'begin': {'terms': {'field': 'start'}}}) sources.append({'end': {'terms': {'field': 'end'}}}) else: - sources.append({elem: {'terms': {'field': 'groupby.' + elem}}}) + field = 'groupby.' + elem + '.keyword' + sources.append({elem: {'terms': {'field': field}}}) return {"sources": sources} diff --git a/cloudkitty/tests/storage/v2/opensearch/test_client.py b/cloudkitty/tests/storage/v2/opensearch/test_client.py index 2fba72dc..b33515c6 100644 --- a/cloudkitty/tests/storage/v2/opensearch/test_client.py +++ b/cloudkitty/tests/storage/v2/opensearch/test_client.py @@ -86,9 +86,9 @@ class TestOpenSearchClient(unittest.TestCase): self.assertEqual( self.client._build_composite(['one', 'type', 'two']), {'sources': [ - {'one': {'terms': {'field': 'groupby.one'}}}, - {'type': {'terms': {'field': 'type'}}}, - {'two': {'terms': {'field': 'groupby.two'}}}, + {'one': {'terms': {'field': 'groupby.one.keyword'}}}, + {'type': {'terms': {'field': 'type.keyword'}}}, + {'two': {'terms': {'field': 'groupby.two.keyword'}}}, ]}, ) diff --git a/releasenotes/notes/fix-opensearch-report-344508dd4e3d0ccc.yaml b/releasenotes/notes/fix-opensearch-report-344508dd4e3d0ccc.yaml new file mode 100644 index 00000000..7f1963fc --- /dev/null +++ b/releasenotes/notes/fix-opensearch-report-344508dd4e3d0ccc.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fix some API report requests that were returning HTTP 500 errors when using + the ``opensearch`` storage backend. This fixes failures to load the Horizon + ``Rating`` panel.