Skip to content

Commit 34a3eee

Browse files
Prepares exporter command for pg17 (#4004)
Prepares exporter command for pg17
1 parent 4d070ce commit 34a3eee

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

internal/controller/postgrescluster/pgmonitor.go

+22-3
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,34 @@ func addPGMonitorExporterToInstancePodSpec(
259259
withBuiltInCollectors :=
260260
!strings.EqualFold(cluster.Annotations[naming.PostgresExporterCollectorsAnnotation], "None")
261261

262+
var cmd []string
263+
// PG 17 does not include some of the columns found in stat_bgwriter with older PGs.
264+
// Selectively turn off the collector for stat_bgwriter in PG 17, unless the user
265+
// requests all collectors to be turned off.
266+
switch {
267+
case cluster.Spec.PostgresVersion == 17 && withBuiltInCollectors && certSecret == nil:
268+
cmd = pgmonitor.ExporterStartCommand(withBuiltInCollectors,
269+
pgmonitor.ExporterDeactivateStatBGWriterFlag)
270+
case cluster.Spec.PostgresVersion == 17 && withBuiltInCollectors && certSecret != nil:
271+
cmd = pgmonitor.ExporterStartCommand(withBuiltInCollectors,
272+
pgmonitor.ExporterWebConfigFileFlag,
273+
pgmonitor.ExporterDeactivateStatBGWriterFlag)
274+
// If you're turning off all built-in collectors, we don't care which
275+
// version of PG you're using.
276+
case certSecret != nil:
277+
cmd = pgmonitor.ExporterStartCommand(withBuiltInCollectors,
278+
pgmonitor.ExporterWebConfigFileFlag)
279+
default:
280+
cmd = pgmonitor.ExporterStartCommand(withBuiltInCollectors)
281+
}
282+
262283
securityContext := initialize.RestrictedSecurityContext()
263284
exporterContainer := corev1.Container{
264285
Name: naming.ContainerPGMonitorExporter,
265286
Image: config.PGExporterContainerImage(cluster),
266287
ImagePullPolicy: cluster.Spec.ImagePullPolicy,
267288
Resources: cluster.Spec.Monitoring.PGMonitor.Exporter.Resources,
268-
Command: pgmonitor.ExporterStartCommand(withBuiltInCollectors),
289+
Command: cmd,
269290
Env: []corev1.EnvVar{
270291
{Name: "DATA_SOURCE_URI", Value: fmt.Sprintf("%s:%d/%s", pgmonitor.ExporterHost, *cluster.Spec.Port, pgmonitor.ExporterDB)},
271292
{Name: "DATA_SOURCE_USER", Value: pgmonitor.MonitoringUser},
@@ -357,8 +378,6 @@ func addPGMonitorExporterToInstancePodSpec(
357378
}}
358379

359380
exporterContainer.VolumeMounts = append(exporterContainer.VolumeMounts, mounts...)
360-
exporterContainer.Command = pgmonitor.ExporterStartCommand(
361-
withBuiltInCollectors, pgmonitor.ExporterWebConfigFileFlag)
362381
}
363382

364383
template.Spec.Containers = append(template.Spec.Containers, exporterContainer)

internal/pgmonitor/exporter.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const (
3232

3333
// postgres_exporter command flags
3434
var (
35-
ExporterWebConfigFileFlag = "--web.config.file=/web-config/web-config.yml"
35+
ExporterWebConfigFileFlag = "--web.config.file=/web-config/web-config.yml"
36+
ExporterDeactivateStatBGWriterFlag = "--no-collector.stat_bgwriter"
3637
)
3738

3839
// Defaults for certain values used in queries.yml

0 commit comments

Comments
 (0)