Skip to content

Commit 35e9ae1

Browse files
authored
fix logRotate and fix path naming add auditlogrotation (mongodb#1591)
1 parent 604ef86 commit 35e9ae1

6 files changed

+24
-5
lines changed

api/v1/mongodbcommunity_types.go

+3
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@ type AgentConfiguration struct {
373373
// LogRotate if enabled, will enable LogRotate for all processes.
374374
LogRotate *automationconfig.CrdLogRotate `json:"logRotate,omitempty"`
375375
// +optional
376+
// AuditLogRotate if enabled, will enable AuditLogRotate for all processes.
377+
AuditLogRotate *automationconfig.CrdLogRotate `json:"AuditLogRotate,omitempty"`
378+
// +optional
376379
// SystemLog configures system log of mongod
377380
SystemLog *automationconfig.SystemLog `json:"systemLog,omitempty"`
378381
}

controllers/mongodb_tls_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ func TestAutomationConfigIsCorrectlyConfiguredWithTLS(t *testing.T) {
329329
assert.Equal(t, "/tmp/test", process.Args26.Get("systemLog.path").String())
330330
assert.Equal(t, "file", process.Args26.Get("systemLog.destination").String())
331331
assert.Equal(t, process.LogRotate, automationconfig.ConvertCrdLogRotateToAC(mdb.Spec.AgentConfiguration.LogRotate))
332+
assert.Equal(t, process.AuditLogRotate, automationconfig.ConvertCrdLogRotateToAC(mdb.Spec.AgentConfiguration.AuditLogRotate))
332333
}
333334
})
334335

controllers/replica_set_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ func buildAutomationConfig(mdb mdbv1.MongoDBCommunity, auth automationconfig.Aut
535535
AddModifications(getMongodConfigModification(mdb)).
536536
AddModifications(modifications...).
537537
AddProcessModification(func(_ int, p *automationconfig.Process) {
538-
automationconfig.ConfigureAgentConfiguration(mdb.Spec.AgentConfiguration.SystemLog, mdb.Spec.AgentConfiguration.LogRotate, p)
538+
automationconfig.ConfigureAgentConfiguration(mdb.Spec.AgentConfiguration.SystemLog, mdb.Spec.AgentConfiguration.LogRotate, mdb.Spec.AgentConfiguration.AuditLogRotate, p)
539539
}).
540540
Build()
541541
}

controllers/replicaset_controller_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ func newTestReplicaSetWithSystemLogAndLogRotate() mdbv1.MongoDBCommunity {
8888
LogRotate: &automationconfig.CrdLogRotate{
8989
SizeThresholdMB: "1",
9090
},
91+
AuditLogRotate: &automationconfig.CrdLogRotate{
92+
SizeThresholdMB: "1",
93+
},
9194
SystemLog: &automationconfig.SystemLog{
9295
Destination: automationconfig.File,
9396
Path: "/tmp/test",

pkg/automationconfig/automation_config.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ type Process struct {
135135
ProcessType ProcessType `json:"processType"`
136136
Version string `json:"version"`
137137
AuthSchemaVersion int `json:"authSchemaVersion"`
138-
LogRotate *AcLogRotate `json:"LogRotate,omitempty"`
138+
LogRotate *AcLogRotate `json:"logRotate,omitempty"`
139+
AuditLogRotate *AcLogRotate `json:"auditLogRotate,omitempty"`
139140
}
140141

141142
func (p *Process) SetPort(port int) *Process {
@@ -180,6 +181,12 @@ func (p *Process) SetLogRotate(lr *CrdLogRotate) *Process {
180181
return p
181182
}
182183

184+
// SetAuditLogRotate sets the acLogRotate by converting the CrdLogRotate to an acLogRotate.
185+
func (p *Process) SetAuditLogRotate(lr *CrdLogRotate) *Process {
186+
p.AuditLogRotate = ConvertCrdLogRotateToAC(lr)
187+
return p
188+
}
189+
183190
// ConvertCrdLogRotateToAC converts a CrdLogRotate to an AcLogRotate representation.
184191
func ConvertCrdLogRotateToAC(lr *CrdLogRotate) *AcLogRotate {
185192
if lr == nil {
@@ -478,7 +485,7 @@ func FromBytes(acBytes []byte) (AutomationConfig, error) {
478485
return ac, nil
479486
}
480487

481-
func ConfigureAgentConfiguration(systemLog *SystemLog, logRotate *CrdLogRotate, p *Process) {
488+
func ConfigureAgentConfiguration(systemLog *SystemLog, logRotate *CrdLogRotate, auditLR *CrdLogRotate, p *Process) {
482489
if systemLog != nil {
483490
p.SetSystemLog(*systemLog)
484491
}
@@ -491,6 +498,7 @@ func ConfigureAgentConfiguration(systemLog *SystemLog, logRotate *CrdLogRotate,
491498
zap.S().Warn("Configuring LogRotate with systemLog.Destination = Syslog will not work")
492499
}
493500
p.SetLogRotate(logRotate)
501+
p.SetAuditLogRotate(auditLR)
494502
}
495503

496504
}

pkg/automationconfig/automation_config_secret_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestEnsureSecret(t *testing.T) {
4444
ctx := context.Background()
4545

4646
desiredAutomationConfig, err = NewBuilder().SetMembers(3).AddProcessModification(func(i_ int, p *Process) {
47-
p.SetLogRotate(&CrdLogRotate{
47+
lr := &CrdLogRotate{
4848
SizeThresholdMB: "0.001",
4949
LogRotate: LogRotate{
5050
TimeThresholdHrs: 1,
@@ -53,7 +53,9 @@ func TestEnsureSecret(t *testing.T) {
5353
IncludeAuditLogsWithMongoDBLogs: false,
5454
},
5555
PercentOfDiskspace: "1",
56-
})
56+
}
57+
p.SetLogRotate(lr)
58+
p.SetAuditLogRotate(lr)
5759
}).Build()
5860
assert.NoError(t, err)
5961

@@ -72,7 +74,9 @@ func TestEnsureSecret(t *testing.T) {
7274
acFromBytes, err := FromBytes(bytes)
7375
assert.NoError(t, err)
7476
assert.Equal(t, 0.001, acFromBytes.Processes[0].LogRotate.SizeThresholdMB)
77+
assert.Equal(t, 0.001, acFromBytes.Processes[0].AuditLogRotate.SizeThresholdMB)
7578
assert.Equal(t, float64(1), acFromBytes.Processes[0].LogRotate.PercentOfDiskspace)
79+
assert.Equal(t, float64(1), acFromBytes.Processes[0].AuditLogRotate.PercentOfDiskspace)
7680
})
7781

7882
t.Run("test LogRotate marshal and unmarshal if not set", func(t *testing.T) {

0 commit comments

Comments
 (0)