Skip to content

Prepares exporter command for pg17 #4004

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 22 additions & 3 deletions internal/controller/postgrescluster/pgmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,34 @@ func addPGMonitorExporterToInstancePodSpec(
withBuiltInCollectors :=
!strings.EqualFold(cluster.Annotations[naming.PostgresExporterCollectorsAnnotation], "None")

var cmd []string
// PG 17 does not include some of the columns found in stat_bgwriter with older PGs.
// Selectively turn off the collector for stat_bgwriter in PG 17, unless the user
// requests all collectors to be turned off.
switch {
case cluster.Spec.PostgresVersion == 17 && withBuiltInCollectors && certSecret == nil:
cmd = pgmonitor.ExporterStartCommand(withBuiltInCollectors,
pgmonitor.ExporterDeactivateStatBGWriterFlag)
case cluster.Spec.PostgresVersion == 17 && withBuiltInCollectors && certSecret != nil:
cmd = pgmonitor.ExporterStartCommand(withBuiltInCollectors,
pgmonitor.ExporterWebConfigFileFlag,
pgmonitor.ExporterDeactivateStatBGWriterFlag)
// If you're turning off all built-in collectors, we don't care which
// version of PG you're using.
case certSecret != nil:
cmd = pgmonitor.ExporterStartCommand(withBuiltInCollectors,
pgmonitor.ExporterWebConfigFileFlag)
default:
cmd = pgmonitor.ExporterStartCommand(withBuiltInCollectors)
}

securityContext := initialize.RestrictedSecurityContext()
exporterContainer := corev1.Container{
Name: naming.ContainerPGMonitorExporter,
Image: config.PGExporterContainerImage(cluster),
ImagePullPolicy: cluster.Spec.ImagePullPolicy,
Resources: cluster.Spec.Monitoring.PGMonitor.Exporter.Resources,
Command: pgmonitor.ExporterStartCommand(withBuiltInCollectors),
Command: cmd,
Env: []corev1.EnvVar{
{Name: "DATA_SOURCE_URI", Value: fmt.Sprintf("%s:%d/%s", pgmonitor.ExporterHost, *cluster.Spec.Port, pgmonitor.ExporterDB)},
{Name: "DATA_SOURCE_USER", Value: pgmonitor.MonitoringUser},
Expand Down Expand Up @@ -357,8 +378,6 @@ func addPGMonitorExporterToInstancePodSpec(
}}

exporterContainer.VolumeMounts = append(exporterContainer.VolumeMounts, mounts...)
exporterContainer.Command = pgmonitor.ExporterStartCommand(
withBuiltInCollectors, pgmonitor.ExporterWebConfigFileFlag)
}

template.Spec.Containers = append(template.Spec.Containers, exporterContainer)
Expand Down
3 changes: 2 additions & 1 deletion internal/pgmonitor/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const (

// postgres_exporter command flags
var (
ExporterWebConfigFileFlag = "--web.config.file=/web-config/web-config.yml"
ExporterWebConfigFileFlag = "--web.config.file=/web-config/web-config.yml"
ExporterDeactivateStatBGWriterFlag = "--no-collector.stat_bgwriter"
)

// Defaults for certain values used in queries.yml
Expand Down
Loading