Skip to content

Commit 2091b30

Browse files
authored
backend: Remove old overall suite-level data (#452)
1 parent 5b6fe0c commit 2091b30

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

backend/code_coverage_backend/gcp.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import re
66
import tempfile
77
from datetime import datetime
8+
from datetime import timedelta
89

10+
import pytz
911
import redis
1012
import structlog
1113
import zstandard as zstd
@@ -368,7 +370,7 @@ def get_suites(self, repository):
368370
suites = self.redis.smembers(KEY_SUITES.format(repository=repository))
369371
return sorted(map(lambda x: x.decode("utf-8"), suites))
370372

371-
def ingest_available_reports(self, repository):
373+
def ingest_available_reports(self, repository, until=None):
372374
"""
373375
Ingest all the available reports for a repository
374376
"""
@@ -377,8 +379,13 @@ def ingest_available_reports(self, repository):
377379
REGEX_BLOB = re.compile(
378380
r"^{}/(\w+)/([\w\-]+):([\w\-]+).json.zstd$".format(repository)
379381
)
382+
now = datetime.utcnow().replace(tzinfo=pytz.UTC)
380383
for blob in self.bucket.list_blobs(prefix=repository):
381384

385+
if isinstance(until, timedelta) and (now - blob.time_created) >= until:
386+
logger.debug(f"Skipping old blob {blob}")
387+
continue
388+
382389
# Get changeset from blob name
383390
match = REGEX_BLOB.match(blob.name)
384391
if match is None:

backend/tools/cleanup.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
# This Source Code Form is subject to the terms of the Mozilla Public
3+
# License, v. 2.0. If a copy of the MPL was not distributed with this
4+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
6+
import os
7+
8+
import redis
9+
10+
11+
def cleanup(client, prefix):
12+
nb, memory = 0, 0
13+
for key in client.keys(f"{prefix}:*"):
14+
if key.endswith(b"all:all"):
15+
continue
16+
17+
key_memory = client.memory_usage(key)
18+
nb += 1
19+
memory += key_memory
20+
print(f"Removing {key_memory}b for {key}")
21+
22+
client.delete(key)
23+
24+
print(f"Removed {nb} keys for {memory} bytes")
25+
26+
27+
if __name__ == "__main__":
28+
client = redis.from_url(os.environ["REDIS_URL"])
29+
cleanup(client, "overall:mozilla-central")

0 commit comments

Comments
 (0)