Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gnocchi/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ def execute_metadata_updates_if_needed(self, indexer_driver, measures, metric):
"resource ID [%s] needs to be restored. The measurement timestamps are [%s].",
resource, metric.id, resource_id, measures['timestamps'])

if resource.ended_at is not None:
if resource.ended_at is not None and indexer_driver.conf.metricd.metric_inactive_after > 0:
if resource.ended_at > latest_timestamp_in_measurements:
LOG.info("Resource [%s] was marked with a timestamp for the 'ended_at' field. It received a "
"measurement for metric [%s]. However, we do not restore it as the latest timestamp "
Expand Down
24 changes: 24 additions & 0 deletions gnocchi/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,7 @@ def test_execute_metadata_updates_if_needed_resource_recover(self):
latest_timestamp_in_measurements = latest_timestamp_in_measurements.replace(tzinfo=datetime.timezone.utc)

indexer_driver_mock = mock.Mock()
indexer_driver_mock.conf.metricd.metric_inactive_after = 1
metric_mock = mock.Mock()
metric_mock.needs_raw_data_truncation = True

Expand Down Expand Up @@ -1389,6 +1390,7 @@ def test_execute_metadata_updates_if_needed_resource_no_recover(self):
numpy.datetime64('1973-01-01T00:00:00')]}

indexer_driver_mock = mock.Mock()
indexer_driver_mock.conf.metricd.metric_inactive_after = 1
metric_mock = mock.Mock()
metric_mock.needs_raw_data_truncation = True

Expand Down Expand Up @@ -1427,6 +1429,28 @@ def test_execute_metadata_updates_if_needed_resource_no_recover(self):
self.assertEqual(1, log_mock.info.call_count)
self.assertEqual(1, log_mock.debug.call_count)

def test_execute_metadata_updates_if_needed_resource_no_recover_when_inactivity_disabled(self):
measures = {"timestamps": [numpy.datetime64('2030-01-01T00:00:00')]}

indexer_driver_mock = mock.Mock()
indexer_driver_mock.conf.metricd.metric_inactive_after = 0

metric_mock = mock.Mock()
metric_mock.needs_raw_data_truncation = False
metric_mock.resource_id = 1

resource_mock = mock.Mock()
resource_mock.ended_at = datetime.datetime(
2023, 11, 4, tzinfo=datetime.timezone.utc)
indexer_driver_mock.get_resource.return_value = resource_mock

self.storage.execute_metadata_updates_if_needed(
indexer_driver_mock, measures, metric_mock)

indexer_driver_mock.update_last_measure_timestamp.assert_called_once_with(
metric_mock.id)
indexer_driver_mock.update_resource.assert_not_called()

def test_add_measures_to_metrics(self):
raw_measures_mock = mock.Mock()

Expand Down
Loading