Skip to content

Commit 22ca36f

Browse files
Merge pull request #762 from cybozu-go/add-log-rotation-size
Add log-rotation-size
2 parents 13895b1 + b4bc8a8 commit 22ca36f

10 files changed

+42
-3
lines changed

api/v1beta2/mysqlcluster_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ type MySQLClusterSpec struct {
109109
// +optional
110110
LogRotationSchedule string `json:"logRotationSchedule,omitempty"`
111111

112+
// LogRotationSize specifies the size to rotate MySQL logs
113+
// If not set, size-based log rotation is disabled by default
114+
// +optional
115+
LogRotationSize int `json:"logRotationSize,omitempty"`
116+
112117
// The name of BackupPolicy custom resource in the same namespace.
113118
// If this is set, MOCO creates a CronJob to take backup of this MySQL cluster periodically.
114119
// +nullable
@@ -171,6 +176,11 @@ func (s MySQLClusterSpec) validateCreate() (admission.Warnings, field.ErrorList)
171176
}
172177
}
173178

179+
pp = p.Child("logRotationSize")
180+
if s.LogRotationSize < 0 {
181+
allErrs = append(allErrs, field.Invalid(pp, s.LogRotationSize, "logRotationSize must be a positve integer or zero"))
182+
}
183+
174184
pp = p.Child("replicas")
175185
if s.Replicas%2 == 0 {
176186
allErrs = append(allErrs, field.Invalid(pp, s.Replicas, "replicas must be a positive odd number"))

api/v1beta2/mysqlcluster_webhook_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,20 @@ var _ = Describe("MySQLCluster Webhook", func() {
158158
Expect(err).To(HaveOccurred())
159159
})
160160

161+
It("should allow a valid logRotationSize", func() {
162+
r := makeMySQLCluster()
163+
r.Spec.LogRotationSize = 1024
164+
err := k8sClient.Create(ctx, r)
165+
Expect(err).NotTo(HaveOccurred())
166+
})
167+
168+
It("should deny an invalid logRotationSize", func() {
169+
r := makeMySQLCluster()
170+
r.Spec.LogRotationSize = -1
171+
err := k8sClient.Create(ctx, r)
172+
Expect(err).To(HaveOccurred())
173+
})
174+
161175
It("should deny without mysqld container", func() {
162176
r := makeMySQLCluster()
163177
r.Spec.PodTemplate.Spec.Containers = nil

charts/moco/templates/generated/crds/moco_crds.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,6 +2256,9 @@ spec:
22562256
logRotationSchedule:
22572257
description: LogRotationSchedule specifies the schedule to rota
22582258
type: string
2259+
logRotationSize:
2260+
description: LogRotationSize specifies the size to rotate MySQL
2261+
type: integer
22592262
maxDelaySeconds:
22602263
default: 60
22612264
description: 'MaxDelaySeconds configures the readiness probe of '

config/crd/bases/moco.cybozu.com_mysqlclusters.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ spec:
7373
logRotationSchedule:
7474
description: LogRotationSchedule specifies the schedule to rota
7575
type: string
76+
logRotationSize:
77+
description: LogRotationSize specifies the size to rotate MySQL
78+
type: integer
7679
maxDelaySeconds:
7780
default: 60
7881
description: 'MaxDelaySeconds configures the readiness probe of '

config/crd/tests/apiextensions.k8s.io_v1_customresourcedefinition_mysqlclusters.moco.cybozu.com.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ spec:
7373
logRotationSchedule:
7474
description: LogRotationSchedule specifies the schedule to rota
7575
type: string
76+
logRotationSize:
77+
description: LogRotationSize specifies the size to rotate MySQL
78+
type: integer
7679
maxDelaySeconds:
7780
default: 60
7881
description: 'MaxDelaySeconds configures the readiness probe of '

controllers/mysql_container.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ func (r *MySQLClusterReconciler) makeV1AgentContainer(cluster *mocov1beta2.MySQL
134134
if cluster.Spec.LogRotationSchedule != "" {
135135
c.WithArgs("--log-rotation-schedule", cluster.Spec.LogRotationSchedule)
136136
}
137+
if cluster.Spec.LogRotationSize > 0 {
138+
c.WithArgs("--log-rotation-size", fmt.Sprintf("%d", cluster.Spec.LogRotationSize))
139+
}
137140

138141
if cluster.Spec.AgentUseLocalhost {
139142
c.WithArgs(constants.MocoMySQLDLocalhostFlag, strconv.FormatBool(cluster.Spec.AgentUseLocalhost))

controllers/mysqlcluster_controller_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,7 @@ var _ = Describe("MySQLCluster reconciler", func() {
10431043
cluster.Spec.MaxDelaySeconds = ptr.To[int](20)
10441044
cluster.Spec.StartupWaitSeconds = 3
10451045
cluster.Spec.LogRotationSchedule = "0 * * * *"
1046+
cluster.Spec.LogRotationSize = 1024
10461047
cluster.Spec.AgentUseLocalhost = true
10471048
cluster.Spec.DisableSlowQueryLogContainer = true
10481049
cluster.Spec.PodTemplate.OverwriteContainers = []mocov1beta2.OverwriteContainer{
@@ -1171,6 +1172,7 @@ var _ = Describe("MySQLCluster reconciler", func() {
11711172
case constants.AgentContainerName:
11721173
Expect(c.Args).To(ContainElement("20s"))
11731174
Expect(c.Args).To(ContainElement("0 * * * *"))
1175+
Expect(c.Args).To(ContainElement("1024"))
11741176
Expect(c.Args).To(ContainElements("--mysqld-localhost", "true"))
11751177
Expect(c.Resources.Requests).To(Equal(corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("100m")}))
11761178
Expect(c.Resources.Limits).To(Equal(corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("100m")}))

docs/crd_mysqlcluster_v1beta2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ MySQLClusterSpec defines the desired state of MySQLCluster
8181
| maxDelaySecondsForPodDeletion | MaxDelaySecondsForPodDeletion configures the maximum allowed replication delay before a Pod deletion is blocked. If the replication delay exceeds this threshold, deletion of the primary pod will be prevented. The default is 0 seconds. Setting this field to 0 disables the delay check for pod deletion. | int64 | false |
8282
| startupWaitSeconds | StartupWaitSeconds is the maximum duration to wait for `mysqld` container to start working. The default is 3600 seconds. | int32 | false |
8383
| logRotationSchedule | LogRotationSchedule specifies the schedule to rotate MySQL logs. If not set, the default is to rotate logs every 5 minutes. See https://pkg.go.dev/github.com/robfig/cron/v3#hdr-CRON_Expression_Format for the field format. | string | false |
84+
| logRotationSize | LogRotationSize specifies the size to rotate MySQL logs If not set, size-based log rotation is disabled by default | int | false |
8485
| backupPolicyName | The name of BackupPolicy custom resource in the same namespace. If this is set, MOCO creates a CronJob to take backup of this MySQL cluster periodically. | *string | false |
8586
| restore | Restore is the specification to perform Point-in-Time-Recovery from existing cluster. If this field is not null, MOCO restores the data as specified and create a new cluster with the data. This field is not editable. | *[RestoreSpec](#restorespec) | false |
8687
| disableSlowQueryLogContainer | DisableSlowQueryLogContainer controls whether to add a sidecar container named \"slow-log\" to output slow logs as the containers output. If set to true, the sidecar container is not added. The default is false. | bool | false |

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.18
1111
github.com/aws/aws-sdk-go-v2/service/s3 v1.61.2
1212
// Do not update moco-agent until changes that will cause StatefulSet to restart are made.
13-
github.com/cybozu-go/moco-agent v0.12.1
13+
github.com/cybozu-go/moco-agent v0.13.0
1414
github.com/go-logr/logr v1.4.2
1515
github.com/go-logr/stdr v1.2.2
1616
github.com/go-sql-driver/mysql v1.8.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
7878
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
7979
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
8080
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
81-
github.com/cybozu-go/moco-agent v0.12.1 h1:Wp3S5whb9b3nD4cNvtJohJ/yBu6TtE7X3Md7WSIK/fw=
82-
github.com/cybozu-go/moco-agent v0.12.1/go.mod h1:qea2oTno2dEpLLHHi/GiY8T0x+Aw6373aGbfk0fA5Bc=
81+
github.com/cybozu-go/moco-agent v0.13.0 h1:74S52H9VhJ1ZnZyB4wPL+PIPRTMS1vjPBmbGtgCrapo=
82+
github.com/cybozu-go/moco-agent v0.13.0/go.mod h1:47vPiMsxKFf0spqts4z1AWKTRIbqAwVOtPcA6q+39zI=
8383
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8484
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8585
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=

0 commit comments

Comments
 (0)