diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index a9767daeae..ae34bfc348 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -64,9 +64,9 @@ jobs: with: k3s-channel: "${{ matrix.kubernetes }}" prefetch-images: | - registry.developers.crunchydata.com/crunchydata/crunchy-pgbackrest:ubi9-2.56.0-2534 - registry.developers.crunchydata.com/crunchydata/crunchy-pgbouncer:ubi9-1.24-2534 - registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-16.10-2534 + registry.developers.crunchydata.com/crunchydata/crunchy-pgbackrest:ubi9-2.56.0-2542 + registry.developers.crunchydata.com/crunchydata/crunchy-pgbouncer:ubi9-1.24-2542 + registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-16.10-2542 - run: make createnamespaces check-envtest-existing env: @@ -98,16 +98,19 @@ jobs: with: k3s-channel: "${{ matrix.kubernetes }}" prefetch-images: | - registry.developers.crunchydata.com/crunchydata/crunchy-pgbackrest:ubi9-2.56.0-2534 - registry.developers.crunchydata.com/crunchydata/crunchy-pgbouncer:ubi9-1.24-2534 - registry.developers.crunchydata.com/crunchydata/crunchy-postgres-exporter:ubi9-0.17.1-2534 - registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-17.6-2534 - registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-16.10-2534 - registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-16.10-3.3-2534 - registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-16.10-3.4-2534 - registry.developers.crunchydata.com/crunchydata/crunchy-upgrade:ubi9-17.6-2534 - registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-17.6-3.4-2534 - registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-17.6-3.5-2534 + registry.developers.crunchydata.com/crunchydata/crunchy-pgbackrest:ubi9-2.56.0-2542 + registry.developers.crunchydata.com/crunchydata/crunchy-pgbouncer:ubi9-1.24-2542 + registry.developers.crunchydata.com/crunchydata/crunchy-postgres-exporter:ubi9-0.17.1-2542 + registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-17.6-2542 + registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-16.10-2542 + registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-16.10-3.3-2542 + registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-16.10-3.4-2542 + registry.developers.crunchydata.com/crunchydata/crunchy-upgrade:ubi9-18.0-2542 + registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-17.6-3.4-2542 + registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-17.6-3.5-2542 + registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-17.6-3.6-2542 + registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-18.0-2542 + registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-18.0-3.6-2542 - name: Get pgMonitor files. run: make get-pgmonitor @@ -126,18 +129,21 @@ jobs: --volume "$(pwd):/mnt" --workdir '/mnt' \ --env 'QUERIES_CONFIG_DIR=/mnt/hack/tools/queries' \ --env 'KUBECONFIG=hack/.kube/postgres-operator/pgo' \ - --env 'RELATED_IMAGE_PGBACKREST=registry.developers.crunchydata.com/crunchydata/crunchy-pgbackrest:ubi9-2.56.0-2534' \ - --env 'RELATED_IMAGE_PGBOUNCER=registry.developers.crunchydata.com/crunchydata/crunchy-pgbouncer:ubi9-1.24-2534' \ - --env 'RELATED_IMAGE_PGEXPORTER=registry.developers.crunchydata.com/crunchydata/crunchy-postgres-exporter:ubi9-0.17.1-2534' \ - --env 'RELATED_IMAGE_PGUPGRADE=registry.developers.crunchydata.com/crunchydata/crunchy-upgrade:ubi9-17.6-2534' \ - --env 'RELATED_IMAGE_POSTGRES_16=registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-16.10-2534' \ - --env 'RELATED_IMAGE_POSTGRES_16_GIS_3.3=registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-16.10-3.3-2534' \ - --env 'RELATED_IMAGE_POSTGRES_16_GIS_3.4=registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-16.10-3.4-2534' \ - --env 'RELATED_IMAGE_POSTGRES_17=registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-17.6-2534' \ - --env 'RELATED_IMAGE_POSTGRES_17_GIS_3.4=registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-17.6-3.4-2534' \ - --env 'RELATED_IMAGE_POSTGRES_17_GIS_3.5=registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-17.6-3.5-2534' \ - --env 'RELATED_IMAGE_STANDALONE_PGADMIN=registry.developers.crunchydata.com/crunchydata/crunchy-pgadmin4:ubi9-9.2-2534' \ - --env 'RELATED_IMAGE_COLLECTOR=registry.developers.crunchydata.com/crunchydata/postgres-operator:ubi9-5.8.3-0' \ + --env 'RELATED_IMAGE_PGBACKREST=registry.developers.crunchydata.com/crunchydata/crunchy-pgbackrest:ubi9-2.56.0-2542' \ + --env 'RELATED_IMAGE_PGBOUNCER=registry.developers.crunchydata.com/crunchydata/crunchy-pgbouncer:ubi9-1.24-2542' \ + --env 'RELATED_IMAGE_PGEXPORTER=registry.developers.crunchydata.com/crunchydata/crunchy-postgres-exporter:ubi9-0.17.1-2542' \ + --env 'RELATED_IMAGE_PGUPGRADE=registry.developers.crunchydata.com/crunchydata/crunchy-upgrade:ubi9-18.0-2542' \ + --env 'RELATED_IMAGE_POSTGRES_16=registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-16.10-2542' \ + --env 'RELATED_IMAGE_POSTGRES_16_GIS_3.3=registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-16.10-3.3-2542' \ + --env 'RELATED_IMAGE_POSTGRES_16_GIS_3.4=registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-16.10-3.4-2542' \ + --env 'RELATED_IMAGE_POSTGRES_17=registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-17.6-2542' \ + --env 'RELATED_IMAGE_POSTGRES_17_GIS_3.4=registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-17.6-3.4-2542' \ + --env 'RELATED_IMAGE_POSTGRES_17_GIS_3.5=registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-17.6-3.5-2542' \ + --env 'RELATED_IMAGE_POSTGRES_17_GIS_3.6=registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-17.6-3.6-2542' \ + --env 'RELATED_IMAGE_POSTGRES_18=registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-18.0-2542' \ + --env 'RELATED_IMAGE_POSTGRES_18_GIS_3.6=registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-18.0-3.6-2542' \ + --env 'RELATED_IMAGE_STANDALONE_PGADMIN=registry.developers.crunchydata.com/crunchydata/crunchy-pgadmin4:ubi9-9.8-2542' \ + --env 'RELATED_IMAGE_COLLECTOR=registry.developers.crunchydata.com/crunchydata/postgres-operator:ubi9-5.8.4-0' \ --env 'PGO_FEATURE_GATES=TablespaceVolumes=true,OpenTelemetryLogs=true,OpenTelemetryMetrics=true' \ --name 'postgres-operator' localhost/postgres-operator @@ -153,7 +159,7 @@ jobs: KUTTL_PG_UPGRADE_TO_VERSION: '17' KUTTL_PG_VERSION: '16' KUTTL_POSTGIS_VERSION: '3.4' - KUTTL_PSQL_IMAGE: 'registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-16.10-2534' + KUTTL_PSQL_IMAGE: 'registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-16.10-2542' - run: | make check-kuttl && exit failed=$? diff --git a/Makefile b/Makefile index 793e806d77..aa6509f4cd 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ CONTROLLER ?= $(GO) tool sigs.k8s.io/controller-tools/cmd/controller-gen CHAINSAW ?= $(GO) run github.com/kyverno/chainsaw@latest CHAINSAW_TEST ?= $(CHAINSAW) test CRD_CHECKER ?= $(GO) run github.com/openshift/crd-schema-checker/cmd/crd-schema-checker@latest -ENVTEST ?= $(GO) run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest +ENVTEST ?= $(GO) run sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.22 KUTTL ?= $(GO) run github.com/kudobuilder/kuttl/cmd/kubectl-kuttl@latest KUTTL_TEST ?= $(KUTTL) test @@ -205,7 +205,7 @@ generate-kuttl: export KUTTL_PG_UPGRADE_FROM_VERSION ?= 16 generate-kuttl: export KUTTL_PG_UPGRADE_TO_VERSION ?= 17 generate-kuttl: export KUTTL_PG_VERSION ?= 16 generate-kuttl: export KUTTL_POSTGIS_VERSION ?= 3.4 -generate-kuttl: export KUTTL_PSQL_IMAGE ?= registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-17.6-2534 +generate-kuttl: export KUTTL_PSQL_IMAGE ?= registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-17.6-2542 generate-kuttl: export KUTTL_TEST_DELETE_NAMESPACE ?= kuttl-test-delete-namespace generate-kuttl: ## Generate kuttl tests [ ! -d testing/kuttl/e2e-generated ] || rm -r testing/kuttl/e2e-generated diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 75c3d4c521..0764e8d7cc 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -23,29 +23,35 @@ spec: - name: CRUNCHY_DEBUG value: "true" - name: RELATED_IMAGE_POSTGRES_16 - value: "registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-16.10-2534" + value: "registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-16.10-2542" - name: RELATED_IMAGE_POSTGRES_16_GIS_3.3 - value: "registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-16.10-3.3-2534" + value: "registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-16.10-3.3-2542" - name: RELATED_IMAGE_POSTGRES_16_GIS_3.4 - value: "registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-16.10-3.4-2534" + value: "registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-16.10-3.4-2542" - name: RELATED_IMAGE_POSTGRES_17 - value: "registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-17.6-2534" + value: "registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-17.6-2542" - name: RELATED_IMAGE_POSTGRES_17_GIS_3.4 - value: "registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-17.6-3.4-2534" + value: "registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-17.6-3.4-2542" - name: RELATED_IMAGE_POSTGRES_17_GIS_3.5 - value: "registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-17.6-3.5-2534" + value: "registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-17.6-3.5-2542" + - name: RELATED_IMAGE_POSTGRES_17_GIS_3.6 + value: "registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-17.6-3.5-2542" + - name: RELATED_IMAGE_POSTGRES_18 + value: "registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-18.0-2542" + - name: RELATED_IMAGE_POSTGRES_18_GIS_3.6 + value: "registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi9-18.0-3.6-2542" - name: RELATED_IMAGE_PGBACKREST - value: "registry.developers.crunchydata.com/crunchydata/crunchy-pgbackrest:ubi9-2.56.0-2534" + value: "registry.developers.crunchydata.com/crunchydata/crunchy-pgbackrest:ubi9-2.56.0-2542" - name: RELATED_IMAGE_PGBOUNCER - value: "registry.developers.crunchydata.com/crunchydata/crunchy-pgbouncer:ubi9-1.24-2534" + value: "registry.developers.crunchydata.com/crunchydata/crunchy-pgbouncer:ubi9-1.24-2542" - name: RELATED_IMAGE_PGEXPORTER - value: "registry.developers.crunchydata.com/crunchydata/crunchy-postgres-exporter:ubi9-0.17.1-2534" + value: "registry.developers.crunchydata.com/crunchydata/crunchy-postgres-exporter:ubi9-0.17.1-2542" - name: RELATED_IMAGE_PGUPGRADE - value: "registry.developers.crunchydata.com/crunchydata/crunchy-upgrade:ubi9-17.6-2534" + value: "registry.developers.crunchydata.com/crunchydata/crunchy-upgrade:ubi9-18.0-2542" - name: RELATED_IMAGE_STANDALONE_PGADMIN - value: "registry.developers.crunchydata.com/crunchydata/crunchy-pgadmin4:ubi9-9.2-2534" + value: "registry.developers.crunchydata.com/crunchydata/crunchy-pgadmin4:ubi9-9.8-2542" - name: RELATED_IMAGE_COLLECTOR - value: "registry.developers.crunchydata.com/crunchydata/postgres-operator:ubi9-5.8.3-0" + value: "registry.developers.crunchydata.com/crunchydata/postgres-operator:ubi9-5.8.4-0" securityContext: allowPrivilegeEscalation: false capabilities: { drop: [ALL] } diff --git a/internal/controller/postgrescluster/pgmonitor.go b/internal/controller/postgrescluster/pgmonitor.go index e30bf3f56f..3d234b39ef 100644 --- a/internal/controller/postgrescluster/pgmonitor.go +++ b/internal/controller/postgrescluster/pgmonitor.go @@ -43,6 +43,7 @@ func (r *Reconciler) reconcilePGMonitorExporter(ctx context.Context, monitoringSecret *corev1.Secret) error { var ( + err error writableInstance *Instance writablePod *corev1.Pod setup string @@ -64,23 +65,11 @@ func (r *Reconciler) reconcilePGMonitorExporter(ctx context.Context, // that function against an updated and running pod. if pgmonitor.ExporterEnabled(ctx, cluster) || collector.OpenTelemetryMetricsEnabled(ctx, cluster) { - sql, err := os.ReadFile(fmt.Sprintf("%s/pg%d/setup.sql", pgmonitor.GetQueriesConfigDir(ctx), cluster.Spec.PostgresVersion)) + setup, err = r.reconcileExporterSqlSetup(ctx, cluster) if err != nil { return err } - if collector.OpenTelemetryMetricsEnabled(ctx, cluster) { - setup = metricsSetupForOTelCollector - } else { - // TODO: Revisit how pgbackrest_info.sh is used with pgMonitor. - // pgMonitor queries expect a path to a script that runs pgBackRest - // info and provides json output. In the queries yaml for pgBackRest - // the default path is `/usr/bin/pgbackrest-info.sh`. We update - // the path to point to the script in our database image. - setup = strings.ReplaceAll(string(sql), "/usr/bin/pgbackrest-info.sh", - "/opt/crunchy/bin/postgres/pgbackrest_info.sh") - } - for _, containerStatus := range writablePod.Status.ContainerStatuses { if containerStatus.Name == naming.ContainerDatabase { pgImageSHA = containerStatus.ImageID @@ -145,6 +134,47 @@ func (r *Reconciler) reconcilePGMonitorExporter(ctx context.Context, return err } +// reconcileExporterSqlSetup generates the setup.sql string based on +// whether the OTel metrics feature is enabled or not and the postgres +// version being used. This function assumes that at least one of +// OTel metrics or postgres_exporter are enabled. +func (r *Reconciler) reconcileExporterSqlSetup(ctx context.Context, + cluster *v1beta1.PostgresCluster) (string, error) { + + // If OTel Metrics is enabled we always want to use it. Otherwise, + // we can assume that postgres_exporter is enabled and we should + // use that + if collector.OpenTelemetryMetricsEnabled(ctx, cluster) { + return metricsSetupForOTelCollector, nil + } + + // pgMonitor will not be adding support for postgres_exporter for postgres + // versions past 17. If using postgres 18 or later with the postgres_exporter, + // create a warning event and set the sql setup to an empty string + pgVersion := cluster.Spec.PostgresVersion + if pgVersion > 17 { + r.Recorder.Eventf(cluster, corev1.EventTypeWarning, "ExporterNotSupportedForPostgresVersion", + "postgres_exporter not supported for pg%d; use OTel for postgres 18 and later", + pgVersion) + return "", nil + } + + // OTel Metrics is not enabled and postgres is version 17 or less, + // go ahead and read the appropriate sql file, format the string, + // and return it + sql, err := os.ReadFile(fmt.Sprintf("%s/pg%d/setup.sql", pgmonitor.GetQueriesConfigDir(ctx), pgVersion)) + if err != nil { + return "", err + } + // TODO: Revisit how pgbackrest_info.sh is used with pgMonitor. + // pgMonitor queries expect a path to a script that runs pgBackRest + // info and provides json output. In the queries yaml for pgBackRest + // the default path is `/usr/bin/pgbackrest-info.sh`. We update + // the path to point to the script in our database image. + return strings.ReplaceAll(string(sql), "/usr/bin/pgbackrest-info.sh", + "/opt/crunchy/bin/postgres/pgbackrest_info.sh"), nil +} + // reconcileMonitoringSecret reconciles the secret containing authentication // for monitoring tools func (r *Reconciler) reconcileMonitoringSecret( diff --git a/internal/controller/postgrescluster/pgmonitor_test.go b/internal/controller/postgrescluster/pgmonitor_test.go index e91b176ec0..6b81e018c9 100644 --- a/internal/controller/postgrescluster/pgmonitor_test.go +++ b/internal/controller/postgrescluster/pgmonitor_test.go @@ -20,10 +20,12 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" + "github.com/crunchydata/postgres-operator/internal/controller/runtime" "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/testing/cmp" + "github.com/crunchydata/postgres-operator/internal/testing/events" "github.com/crunchydata/postgres-operator/internal/testing/require" "github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1" ) @@ -551,8 +553,7 @@ func TestReconcilePGMonitorExporter(t *testing.T) { observed := &observedInstances{forCluster: instances} called = false - assert.NilError(t, reconciler.reconcilePGMonitorExporter(ctx, - cluster, observed, nil)) + assert.NilError(t, reconciler.reconcilePGMonitorExporter(ctx, cluster, observed, nil)) assert.Assert(t, called, "PodExec was not called.") assert.Assert(t, cluster.Status.Monitoring.ExporterConfiguration != "", "ExporterConfiguration was empty.") }) @@ -836,6 +837,147 @@ func TestReconcileExporterQueriesConfig(t *testing.T) { actual, err = reconciler.reconcileExporterQueriesConfig(ctx, cluster) assert.NilError(t, err) assert.Assert(t, actual.Data["defaultQueries.yml"] == existing.Data["defaultQueries.yml"], "Data does not align.") + assert.Assert(t, actual.Data["defaultQueries.yml"] != "", "Data should not be empty.") + }) + + t.Run("Pg>17", func(t *testing.T) { + cluster.Spec.PostgresVersion = 18 + actual, err = reconciler.reconcileExporterQueriesConfig(ctx, cluster) + assert.NilError(t, err) + assert.Assert(t, actual.Data["defaultQueries.yml"] == "", "Data should be empty") }) }) } + +// TestReconcileExporterSqlSetup checks that the setup script returned +// by reconcileExporterSqlSetup is either empty or not depending on +// which exporter is enabled and what the postgres version is. +func TestReconcileExporterSqlSetup(t *testing.T) { + ctx := context.Background() + + monitoringSpec := &v1beta1.MonitoringSpec{ + PGMonitor: &v1beta1.PGMonitorSpec{ + Exporter: &v1beta1.ExporterSpec{ + Image: "image", + }, + }, + } + + instrumentationSpec := &v1beta1.InstrumentationSpec{ + Image: "image", + } + + testCases := []struct { + tcName string + postgresVersion int32 + exporterEnabled bool + otelMetricsEnabled bool + errorPresent bool + setupEmpty bool + expectedNumEvents int + expectedEvent string + }{{ + tcName: "ExporterEnabledOtelDisabled", + postgresVersion: 17, + exporterEnabled: true, + otelMetricsEnabled: false, + errorPresent: false, + setupEmpty: false, + expectedNumEvents: 0, + expectedEvent: "", + }, { + tcName: "ExporterDisabledOtelEnabled", + postgresVersion: 17, + exporterEnabled: false, + otelMetricsEnabled: true, + errorPresent: false, + setupEmpty: false, + expectedNumEvents: 0, + expectedEvent: "", + }, { + tcName: "BothEnabled", + postgresVersion: 17, + exporterEnabled: true, + otelMetricsEnabled: true, + errorPresent: false, + setupEmpty: false, + expectedNumEvents: 0, + expectedEvent: "", + }, { + tcName: "ExporterEnabledOtelDisabledPostgres18", + postgresVersion: 18, + exporterEnabled: true, + otelMetricsEnabled: false, + errorPresent: false, + setupEmpty: true, + expectedNumEvents: 1, + expectedEvent: "postgres_exporter not supported for pg18; use OTel for postgres 18 and later", + }, { + tcName: "ExporterDisabledOtelEnabledPostgres18", + postgresVersion: 18, + exporterEnabled: false, + otelMetricsEnabled: true, + errorPresent: false, + setupEmpty: false, + expectedNumEvents: 0, + expectedEvent: "", + }, { + tcName: "BothEnabledPostgres18", + postgresVersion: 18, + exporterEnabled: true, + otelMetricsEnabled: true, + errorPresent: false, + setupEmpty: false, + expectedNumEvents: 0, + expectedEvent: "", + }, { + tcName: "ExporterEnabledOtelDisabledBadPostgresVersion", + postgresVersion: 1, + exporterEnabled: true, + otelMetricsEnabled: false, + errorPresent: true, + setupEmpty: true, + expectedNumEvents: 0, + expectedEvent: "", + }} + + for _, tc := range testCases { + t.Run(tc.tcName, func(t *testing.T) { + cluster := testCluster() + cluster.Spec.PostgresVersion = tc.postgresVersion + + recorder := events.NewRecorder(t, runtime.Scheme) + r := &Reconciler{Recorder: recorder} + + gate := feature.NewGate() + assert.NilError(t, gate.SetFromMap(map[string]bool{ + feature.OpenTelemetryMetrics: tc.otelMetricsEnabled, + })) + ctx := feature.NewContext(ctx, gate) + + if tc.otelMetricsEnabled { + cluster.Spec.Instrumentation = instrumentationSpec + } + + if tc.exporterEnabled { + cluster.Spec.Monitoring = monitoringSpec + } + + setup, err := r.reconcileExporterSqlSetup(ctx, cluster) + if tc.errorPresent { + assert.Assert(t, err != nil) + } else { + assert.NilError(t, err) + } + assert.Equal(t, setup == "", tc.setupEmpty) + + assert.Equal(t, len(recorder.Events), tc.expectedNumEvents) + if tc.expectedNumEvents == 1 { + assert.Equal(t, recorder.Events[0].Regarding.Name, cluster.Name) + assert.Equal(t, recorder.Events[0].Reason, "ExporterNotSupportedForPostgresVersion") + assert.Equal(t, recorder.Events[0].Note, tc.expectedEvent) + assert.Equal(t, recorder.Events[0].Type, corev1.EventTypeWarning) + } + }) + } +} diff --git a/internal/pgmonitor/exporter.go b/internal/pgmonitor/exporter.go index c8422fcc2c..824674349b 100644 --- a/internal/pgmonitor/exporter.go +++ b/internal/pgmonitor/exporter.go @@ -66,6 +66,12 @@ func GenerateDefaultExporterQueries(ctx context.Context, cluster *v1beta1.Postgr queries += string(queriesContents) + "\n" } + // pgMonitor will not be adding support for postgres_exporter for postgres + // versions past 17. If pg version is greater than 17, return an empty string. + if cluster.Spec.PostgresVersion > 17 { + return "" + } + // Add general queries for specific postgres version queriesGeneral, err := os.ReadFile(fmt.Sprintf("%s/pg%d/queries_general.yml", queriesConfigDir, cluster.Spec.PostgresVersion)) if err != nil { diff --git a/internal/pgmonitor/exporter_test.go b/internal/pgmonitor/exporter_test.go index 486b658dab..f9c8321821 100644 --- a/internal/pgmonitor/exporter_test.go +++ b/internal/pgmonitor/exporter_test.go @@ -38,6 +38,12 @@ func TestGenerateDefaultExporterQueries(t *testing.T) { assert.Assert(t, strings.Contains(queries, "ccp_pg_stat_statements_reset"), "Queries do not contain 'ccp_pg_stat_statements_reset' query when they should.") }) + + t.Run("PG>17", func(t *testing.T) { + cluster.Spec.PostgresVersion = 18 + queries := GenerateDefaultExporterQueries(ctx, cluster) + assert.Equal(t, queries, "") + }) } func TestExporterStartCommand(t *testing.T) { diff --git a/internal/testing/events/recorder.go b/internal/testing/events/recorder.go index e76ef21eb3..dad5dccf83 100644 --- a/internal/testing/events/recorder.go +++ b/internal/testing/events/recorder.go @@ -89,7 +89,7 @@ func (*Recorder) AnnotatedEventf(object runtime.Object, annotations map[string]s } func (r *Recorder) Event(object runtime.Object, eventtype, reason, message string) { if r.eventf != nil { - r.eventf(object, nil, eventtype, reason, "", message) + r.eventf(object, nil, eventtype, reason, "", "%v", message) } } func (r *Recorder) Eventf(object runtime.Object, eventtype, reason, messageFmt string, args ...any) { diff --git a/testing/chainsaw/e2e/values.yaml b/testing/chainsaw/e2e/values.yaml index 152354e5dc..9dc2157b85 100644 --- a/testing/chainsaw/e2e/values.yaml +++ b/testing/chainsaw/e2e/values.yaml @@ -2,4 +2,4 @@ versions: postgres: '17' images: - psql: 'registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-17.6-2534' + psql: 'registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-17.6-2542'