Skip to content

Commit

Permalink
[RHINENG-6095] - Use custom staleness in per_reporter_staleness (#1585)
Browse files Browse the repository at this point in the history
* start new method

* fix(RHIENG-6095): Fix stale_timestamp inside per reporter staleness

* feat(RHINENG-6095): Fix test values
  • Loading branch information
jpramos123 authored Jan 5, 2024
1 parent 395dc1d commit 230c093
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
22 changes: 21 additions & 1 deletion app/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ def serialize_host(
if "reporter" in fields:
serialized_host["reporter"] = host.reporter
if "per_reporter_staleness" in fields:
serialized_host["per_reporter_staleness"] = host.per_reporter_staleness
serialized_host["per_reporter_staleness"] = _serialize_per_reporter_staleness(
host, staleness, staleness_timestamps
)
if "stale_timestamp" in fields:
serialized_host["stale_timestamp"] = stale_timestamp and _serialize_staleness_to_string(stale_timestamp)
if "stale_warning_timestamp" in fields:
Expand Down Expand Up @@ -407,3 +409,21 @@ def serialize_staleness_to_dict(staleness_obj) -> dict:
"immutable_time_to_stale_warning": staleness_obj.immutable_time_to_stale_warning,
"immutable_time_to_delete": staleness_obj.immutable_time_to_delete,
}


def _serialize_per_reporter_staleness(host, staleness, staleness_timestamps):
for reporter in host.per_reporter_staleness:
if host.system_profile_facts.get("host_type") == "edge":
stale_timestamp = staleness_timestamps.stale_timestamp(
_deserialize_datetime(host.per_reporter_staleness[reporter]["last_check_in"]),
staleness["immutable_time_to_stale"],
)
else:
stale_timestamp = staleness_timestamps.stale_timestamp(
_deserialize_datetime(host.per_reporter_staleness[reporter]["last_check_in"]),
staleness["conventional_time_to_stale"],
)

host.per_reporter_staleness[reporter]["stale_timestamp"] = _serialize_staleness_to_string(stale_timestamp)

return host.per_reporter_staleness
5 changes: 4 additions & 1 deletion tests/fixtures/mq_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from datetime import datetime
from datetime import timezone
from unittest.mock import patch

import pytest
Expand Down Expand Up @@ -87,7 +88,9 @@ def mq_create_hosts_in_all_states(mq_create_or_update_host):
@pytest.fixture(scope="function")
def mq_create_deleted_hosts(mq_create_or_update_host):
with patch("app.models.datetime") as mock_datetime:
mock_datetime.now.return_value = datetime(year=2023, month=4, day=2, hour=1, minute=1, second=1)
mock_datetime.now.return_value = datetime(
year=2023, month=4, day=2, hour=1, minute=1, second=1, tzinfo=timezone.utc
)
mock_datetime.side_effect = lambda *args, **kw: datetime(*args, **kw)

staleness_timestamps = get_staleness_timestamps()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_xjoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ def test_response_processed_properly(graphql_query_with_response, api_get):
"puptoo": {
"check_in_succeeded": True,
"last_check_in": "2020-02-10T08:07:03.354307+00:00",
"stale_timestamp": "2020-02-10T08:07:03.354307+00:00",
"stale_timestamp": "2020-02-11T13:07:03.354307+00:00",
}
},
"subscription_manager_id": None,
Expand Down Expand Up @@ -912,7 +912,7 @@ def test_response_processed_properly(graphql_query_with_response, api_get):
"yupana": {
"check_in_succeeded": True,
"last_check_in": "2020-02-10T08:07:03.354307+00:00",
"stale_timestamp": "2020-02-10T08:07:03.354307+00:00",
"stale_timestamp": "2020-02-11T13:07:03.354307+00:00",
}
},
"subscription_manager_id": None,
Expand Down

0 comments on commit 230c093

Please sign in to comment.