Skip to content

Commit ea3a366

Browse files
committed
Change rotation to timed, rather than size
1 parent 727d227 commit ea3a366

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

internal/controller/standalone_pgadmin/pod.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,10 @@ func startupCommand(ctx context.Context, inPgadmin *v1beta1.PGAdmin) []string {
381381
)
382382
var (
383383
maxBackupRetentionNumber = "1"
384-
retentionPeriod = "24 * 60"
384+
// One day in minutes for pgadmin rotation
385+
pgAdminRetentionPeriod = "24 * 60"
386+
// Daily rotation for gunicorn rotation
387+
gunicornRetentionPeriod = "D"
385388
)
386389

387390
// If the OpenTelemetryLogs Feature is enabled and the user has set a retention period,
@@ -398,7 +401,10 @@ func startupCommand(ctx context.Context, inPgadmin *v1beta1.PGAdmin) []string {
398401
// for the currently-used log file.
399402
maxBackupRetentionNumber = strconv.Itoa(retentionNumber - 1)
400403
if period == "hourly" {
401-
retentionPeriod = "60"
404+
// If the period is hourly, set the pgadmin
405+
// and gunicorn retention periods to hourly.
406+
pgAdminRetentionPeriod = "60"
407+
gunicornRetentionPeriod = "H"
402408
}
403409
}
404410

@@ -420,7 +426,7 @@ if os.path.isfile('` + configDatabaseURIPathAbsolutePath + `'):
420426
421427
DATA_DIR = '` + dataMountPath + `'
422428
LOG_FILE = '` + LogFileAbsolutePath + `'
423-
LOG_ROTATION_AGE = ` + retentionPeriod + ` # minutes
429+
LOG_ROTATION_AGE = ` + pgAdminRetentionPeriod + ` # minutes
424430
LOG_ROTATION_SIZE = 5 # MiB
425431
LOG_ROTATION_MAX_LOG_FILES = ` + maxBackupRetentionNumber + `
426432
@@ -455,9 +461,11 @@ logconfig_dict = copy.deepcopy(gunicorn.glogging.CONFIG_DEFAULTS)
455461
logconfig_dict['loggers']['gunicorn.access']['handlers'] = ['file']
456462
logconfig_dict['loggers']['gunicorn.error']['handlers'] = ['file']
457463
logconfig_dict['handlers']['file'] = {
458-
'class': 'logging.handlers.RotatingFileHandler',
464+
'class': 'logging.handlers.TimedRotatingFileHandler',
459465
'filename': '` + GunicornLogFileAbsolutePath + `',
460-
'backupCount': ` + maxBackupRetentionNumber + `, 'maxBytes': 2 << 20, # MiB
466+
'backupCount': ` + maxBackupRetentionNumber + `,
467+
'interval': 1, # every one unit (defined by when), rotate
468+
'when': '` + gunicornRetentionPeriod + `',
461469
'formatter': 'json',
462470
}
463471
logconfig_dict['formatters']['json'] = {

internal/controller/standalone_pgadmin/pod_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,11 @@ initContainers:
181181
logconfig_dict['loggers']['gunicorn.access']['handlers'] = ['file']
182182
logconfig_dict['loggers']['gunicorn.error']['handlers'] = ['file']
183183
logconfig_dict['handlers']['file'] = {
184-
'class': 'logging.handlers.RotatingFileHandler',
184+
'class': 'logging.handlers.TimedRotatingFileHandler',
185185
'filename': '/var/lib/pgadmin/logs/gunicorn.log',
186-
'backupCount': 1, 'maxBytes': 2 << 20, # MiB
186+
'backupCount': 1,
187+
'interval': 1, # every one unit (defined by when), rotate
188+
'when': 'D',
187189
'formatter': 'json',
188190
}
189191
logconfig_dict['formatters']['json'] = {
@@ -414,9 +416,11 @@ initContainers:
414416
logconfig_dict['loggers']['gunicorn.access']['handlers'] = ['file']
415417
logconfig_dict['loggers']['gunicorn.error']['handlers'] = ['file']
416418
logconfig_dict['handlers']['file'] = {
417-
'class': 'logging.handlers.RotatingFileHandler',
419+
'class': 'logging.handlers.TimedRotatingFileHandler',
418420
'filename': '/var/lib/pgadmin/logs/gunicorn.log',
419-
'backupCount': 11, 'maxBytes': 2 << 20, # MiB
421+
'backupCount': 11,
422+
'interval': 1, # every one unit (defined by when), rotate
423+
'when': 'H',
420424
'formatter': 'json',
421425
}
422426
logconfig_dict['formatters']['json'] = {

0 commit comments

Comments
 (0)