Commit f6f401b2 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos/collect: Preserve entries at the database for 15 days

  This may case more memory usage and more 'live' data to handle,
  for this reason, I'm making it configurable
parent 9a1f39a8
......@@ -89,7 +89,8 @@ def do_collect(conf):
user_dict[snapshot.username].append(snapshot)
except (KeyboardInterrupt, SystemExit, NoSuchProcess):
raise
days_to_preserve = conf.getint("slapos", "collect_cache", 15)
log_directory = "%s/var/data-log" % conf.get("slapos", "instance_root")
mkdir_p(log_directory, 0o755)
......@@ -160,7 +161,7 @@ def do_collect(conf):
compressLogFolder(log_directory)
# Drop older entries already reported
database.garbageCollect()
database.garbageCollect(int(days_to_preserve))
except AccessDenied:
print("You HAVE TO execute this script with root permission.")
......
......@@ -259,7 +259,7 @@ class Database:
return [i[0] for i in self._execute(
"SELECT name FROM sqlite_master WHERE type='table'")]
def _getGarbageCollectionDateList(self, days_to_preserve=3):
def _getGarbageCollectionDateList(self, days_to_preserve):
""" Return the list of dates to Preserve when data collect
"""
base = datetime.datetime.today()
......@@ -268,11 +268,11 @@ class Database:
date_list.append((base - datetime.timedelta(days=x)).strftime("%Y-%m-%d"))
return date_list
def garbageCollect(self):
def garbageCollect(self, days_to_preserve=3):
""" Garbase collect the database, by removing older records already
reported.
"""
date_list = self._getGarbageCollectionDateList()
date_list = self._getGarbageCollectionDateList(days_to_preserve)
where_clause = "reported = 1"
for _date in date_list:
where_clause += " AND date != '%s' " % _date
......
......@@ -214,7 +214,7 @@ class TestCollectDatabase(unittest.TestCase):
def test_garbage_collection_date_list(self):
database = db.Database(self.instance_root)
self.assertEqual(len(database._getGarbageCollectionDateList()), 3)
self.assertEqual(len(database._getGarbageCollectionDateList(3)), 3)
self.assertEqual(len(database._getGarbageCollectionDateList(1)), 1)
self.assertEqual(len(database._getGarbageCollectionDateList(0)), 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment