Skip to content

Commit

Permalink
Use proper start timeframe when handling different resources together
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelweingartner committed Aug 15, 2023
1 parent 69b0b7c commit 7648012
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion gnocchi/rest/aggregates/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,17 @@ def get_grouped_measures(self):
return response

def group(self, to_group):
to_group.sort(key=lambda g: g['revision_start'])
to_group.sort(key=lambda g: (g['original_resource_id'],
g['revision_start']))

is_first = True
last_processed_resource_id = None
for value in to_group:
resource_id = value['original_resource_id']
if resource_id != last_processed_resource_id:
last_processed_resource_id = resource_id
is_first = True

self.truncate_resource_time_window(value, is_first=is_first)
is_first = False
to_group.sort(key=lambda x: tuple((attr, str(x[attr] or ''))
Expand Down
3 changes: 3 additions & 0 deletions gnocchi/tests/test_aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,21 @@ def setUp(self):

self.test_resource_1 = {
'uuid': '30b51786-944f-427b-85df-ce5f462e58a4',
'original_resource_id': '30b51786-944f-427b-85df-ce5f462e58a4',
'revision_start': self.start - datetime.timedelta(hours=10),
'revision_end': self.start - datetime.timedelta(hours=9),
"attribute1": "a", "attribute2": "a", "attribute3": "a"
}
self.test_resource_2 = {
'uuid': '17002c42-2f30-45fb-b1f1-eb33f7345e89',
'original_resource_id': '17002c42-2f30-45fb-b1f1-eb33f7345e89',
'revision_start': self.start - datetime.timedelta(hours=7),
'revision_end': self.start - datetime.timedelta(hours=5),
"attribute1": None, "attribute2": "b", "attribute3": "b"
}
self.test_resource_3 = {
'uuid': '8f6be3bb-d5ee-4d01-986b-c034386637b0',
'original_resource_id': '8f6be3bb-d5ee-4d01-986b-c034386637b0',
'revision_start': self.start - datetime.timedelta(hours=2),
'revision_end': self.start - datetime.timedelta(hours=1),
"attribute1": "c", "attribute2": None, "attribute3": None
Expand Down
1 change: 1 addition & 0 deletions gnocchi/tests/test_measures_grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self, id, flavor_name, host, display_name,
self.display_name = display_name
self.revision_start = revision_start
self.revision_end = None
self.original_resource_id = str(hash(id))


class ResourceHistory(object):
Expand Down

0 comments on commit 7648012

Please sign in to comment.