diff --git a/internal/pgmonitor/util.go b/internal/pgmonitor/util.go index 72f528ffa3..76a8a6adae 100644 --- a/internal/pgmonitor/util.go +++ b/internal/pgmonitor/util.go @@ -8,6 +8,7 @@ import ( "context" "os" + "github.com/crunchydata/postgres-operator/internal/collector" "github.com/crunchydata/postgres-operator/internal/logging" "github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1" ) @@ -27,6 +28,11 @@ func GetQueriesConfigDir(ctx context.Context) string { // ExporterEnabled returns true if the monitoring exporter is enabled func ExporterEnabled(ctx context.Context, cluster *v1beta1.PostgresCluster) bool { + // If OpenTelemetry metrics are enabled for this cluster, that takes precedence + // over the postgres_exporter metrics. + if collector.OpenTelemetryMetricsEnabled(ctx, cluster) { + return false + } if cluster.Spec.Monitoring == nil { return false } diff --git a/internal/pgmonitor/util_test.go b/internal/pgmonitor/util_test.go index a7758d0da4..e862e87a67 100644 --- a/internal/pgmonitor/util_test.go +++ b/internal/pgmonitor/util_test.go @@ -10,6 +10,8 @@ import ( "gotest.tools/v3/assert" + "github.com/crunchydata/postgres-operator/internal/feature" + "github.com/crunchydata/postgres-operator/internal/testing/require" "github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1" ) @@ -26,4 +28,19 @@ func TestExporterEnabled(t *testing.T) { cluster.Spec.Monitoring.PGMonitor.Exporter = &v1beta1.ExporterSpec{} assert.Assert(t, ExporterEnabled(ctx, cluster)) + + // Enabling the OpenTelemetryMetrics is not sufficient to disable the exporter + gate := feature.NewGate() + assert.NilError(t, gate.SetFromMap(map[string]bool{ + feature.OpenTelemetryMetrics: true, + })) + ctx = feature.NewContext(ctx, gate) + assert.Assert(t, ExporterEnabled(ctx, cluster)) + + require.UnmarshalInto(t, &cluster.Spec, `{ + instrumentation: { + logs: { retentionPeriod: 5h }, + }, + }`) + assert.Assert(t, !ExporterEnabled(ctx, cluster)) }