Skip to content

Commit a2e21d8

Browse files
authored
backend: Set expiration for ingested reports, fixes #258. (#468)
1 parent 92c7045 commit a2e21d8

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

backend/code_coverage_backend/gcp.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ def ingest_report(self, report):
132132
assert len(overall_coverage) > 0, "No overall coverage"
133133
self.redis.hmset(report.key_overall, overall_coverage)
134134

135+
# Apply expiry for overall report
136+
if report.ttl is not None:
137+
self.redis.expire(report.key_overall, report.ttl)
138+
135139
# Add the changeset to the sorted sets of known reports
136140
# The numeric push_id is used as a score to keep the ingested
137141
# changesets ordered

backend/code_coverage_backend/report.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,15 @@ def key_overall(self):
9494
platform = self.platform or "all"
9595
suite = self.suite or "all"
9696
return f"overall:{self.repository}:{self.changeset}:{platform}:{suite}"
97+
98+
@property
99+
def ttl(self):
100+
"""Time to live in seconds for the full report
101+
102+
Will be None (no expiry) for full report (all:all)
103+
Otherwise set to 2 weeks
104+
"""
105+
if self.suite == DEFAULT_FILTER and self.platform == DEFAULT_FILTER:
106+
return
107+
108+
return 15 * 24 * 3600

backend/tests/test_gcp.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ def test_ingestion(mock_cache):
6565
mock_cache.ingest_report(report_2)
6666
mock_cache.ingest_report(report_10)
6767

68+
# Check expiry
69+
assert report_1.ttl is None
70+
assert mock_cache.redis.ttl(report_1.key_overall) == -1
71+
6872
# They must be in redis and on the file system
6973
assert mock_cache.redis.zcard(b"reports:myrepo:all:all") == 3
7074
assert mock_cache.redis.zcard(b"history:myrepo") == 3
@@ -108,6 +112,33 @@ def test_ingestion(mock_cache):
108112
]
109113

110114

115+
def test_expiry(mock_cache):
116+
"""
117+
Test expiry for platform & suite reports
118+
"""
119+
mock_cache.bucket.add_mock_blob("myrepo/rev1/all:somesuite.json.zstd", coverage=1.0)
120+
report_suite = Report(
121+
mock_cache.reports_dir,
122+
"myrepo",
123+
"rev1",
124+
platform="all",
125+
suite="somesuite",
126+
date=1000,
127+
push_id=1,
128+
)
129+
mock_cache.ingest_report(report_suite)
130+
assert report_suite.ttl == 1296000
131+
assert mock_cache.redis.ttl(report_suite.key_overall) > 0
132+
133+
mock_cache.bucket.add_mock_blob("myrepo/rev1/win:all.json.zstd", coverage=1.0)
134+
report_platform = Report(
135+
mock_cache.reports_dir, "myrepo", "rev1", platform="win", date=2000, push_id=2
136+
)
137+
mock_cache.ingest_report(report_platform)
138+
assert report_platform.ttl == 1296000
139+
assert mock_cache.redis.ttl(report_platform.key_overall) > 0
140+
141+
111142
def test_ingest_hgmo(mock_cache, mock_hgmo):
112143
"""
113144
Test ingestion using a mock HGMO

0 commit comments

Comments
 (0)