Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer OTEL to exporter if both enabled #4137

Merged
merged 1 commit into from
Mar 19, 2025
Merged
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
@@ -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
}
17 changes: 17 additions & 0 deletions internal/pgmonitor/util_test.go
Original file line number Diff line number Diff line change
@@ -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))
}