-
Notifications
You must be signed in to change notification settings - Fork 637
Rotate pgbackrest #4108
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
Rotate pgbackrest #4108
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,10 +27,13 @@ func NewConfigForPostgresPod(ctx context.Context, | |
| ) *Config { | ||
| config := NewConfig(inCluster.Spec.Instrumentation) | ||
|
|
||
| // Metrics | ||
| EnablePostgresMetrics(ctx, inCluster, config) | ||
| EnablePatroniMetrics(ctx, inCluster, config) | ||
| EnablePatroniLogging(ctx, inCluster, config) | ||
|
|
||
| // Logging | ||
| EnablePostgresLogging(ctx, inCluster, config, outParameters) | ||
| EnablePatroniLogging(ctx, inCluster, config) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just re-ordering and grouping |
||
|
|
||
| return config | ||
| } | ||
|
|
@@ -229,10 +232,9 @@ func EnablePostgresLogging( | |
| } | ||
|
|
||
| // pgBackRest pipeline | ||
| // TODO(log-rotation): Create this directory during Collector startup. | ||
| outConfig.Extensions["file_storage/pgbackrest_logs"] = map[string]any{ | ||
| "directory": naming.PGBackRestPGDataLogPath + "/receiver", | ||
| "create_directory": true, | ||
| "create_directory": false, | ||
| "fsync": true, | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ import ( | |
|
|
||
| "github.com/crunchydata/postgres-operator/internal/collector" | ||
| "github.com/crunchydata/postgres-operator/internal/config" | ||
| "github.com/crunchydata/postgres-operator/internal/feature" | ||
| "github.com/crunchydata/postgres-operator/internal/initialize" | ||
| "github.com/crunchydata/postgres-operator/internal/naming" | ||
| "github.com/crunchydata/postgres-operator/internal/postgres" | ||
|
|
@@ -129,11 +130,32 @@ func CreatePGBackRestConfigMapIntent(ctx context.Context, postgresCluster *v1bet | |
| postgresCluster.Spec.Backups.PGBackRest.Global, | ||
| ).String() | ||
|
|
||
| err = collector.AddToConfigMap(ctx, collector.NewConfigForPgBackrestRepoHostPod( | ||
| ctx, | ||
| postgresCluster.Spec.Instrumentation, | ||
| postgresCluster.Spec.Backups.PGBackRest.Repos, | ||
| ), cm) | ||
| if RepoHostVolumeDefined(postgresCluster) && | ||
| (feature.Enabled(ctx, feature.OpenTelemetryLogs) || | ||
| feature.Enabled(ctx, feature.OpenTelemetryMetrics)) { | ||
| err = collector.AddToConfigMap(ctx, collector.NewConfigForPgBackrestRepoHostPod( | ||
| ctx, | ||
| postgresCluster.Spec.Instrumentation, | ||
| postgresCluster.Spec.Backups.PGBackRest.Repos, | ||
| ), cm) | ||
|
|
||
| // If OTel logging is enabled, add logrotate config for the RepoHost | ||
| if err == nil && | ||
| postgresCluster.Spec.Instrumentation != nil && | ||
| feature.Enabled(ctx, feature.OpenTelemetryLogs) { | ||
| var pgBackRestLogPath string | ||
| for _, repo := range postgresCluster.Spec.Backups.PGBackRest.Repos { | ||
| if repo.Volume != nil { | ||
| pgBackRestLogPath = fmt.Sprintf(naming.PGBackRestRepoLogPath, repo.Name) | ||
| break | ||
| } | ||
| } | ||
|
|
||
| collector.AddLogrotateConfigs(ctx, postgresCluster.Spec.Instrumentation, cm, []collector.LogrotateConfig{{ | ||
| LogFiles: []string{pgBackRestLogPath + "/*.log"}, | ||
| }}) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| cm.Data[ConfigHashKey] = configHash | ||
|
|
@@ -144,7 +166,7 @@ func CreatePGBackRestConfigMapIntent(ctx context.Context, postgresCluster *v1bet | |
| // MakePGBackrestLogDir creates the pgBackRest default log path directory used when a | ||
| // dedicated repo host is configured. | ||
| func MakePGBackrestLogDir(template *corev1.PodTemplateSpec, | ||
| cluster *v1beta1.PostgresCluster) { | ||
| cluster *v1beta1.PostgresCluster) string { | ||
|
|
||
| var pgBackRestLogPath string | ||
| for _, repo := range cluster.Spec.Backups.PGBackRest.Repos { | ||
|
|
@@ -172,6 +194,8 @@ func MakePGBackrestLogDir(template *corev1.PodTemplateSpec, | |
| } | ||
| } | ||
| template.Spec.InitContainers = append(template.Spec.InitContainers, container) | ||
|
|
||
| return pgBackRestLogPath | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got tired of looping through repos to get this name, so I had this func return it since I needed this name right after this func was called. I could've done that work outside this func or create a util, maybe I'll consider that tomorrow. |
||
| } | ||
|
|
||
| // RestoreCommand returns the command for performing a pgBackRest restore. In addition to calling | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we want to require the instrumentation spec, then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, just like you said at another point: this is all feature gated, but turning on a feature gate doesn't necessarily mean you want X feature for all your clusters.