Skip to content

Commit

Permalink
feat: Get last updated ts for AtlasProxy (#177)
Browse files Browse the repository at this point in the history
* get_latest_updated_ts_atlas_proxy | 🎉 Initial commit.

Signed-off-by: mgorsk1 <[email protected]>

* get_latest_updated_ts_atlas_proxy | ✅ Adding tests.

Signed-off-by: mgorsk1 <[email protected]>
  • Loading branch information
mgorsk1 authored Aug 25, 2020
1 parent 8d0eb48 commit 3e92586
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
12 changes: 11 additions & 1 deletion metadata_service/proxy/atlas_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,17 @@ def get_popular_tables(self, *, num_entries: int) -> List[PopularTable]:
return popular_tables

def get_latest_updated_ts(self) -> int:
pass
date = None

for metrics in self._driver.admin_metrics:
try:
date = self._parse_date(metrics.general.get('stats', {}).get('Notification:lastMessageProcessedTime'))
except AttributeError:
pass

date = date or 0

return date

def get_tags(self) -> List:
"""
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/proxy/fixtures/atlas_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,11 @@ class Data:
}}

report_entities = [report_entity_1, report_entity_2, report_entity_3]

metrics_data = [DottedDict({
'general': {
'stats': {
'Notification:lastMessageProcessedTime': 1598342400000
}
}
})]
12 changes: 12 additions & 0 deletions tests/unit/proxy/test_atlas_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,18 @@ def test_get_frequently_used_tables(self) -> None:

self.assertEqual(expected, res)

def test_get_latest_updated_ts_when_exists(self) -> None:
with patch.object(self.proxy._driver, 'admin_metrics', self.metrics_data):
result = self.proxy.get_latest_updated_ts()

assert result == 1598342400

def test_get_latest_updated_ts_when_not_exists(self) -> None:
with patch.object(self.proxy._driver, 'admin_metrics', []):
result = self.proxy.get_latest_updated_ts()

assert result == 0


if __name__ == '__main__':
unittest.main()

0 comments on commit 3e92586

Please sign in to comment.