Skip to content

Commit a2f4b11

Browse files
authored
Merge pull request #100 from stackhpc/2024.1-cherry-pick
Apply 2024.1 backports from 2023.1
2 parents 57ea7f3 + 1853c37 commit a2f4b11

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

cloudkitty/collector/prometheus.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ def fetch_all(self, metric_name, start, end, scope_id, q_filter=None):
212212
if query_suffix:
213213
query = "{0} {1}".format(query, query_suffix)
214214

215+
LOG.debug("Calling Prometheus with query: %s", query)
216+
215217
try:
216218
res = self._conn.get_instant(
217219
query,

cloudkitty/storage/v2/elasticsearch/client.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,15 @@ def _build_composite(self, groupby):
9898
sources = []
9999
for elem in groupby:
100100
if elem == 'type':
101-
sources.append({'type': {'terms': {'field': 'type'}}})
101+
sources.append({'type': {'terms': {'field': 'type.keyword'}}})
102102
elif elem == 'time':
103103
# Not doing a date_histogram aggregation because we don't know
104104
# the period
105105
sources.append({'begin': {'terms': {'field': 'start'}}})
106106
sources.append({'end': {'terms': {'field': 'end'}}})
107107
else:
108-
sources.append({elem: {'terms': {'field': 'groupby.' + elem}}})
108+
field = 'groupby.' + elem + '.keyword'
109+
sources.append({elem: {'terms': {'field': field}}})
109110

110111
return {"sources": sources}
111112

@@ -158,12 +159,9 @@ def put_mapping(self, mapping):
158159
:rtype: requests.models.Response
159160
"""
160161
url = '/'.join(
161-
(self._url, self._index_name, '_mapping', self._mapping_name))
162-
# NOTE(peschk_l): This is done for compatibility with
163-
# Elasticsearch 6 and 7.
164-
param = {"include_type_name": "true"}
162+
(self._url, self._index_name, self._mapping_name))
165163
return self._req(
166-
self._sess.put, url, json.dumps(mapping), param, deserialize=False)
164+
self._sess.post, url, json.dumps(mapping), {}, deserialize=False)
167165

168166
def get_index(self):
169167
"""Does a GET request against ES's index API.
@@ -228,7 +226,7 @@ def bulk_with_instruction(self, instruction, terms):
228226
"""Does a POST request against ES's bulk API
229227
230228
The POST request will be done against
231-
`/<index_name>/<mapping_name>/_bulk`
229+
`/<index_name>/_bulk`
232230
233231
The instruction will be appended before each term. For example,
234232
bulk_with_instruction('instr', ['one', 'two']) will produce::
@@ -249,7 +247,7 @@ def bulk_with_instruction(self, instruction, terms):
249247
*[(instruction, json.dumps(term)) for term in terms]
250248
)) + '\n'
251249
url = '/'.join(
252-
(self._url, self._index_name, self._mapping_name, '_bulk'))
250+
(self._url, self._index_name, '_bulk'))
253251
return self._req(self._sess.post, url, data, None, deserialize=False)
254252

255253
def bulk_index(self, terms):

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ def test_build_composite(self):
8686
self.assertEqual(
8787
self.client._build_composite(['one', 'type', 'two']),
8888
{'sources': [
89-
{'one': {'terms': {'field': 'groupby.one'}}},
90-
{'type': {'terms': {'field': 'type'}}},
91-
{'two': {'terms': {'field': 'groupby.two'}}},
89+
{'one': {'terms': {'field': 'groupby.one.keyword'}}},
90+
{'type': {'terms': {'field': 'type.keyword'}}},
91+
{'two': {'terms': {'field': 'groupby.two.keyword'}}},
9292
]},
9393
)
9494

@@ -186,9 +186,9 @@ def test_put_mapping(self):
186186
with mock.patch.object(self.client, '_req') as rmock:
187187
self.client.put_mapping(mapping)
188188
rmock.assert_called_once_with(
189-
self.client._sess.put,
190-
'http://elasticsearch:9200/index_name/_mapping/test_mapping',
191-
'{"a": "b"}', {'include_type_name': 'true'}, deserialize=False)
189+
self.client._sess.post,
190+
'http://elasticsearch:9200/index_name/test_mapping',
191+
'{"a": "b"}', {}, deserialize=False)
192192

193193
def test_get_index(self):
194194
with mock.patch.object(self.client, '_req') as rmock:
@@ -259,7 +259,7 @@ def test_bulk_with_instruction(self):
259259
self.client.bulk_with_instruction(instruction, terms)
260260
rmock.assert_called_once_with(
261261
self.client._sess.post,
262-
'http://elasticsearch:9200/index_name/test_mapping/_bulk',
262+
'http://elasticsearch:9200/index_name/_bulk',
263263
expected_data, None, deserialize=False)
264264

265265
def test_bulk_index(self):

0 commit comments

Comments
 (0)