Skip to content

Commit cf86b9a

Browse files
[management] enable access log cleanup by default (#5842)
1 parent ee588e1 commit cf86b9a

4 files changed

Lines changed: 23 additions & 9 deletions

File tree

combined/cmd/config.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,11 @@ type StoreConfig struct {
179179

180180
// ReverseProxyConfig contains reverse proxy settings
181181
type ReverseProxyConfig struct {
182-
TrustedHTTPProxies []string `yaml:"trustedHTTPProxies"`
183-
TrustedHTTPProxiesCount uint `yaml:"trustedHTTPProxiesCount"`
184-
TrustedPeers []string `yaml:"trustedPeers"`
182+
TrustedHTTPProxies []string `yaml:"trustedHTTPProxies"`
183+
TrustedHTTPProxiesCount uint `yaml:"trustedHTTPProxiesCount"`
184+
TrustedPeers []string `yaml:"trustedPeers"`
185+
AccessLogRetentionDays int `yaml:"accessLogRetentionDays"`
186+
AccessLogCleanupIntervalHours int `yaml:"accessLogCleanupIntervalHours"`
185187
}
186188

187189
// DefaultConfig returns a CombinedConfig with default values
@@ -645,7 +647,9 @@ func (c *CombinedConfig) ToManagementConfig() (*nbconfig.Config, error) {
645647

646648
// Build reverse proxy config
647649
reverseProxy := nbconfig.ReverseProxy{
648-
TrustedHTTPProxiesCount: mgmt.ReverseProxy.TrustedHTTPProxiesCount,
650+
TrustedHTTPProxiesCount: mgmt.ReverseProxy.TrustedHTTPProxiesCount,
651+
AccessLogRetentionDays: mgmt.ReverseProxy.AccessLogRetentionDays,
652+
AccessLogCleanupIntervalHours: mgmt.ReverseProxy.AccessLogCleanupIntervalHours,
649653
}
650654
for _, p := range mgmt.ReverseProxy.TrustedHTTPProxies {
651655
if prefix, err := netip.ParsePrefix(p); err == nil {

management/internals/modules/reverseproxy/accesslogs/manager/manager.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,23 @@ func (m *managerImpl) CleanupOldAccessLogs(ctx context.Context, retentionDays in
106106

107107
// StartPeriodicCleanup starts a background goroutine that periodically cleans up old access logs
108108
func (m *managerImpl) StartPeriodicCleanup(ctx context.Context, retentionDays, cleanupIntervalHours int) {
109-
if retentionDays <= 0 {
110-
log.WithContext(ctx).Debug("periodic access log cleanup disabled: retention days is 0 or negative")
109+
if retentionDays < 0 {
110+
log.WithContext(ctx).Debug("periodic access log cleanup disabled: retention days is negative")
111111
return
112112
}
113113

114+
if retentionDays == 0 {
115+
retentionDays = 7
116+
log.WithContext(ctx).Debugf("no retention days specified for access log cleanup, defaulting to %d days", retentionDays)
117+
} else {
118+
log.WithContext(ctx).Debugf("access log retention period set to %d days", retentionDays)
119+
}
120+
114121
if cleanupIntervalHours <= 0 {
115122
cleanupIntervalHours = 24
123+
log.WithContext(ctx).Debugf("no cleanup interval specified for access log cleanup, defaulting to %d hours", cleanupIntervalHours)
124+
} else {
125+
log.WithContext(ctx).Debugf("access log cleanup interval set to %d hours", cleanupIntervalHours)
116126
}
117127

118128
cleanupCtx, cancel := context.WithCancel(ctx)

management/internals/modules/reverseproxy/accesslogs/manager/manager_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func TestCleanupWithExactBoundary(t *testing.T) {
121121
}
122122

123123
func TestStartPeriodicCleanup(t *testing.T) {
124-
t.Run("periodic cleanup disabled with zero retention", func(t *testing.T) {
124+
t.Run("periodic cleanup disabled with negative retention", func(t *testing.T) {
125125
ctrl := gomock.NewController(t)
126126
defer ctrl.Finish()
127127

@@ -135,7 +135,7 @@ func TestStartPeriodicCleanup(t *testing.T) {
135135
ctx, cancel := context.WithCancel(context.Background())
136136
defer cancel()
137137

138-
manager.StartPeriodicCleanup(ctx, 0, 1)
138+
manager.StartPeriodicCleanup(ctx, -1, 1)
139139

140140
time.Sleep(100 * time.Millisecond)
141141

management/internals/server/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ type ReverseProxy struct {
203203

204204
// AccessLogRetentionDays specifies the number of days to retain access logs.
205205
// Logs older than this duration will be automatically deleted during cleanup.
206-
// A value of 0 or negative means logs are kept indefinitely (no cleanup).
206+
// A value of 0 will default to 7 days. Negative means logs are kept indefinitely (no cleanup).
207207
AccessLogRetentionDays int
208208

209209
// AccessLogCleanupIntervalHours specifies how often (in hours) to run the cleanup routine.

0 commit comments

Comments
 (0)