Skip to content

Commit 30e8e5b

Browse files
author
tony-landreth
committed
Remove requirement of exporter block for OTel metrics
1 parent 1ec9140 commit 30e8e5b

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

internal/controller/postgrescluster/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,13 @@ func (r *Reconciler) Reconcile(
235235
}
236236

237237
pgHBAs := postgres.NewHBAs()
238-
pgmonitor.PostgreSQLHBAs(cluster, &pgHBAs)
238+
pgmonitor.PostgreSQLHBAs(ctx, cluster, &pgHBAs)
239239
pgbouncer.PostgreSQL(cluster, &pgHBAs)
240240

241241
pgParameters := postgres.NewParameters()
242242
pgaudit.PostgreSQLParameters(&pgParameters)
243243
pgbackrest.PostgreSQL(cluster, &pgParameters, backupsSpecFound)
244-
pgmonitor.PostgreSQLParameters(cluster, &pgParameters)
244+
pgmonitor.PostgreSQLParameters(ctx, cluster, &pgParameters)
245245

246246
otelConfig := collector.NewConfigForPostgresPod(ctx, cluster, &pgParameters)
247247

internal/controller/postgrescluster/pgmonitor.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ func (r *Reconciler) reconcilePGMonitorExporter(ctx context.Context,
7373
// We use this ImageID and the setup.sql file in the hash we make to see if the operator needs to rerun
7474
// the `EnableExporterInPostgreSQL` funcs; that way we are always running
7575
// that function against an updated and running pod.
76-
if pgmonitor.ExporterEnabled(cluster) {
76+
77+
if pgmonitor.ExporterEnabled(cluster) || feature.Enabled(ctx, feature.OpenTelemetryMetrics) {
7778
sql, err := os.ReadFile(fmt.Sprintf("%s/pg%d/setup.sql", pgmonitor.GetQueriesConfigDir(ctx), cluster.Spec.PostgresVersion))
7879
if err != nil {
7980
return err
@@ -110,7 +111,7 @@ func (r *Reconciler) reconcilePGMonitorExporter(ctx context.Context,
110111
return pgmonitor.EnableExporterInPostgreSQL(ctx, exec, monitoringSecret, pgmonitor.ExporterDB, setup)
111112
}
112113

113-
if !pgmonitor.ExporterEnabled(cluster) {
114+
if !pgmonitor.ExporterEnabled(cluster) && !feature.Enabled(ctx, feature.OpenTelemetryMetrics) {
114115
action = func(ctx context.Context, exec postgres.Executor) error {
115116
return pgmonitor.DisableExporterInPostgreSQL(ctx, exec)
116117
}
@@ -168,7 +169,7 @@ func (r *Reconciler) reconcileMonitoringSecret(
168169
return nil, err
169170
}
170171

171-
if !pgmonitor.ExporterEnabled(cluster) {
172+
if !pgmonitor.ExporterEnabled(cluster) && !feature.Enabled(ctx, feature.OpenTelemetryMetrics) {
172173
// TODO: Checking if the exporter is enabled to determine when monitoring
173174
// secret should be created. If more tools are added to the monitoring
174175
// suite, they could need the secret when the exporter is not enabled.
@@ -259,7 +260,7 @@ func addPGMonitorExporterToInstancePodSpec(
259260
template *corev1.PodTemplateSpec,
260261
exporterQueriesConfig, exporterWebConfig *corev1.ConfigMap) error {
261262

262-
if !pgmonitor.ExporterEnabled(cluster) {
263+
if !pgmonitor.ExporterEnabled(cluster) && !feature.Enabled(ctx, feature.OpenTelemetryMetrics) {
263264
return nil
264265
}
265266

@@ -407,7 +408,7 @@ func (r *Reconciler) reconcileExporterWebConfig(ctx context.Context,
407408
return nil, err
408409
}
409410

410-
if !pgmonitor.ExporterEnabled(cluster) || cluster.Spec.Monitoring.PGMonitor.Exporter.CustomTLSSecret == nil {
411+
if !pgmonitor.ExporterEnabled(cluster) || feature.Enabled(ctx, feature.OpenTelemetryMetrics) || cluster.Spec.Monitoring.PGMonitor.Exporter.CustomTLSSecret == nil {
411412
// We could still have a NotFound error here so check the err.
412413
// If no error that means the configmap is found and needs to be deleted
413414
if err == nil {

internal/pgmonitor/postgres.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
corev1 "k8s.io/api/core/v1"
1212

13+
"github.com/crunchydata/postgres-operator/internal/feature"
1314
"github.com/crunchydata/postgres-operator/internal/logging"
1415
"github.com/crunchydata/postgres-operator/internal/postgres"
1516
"github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
@@ -22,8 +23,8 @@ const (
2223

2324
// PostgreSQLHBAs provides the Postgres HBA rules for allowing the monitoring
2425
// exporter to be accessible
25-
func PostgreSQLHBAs(inCluster *v1beta1.PostgresCluster, outHBAs *postgres.HBAs) {
26-
if ExporterEnabled(inCluster) {
26+
func PostgreSQLHBAs(ctx context.Context, inCluster *v1beta1.PostgresCluster, outHBAs *postgres.HBAs) {
27+
if ExporterEnabled(inCluster) || feature.Enabled(ctx, feature.OpenTelemetryMetrics) {
2728
// Limit the monitoring user to local connections using SCRAM.
2829
outHBAs.Mandatory = append(outHBAs.Mandatory,
2930
postgres.NewHBA().TCP().User(MonitoringUser).Method("scram-sha-256").Network("127.0.0.0/8"),
@@ -34,8 +35,8 @@ func PostgreSQLHBAs(inCluster *v1beta1.PostgresCluster, outHBAs *postgres.HBAs)
3435

3536
// PostgreSQLParameters provides additional required configuration parameters
3637
// that Postgres needs to support monitoring
37-
func PostgreSQLParameters(inCluster *v1beta1.PostgresCluster, outParameters *postgres.Parameters) {
38-
if ExporterEnabled(inCluster) {
38+
func PostgreSQLParameters(ctx context.Context, inCluster *v1beta1.PostgresCluster, outParameters *postgres.Parameters) {
39+
if ExporterEnabled(inCluster) || feature.Enabled(ctx, feature.OpenTelemetryMetrics) {
3940
// Exporter expects that shared_preload_libraries are installed
4041
// pg_stat_statements: https://access.crunchydata.com/documentation/pgmonitor/latest/exporter/
4142
// pgnodemx: https://github.com/CrunchyData/pgnodemx

0 commit comments

Comments
 (0)