Skip to content
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
6 changes: 6 additions & 0 deletions internal/pgmonitor/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
}
Expand Down
17 changes: 17 additions & 0 deletions internal/pgmonitor/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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))
}