Skip to content

Commit 16aa87e

Browse files
authored
CLOUDP-127672 - add logRotate support for automation (#1363)
1 parent 10fc2b0 commit 16aa87e

17 files changed

+359
-32
lines changed

api/v1/mongodbcommunity_types.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ type MongoDBCommunitySpec struct {
130130
AdditionalConnectionStringConfig MapWrapper `json:"additionalConnectionStringConfig,omitempty"`
131131
}
132132

133-
// Wrapper for a map to be used by other structs.
133+
// MapWrapper is a wrapper for a map to be used by other structs.
134134
// The CRD generator does not support map[string]interface{}
135135
// on the top level and hence we need to work around this with
136136
// a wrapping struct.
@@ -327,8 +327,9 @@ type AutomationConfigOverride struct {
327327

328328
// OverrideProcess contains fields that we can override on the AutomationConfig processes.
329329
type OverrideProcess struct {
330-
Name string `json:"name"`
331-
Disabled bool `json:"disabled"`
330+
Name string `json:"name"`
331+
Disabled bool `json:"disabled"`
332+
LogRotate *automationconfig.CrdLogRotate `json:"logRotate,omitempty"`
332333
}
333334

334335
// StatefulSetConfiguration holds the optional custom StatefulSet
@@ -355,6 +356,12 @@ type AgentConfiguration struct {
355356
LogLevel LogLevel `json:"logLevel"`
356357
// +optional
357358
MaxLogFileDurationHours int `json:"maxLogFileDurationHours"`
359+
// +optional
360+
// LogRotate if enabled, will enable LogRotate for all processes.
361+
LogRotate *automationconfig.CrdLogRotate `json:"logRotate,omitempty"`
362+
// +optional
363+
// SystemLog configures system log of mongod
364+
SystemLog *automationconfig.SystemLog `json:"systemLog,omitempty"`
358365
}
359366

360367
// StatefulSetSpecWrapper is a wrapper around StatefulSetSpec with a custom implementation

api/v1/zz_generated.deepcopy.go

Lines changed: 19 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/mongodbcommunity.mongodb.com_mongodbcommunity.yaml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,54 @@ spec:
7171
properties:
7272
logLevel:
7373
type: string
74+
logRotate:
75+
description: LogRotate if enabled, will enable LogRotate for all
76+
processes.
77+
properties:
78+
includeAuditLogsWithMongoDBLogs:
79+
description: set to 'true' to have the Automation Agent rotate
80+
the audit files along with mongodb log files
81+
type: boolean
82+
numTotal:
83+
description: maximum number of log files to have total
84+
type: integer
85+
numUncompressed:
86+
description: maximum number of log files to leave uncompressed
87+
type: integer
88+
percentOfDiskspace:
89+
description: Maximum percentage of the total disk space these
90+
log files should take up. The string needs to be able to
91+
be converted to float64
92+
type: string
93+
sizeThresholdMB:
94+
description: Maximum size for an individual log file before
95+
rotation. The string needs to be able to be converted to
96+
float64. Fractional values of MB are supported.
97+
type: string
98+
timeThresholdHrs:
99+
description: maximum hours for an individual log file before
100+
rotation
101+
type: integer
102+
required:
103+
- sizeThresholdMB
104+
- timeThresholdHrs
105+
type: object
74106
maxLogFileDurationHours:
75107
type: integer
108+
systemLog:
109+
description: SystemLog configures system log of mongod
110+
properties:
111+
destination:
112+
type: string
113+
logAppend:
114+
type: boolean
115+
path:
116+
type: string
117+
required:
118+
- destination
119+
- logAppend
120+
- path
121+
type: object
76122
type: object
77123
arbiters:
78124
description: 'Arbiters is the number of arbiters to add to the Replica
@@ -91,6 +137,40 @@ spec:
91137
properties:
92138
disabled:
93139
type: boolean
140+
logRotate:
141+
description: CrdLogRotate is the crd definition of LogRotate
142+
including fields in strings while the agent supports them
143+
as float64
144+
properties:
145+
includeAuditLogsWithMongoDBLogs:
146+
description: set to 'true' to have the Automation Agent
147+
rotate the audit files along with mongodb log files
148+
type: boolean
149+
numTotal:
150+
description: maximum number of log files to have total
151+
type: integer
152+
numUncompressed:
153+
description: maximum number of log files to leave uncompressed
154+
type: integer
155+
percentOfDiskspace:
156+
description: Maximum percentage of the total disk space
157+
these log files should take up. The string needs to
158+
be able to be converted to float64
159+
type: string
160+
sizeThresholdMB:
161+
description: Maximum size for an individual log file
162+
before rotation. The string needs to be able to be
163+
converted to float64. Fractional values of MB are
164+
supported.
165+
type: string
166+
timeThresholdHrs:
167+
description: maximum hours for an individual log file
168+
before rotation
169+
type: integer
170+
required:
171+
- sizeThresholdMB
172+
- timeThresholdHrs
173+
type: object
94174
name:
95175
type: string
96176
required:

controllers/mongodb_tls_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,17 @@ func TestAutomationConfigIsCorrectlyConfiguredWithTLS(t *testing.T) {
318318
}
319319
})
320320

321+
t.Run("With logRotate and SystemLog enabled", func(t *testing.T) {
322+
mdb := newTestReplicaSetWithSystemLogAndLogRotate()
323+
ac := createAC(mdb)
324+
325+
for _, process := range ac.Processes {
326+
assert.Equal(t, "/tmp/test", process.Args26.Get("systemLog.path").String())
327+
assert.Equal(t, "file", process.Args26.Get("systemLog.destination").String())
328+
assert.Equal(t, process.LogRotate, automationconfig.ConvertCrdLogRotateToAC(mdb.Spec.AgentConfiguration.LogRotate))
329+
}
330+
})
331+
321332
t.Run("With TLS enabled and required, rollout completed", func(t *testing.T) {
322333
mdb := newTestReplicaSetWithTLS()
323334
ac := createAC(mdb)

controllers/replica_set_controller.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,9 @@ func buildAutomationConfig(mdb mdbv1.MongoDBCommunity, auth automationconfig.Aut
557557
SetDataDir(mdb.GetMongodConfiguration().GetDBDataDir()).
558558
AddModifications(getMongodConfigModification(mdb)).
559559
AddModifications(modifications...).
560+
AddProcessModification(func(_ int, p *automationconfig.Process) {
561+
automationconfig.ConfigureAgentConfiguration(mdb.Spec.AgentConfiguration.SystemLog, mdb.Spec.AgentConfiguration.LogRotate, p)
562+
}).
560563
Build()
561564
}
562565

@@ -703,24 +706,25 @@ func (r ReplicaSetReconciler) buildAutomationConfig(mdb mdbv1.MongoDBCommunity)
703706
}
704707

705708
if mdb.Spec.AutomationConfigOverride != nil {
706-
automationConfig = merge.AutomationConfigs(automationConfig, overrideToAutomationConfig(*mdb.Spec.AutomationConfigOverride))
709+
automationConfig = merge.AutomationConfigs(automationConfig, OverrideToAutomationConfig(*mdb.Spec.AutomationConfigOverride))
707710
}
708711

709712
return automationConfig, nil
710713
}
711714

712-
// overrideToAutomationConfig turns an automation config override from the resource spec into an automation config
715+
// OverrideToAutomationConfig turns an automation config override from the resource spec into an automation config
713716
// which can be used to merge.
714-
func overrideToAutomationConfig(override mdbv1.AutomationConfigOverride) automationconfig.AutomationConfig {
717+
func OverrideToAutomationConfig(override mdbv1.AutomationConfigOverride) automationconfig.AutomationConfig {
715718
var processes []automationconfig.Process
716-
for _, p := range override.Processes {
717-
processes = append(processes, automationconfig.Process{
718-
Name: p.Name,
719-
Disabled: p.Disabled,
720-
})
719+
for _, o := range override.Processes {
720+
p := automationconfig.Process{
721+
Name: o.Name,
722+
Disabled: o.Disabled,
723+
LogRotate: automationconfig.ConvertCrdLogRotateToAC(o.LogRotate),
724+
}
725+
processes = append(processes, p)
721726
}
722727

723-
// TODO: currently we are just merging processes. Other fields can be added here.
724728
return automationconfig.AutomationConfig{
725729
Processes: processes,
726730
}

controllers/replicaset_controller_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,34 @@ func newTestReplicaSet() mdbv1.MongoDBCommunity {
6868
}
6969
}
7070

71+
func newTestReplicaSetWithSystemLogAndLogRotate() mdbv1.MongoDBCommunity {
72+
return mdbv1.MongoDBCommunity{
73+
ObjectMeta: metav1.ObjectMeta{
74+
Name: "my-rs",
75+
Namespace: "my-ns",
76+
Annotations: map[string]string{},
77+
},
78+
Spec: mdbv1.MongoDBCommunitySpec{
79+
Members: 3,
80+
Version: "6.0.5",
81+
Security: mdbv1.Security{
82+
Authentication: mdbv1.Authentication{
83+
Modes: []mdbv1.AuthMode{"SCRAM"},
84+
},
85+
},
86+
AgentConfiguration: mdbv1.AgentConfiguration{
87+
LogRotate: &automationconfig.CrdLogRotate{
88+
SizeThresholdMB: "1",
89+
},
90+
SystemLog: &automationconfig.SystemLog{
91+
Destination: automationconfig.File,
92+
Path: "/tmp/test",
93+
},
94+
},
95+
},
96+
}
97+
}
98+
7199
func newScramReplicaSet(users ...mdbv1.MongoDBUser) mdbv1.MongoDBCommunity {
72100
return mdbv1.MongoDBCommunity{
73101
ObjectMeta: metav1.ObjectMeta{

docs/RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
- For these users, `scramCredentialsSecretName` and `passwordSecretRef` should **not** be set.
1414
- Sample resource [yaml](config/samples/mongodb.com_v1_mongodbcommunity_x509.yaml)
1515
- Sample agent certificate [yaml](config/samples/external_access/agent-certificate.yaml)
16+
- Add support for configuring [logRotate](https://www.mongodb.com/docs/ops-manager/current/reference/cluster-configuration/#mongodb-instances) on the automation-agent. The settings can be found under `processes[n].logRotate.<setting>`.
17+
- Additionally, [systemLog](https://www.mongodb.com/docs/manual/reference/configuration-options/#systemlog-options) can now be configured. In particular the settings: `path`, `destination` and `logAppend`.
1618

1719
# MongoDB Kubernetes Operator 0.8.2
1820

0 commit comments

Comments
 (0)