Temporarily change to storing logs in a new LogEntry2 table
This will prevent us from running out of auto-incrementing ID values until such time as we can upgrade to peewee 3 and change the field type to a BigInt Fixes https://jira.coreos.com/browse/QUAY-943
This commit is contained in:
parent
66b4e45929
commit
a007332d4c
13 changed files with 201 additions and 113 deletions
|
@ -1,45 +0,0 @@
|
|||
import logging
|
||||
|
||||
from datetime import timedelta, datetime
|
||||
|
||||
from app import app
|
||||
from data.database import LogEntry
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
LOG_FORMAT = "%(asctime)s [%(process)d] [%(levelname)s] [%(name)s] %(message)s"
|
||||
BATCH_SIZE = 1000
|
||||
|
||||
def delete_old_logentries(delete_before):
|
||||
delete_up_to_id = (LogEntry
|
||||
.select(LogEntry.id)
|
||||
.where(LogEntry.datetime <= delete_before)
|
||||
.order_by(LogEntry.id.desc())
|
||||
.limit(1)
|
||||
.tuples())[0][0]
|
||||
logger.debug('Deleting up to id: %s', delete_up_to_id)
|
||||
|
||||
start_from_id = (LogEntry
|
||||
.select(LogEntry.id)
|
||||
.order_by(LogEntry.id)
|
||||
.limit(1)
|
||||
.tuples())[0][0]
|
||||
logger.debug('Starting from id: %s', start_from_id)
|
||||
|
||||
deleted = 1
|
||||
current_batch_end = min(start_from_id + BATCH_SIZE, delete_up_to_id)
|
||||
while deleted > 0 or current_batch_end < delete_up_to_id:
|
||||
deleted = (LogEntry
|
||||
.delete()
|
||||
.where(LogEntry.id <= current_batch_end)
|
||||
.execute())
|
||||
logger.debug('Deleted %s entries', deleted)
|
||||
current_batch_end = min(current_batch_end + BATCH_SIZE, delete_up_to_id)
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT)
|
||||
|
||||
now = datetime.now()
|
||||
one_month_ago = now - timedelta(days=30)
|
||||
|
||||
delete_old_logentries(one_month_ago)
|
Reference in a new issue