Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log-rotation-size #762

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions api/v1beta2/mysqlcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ type MySQLClusterSpec struct {
// +optional
LogRotationSchedule string `json:"logRotationSchedule,omitempty"`

// LogRotationSize specifies the size to rotate MySQL logs
// If not set, size-based log rotation is disabled by default
// +optional
LogRotationSize int `json:"logRotationSize,omitempty"`

// 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.
// +nullable
Expand Down Expand Up @@ -171,6 +176,11 @@ func (s MySQLClusterSpec) validateCreate() (admission.Warnings, field.ErrorList)
}
}

pp = p.Child("logRotationSize")
if s.LogRotationSize < 0 {
allErrs = append(allErrs, field.Invalid(pp, s.LogRotationSize, "logRotationSize must be a positve integer or zero"))
}

pp = p.Child("replicas")
if s.Replicas%2 == 0 {
allErrs = append(allErrs, field.Invalid(pp, s.Replicas, "replicas must be a positive odd number"))
Expand Down
7 changes: 7 additions & 0 deletions api/v1beta2/mysqlcluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ var _ = Describe("MySQLCluster Webhook", func() {
Expect(err).NotTo(HaveOccurred())
})

It("should allow a valid logRotationSize", func() {
r := makeMySQLCluster()
r.Spec.LogRotationSize = 1024
err := k8sClient.Create(ctx, r)
Expect(err).NotTo(HaveOccurred())
})

shunki-fujita marked this conversation as resolved.
Show resolved Hide resolved
It("should deny an invalid logRotationSchedule", func() {
r := makeMySQLCluster()
r.Spec.LogRotationSchedule = "hoge fuga"
Expand Down
3 changes: 3 additions & 0 deletions charts/moco/templates/generated/crds/moco_crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2256,6 +2256,9 @@ spec:
logRotationSchedule:
description: LogRotationSchedule specifies the schedule to rota
type: string
logRotationSize:
description: LogRotationSize specifies the size to rotate MySQL
type: integer
maxDelaySeconds:
default: 60
description: 'MaxDelaySeconds configures the readiness probe of '
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/moco.cybozu.com_mysqlclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ spec:
logRotationSchedule:
description: LogRotationSchedule specifies the schedule to rota
type: string
logRotationSize:
description: LogRotationSize specifies the size to rotate MySQL
type: integer
maxDelaySeconds:
default: 60
description: 'MaxDelaySeconds configures the readiness probe of '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ spec:
logRotationSchedule:
description: LogRotationSchedule specifies the schedule to rota
type: string
logRotationSize:
description: LogRotationSize specifies the size to rotate MySQL
type: integer
maxDelaySeconds:
default: 60
description: 'MaxDelaySeconds configures the readiness probe of '
Expand Down
3 changes: 3 additions & 0 deletions controllers/mysql_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ func (r *MySQLClusterReconciler) makeV1AgentContainer(cluster *mocov1beta2.MySQL
if cluster.Spec.LogRotationSchedule != "" {
c.WithArgs("--log-rotation-schedule", cluster.Spec.LogRotationSchedule)
}
if cluster.Spec.LogRotationSize > 0 {
c.WithArgs("--log-rotation-size", fmt.Sprintf("%d", cluster.Spec.LogRotationSize))
}

if cluster.Spec.AgentUseLocalhost {
c.WithArgs(constants.MocoMySQLDLocalhostFlag, strconv.FormatBool(cluster.Spec.AgentUseLocalhost))
Expand Down
2 changes: 2 additions & 0 deletions controllers/mysqlcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,7 @@ var _ = Describe("MySQLCluster reconciler", func() {
cluster.Spec.MaxDelaySeconds = ptr.To[int](20)
cluster.Spec.StartupWaitSeconds = 3
cluster.Spec.LogRotationSchedule = "0 * * * *"
cluster.Spec.LogRotationSize = 1024
cluster.Spec.AgentUseLocalhost = true
cluster.Spec.DisableSlowQueryLogContainer = true
cluster.Spec.PodTemplate.OverwriteContainers = []mocov1beta2.OverwriteContainer{
Expand Down Expand Up @@ -1171,6 +1172,7 @@ var _ = Describe("MySQLCluster reconciler", func() {
case constants.AgentContainerName:
Expect(c.Args).To(ContainElement("20s"))
Expect(c.Args).To(ContainElement("0 * * * *"))
Expect(c.Args).To(ContainElement("1024"))
Expect(c.Args).To(ContainElements("--mysqld-localhost", "true"))
Expect(c.Resources.Requests).To(Equal(corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("100m")}))
Expect(c.Resources.Limits).To(Equal(corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("100m")}))
Expand Down
1 change: 1 addition & 0 deletions docs/crd_mysqlcluster_v1beta2.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ MySQLClusterSpec defines the desired state of MySQLCluster
| 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 |
| startupWaitSeconds | StartupWaitSeconds is the maximum duration to wait for `mysqld` container to start working. The default is 3600 seconds. | int32 | false |
| 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 |
| logRotationSize | LogRotationSize specifies the size to rotate MySQL logs If not set, size-based log rotation is disabled by default | int | false |
| 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 |
| 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 |
| 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 |
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.18
github.com/aws/aws-sdk-go-v2/service/s3 v1.61.2
// Do not update moco-agent until changes that will cause StatefulSet to restart are made.
github.com/cybozu-go/moco-agent v0.12.1
github.com/cybozu-go/moco-agent v0.13.0
github.com/go-logr/logr v1.4.2
github.com/go-logr/stdr v1.2.2
github.com/go-sql-driver/mysql v1.8.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/cybozu-go/moco-agent v0.12.1 h1:Wp3S5whb9b3nD4cNvtJohJ/yBu6TtE7X3Md7WSIK/fw=
github.com/cybozu-go/moco-agent v0.12.1/go.mod h1:qea2oTno2dEpLLHHi/GiY8T0x+Aw6373aGbfk0fA5Bc=
github.com/cybozu-go/moco-agent v0.13.0 h1:74S52H9VhJ1ZnZyB4wPL+PIPRTMS1vjPBmbGtgCrapo=
github.com/cybozu-go/moco-agent v0.13.0/go.mod h1:47vPiMsxKFf0spqts4z1AWKTRIbqAwVOtPcA6q+39zI=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand Down