Skip to content

Commit f647e44

Browse files
Ning Yaorafaelweingartner
authored andcommitted
Fix response format 'total' for v2 dataframes API
Based on [1], the response for v2 dataframes is {"total": 3}. However, for Elasticsearch search response [2], the "hits.total" in the response body is {"value": 3, "relation": "eq"}, which does not match the API response schema. [1]: https://docs.openstack.org/cloudkitty/latest/api-reference/v2/index.html?expanded=get-dataframes-from-the-storage-backend-detail#response-example [2]: https://www.elastic.co/guide/en/elasticsearch/reference/8.3/search-your-data.html Story: 2010219 Task: 45967 Change-Id: Ie2c8fd1b146138efc085d7c844afd27b7e10f3f3 Co-Authored-By: Rafael Weingärtner <[email protected]> Signed-off-by: Ning Yao <[email protected]> (cherry picked from commit 3ba19ed)
1 parent 185f9be commit f647e44

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

cloudkitty/storage/v2/elasticsearch/client.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,14 @@ def retrieve(self, begin, end, filters, metric_types,
308308

309309
scroll_id = resp['_scroll_id']
310310
self._scroll_ids.add(scroll_id)
311-
total = resp['hits']['total']
311+
total_hits = resp['hits']['total']
312+
313+
if isinstance(total_hits, dict):
314+
LOG.debug("Total hits [%s] is a dict. Therefore, we only extract "
315+
"the 'value' attribute as the total option.", total_hits)
316+
total_hits = total_hits.get("value")
317+
318+
total = total_hits
312319
chunk = resp['hits']['hits']
313320

314321
output = chunk[offset:offset+limit if paginate else len(chunk)]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
Fix response format ``total`` for v2 dataframes API. The response for v2
5+
dataframes is ``{"total": 3}``. However, for Elasticsearch search response,
6+
the ``"hits.total"`` in the response body is ``{"value": 3, "relation":
7+
"eq"}``, which does not match the API response schema.

0 commit comments

Comments
 (0)