Skip to content

Commit

Permalink
Prepares exporter command for pg17 (#4004)
Browse files Browse the repository at this point in the history
Prepares exporter command for pg17
  • Loading branch information
tony-landreth authored Sep 26, 2024
1 parent 4d070ce commit 34a3eee
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
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

0 comments on commit 34a3eee

Please sign in to comment.