Skip to content

Commit 7bc0c03

Browse files
committed
Only add metrics port when a component in the pod has metrics to serve.
1 parent 94d85fb commit 7bc0c03

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

internal/collector/instance.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func AddToPod(
4848
sqlQueryPassword string,
4949
logDirectories []string,
5050
includeLogrotate bool,
51+
includeMetricsPort bool,
5152
) {
5253
if spec == nil ||
5354
!(feature.Enabled(ctx, feature.OpenTelemetryLogs) ||
@@ -153,7 +154,7 @@ func AddToPod(
153154
template.Spec.Volumes = append(template.Spec.Volumes, logrotateConfigVolume)
154155
}
155156

156-
if feature.Enabled(ctx, feature.OpenTelemetryMetrics) {
157+
if feature.Enabled(ctx, feature.OpenTelemetryMetrics) && includeMetricsPort {
157158
container.Ports = []corev1.ContainerPort{{
158159
ContainerPort: int32(PrometheusPort),
159160
Name: "otel-metrics",

internal/controller/postgrescluster/instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ func (r *Reconciler) reconcileInstance(
12221222
// but we are using it for pgbackrest logs in the postgres pod
12231223
collector.AddToPod(ctx, cluster.Spec.Instrumentation, cluster.Spec.ImagePullPolicy, instanceConfigMap, &instance.Spec.Template,
12241224
[]corev1.VolumeMount{postgres.DataVolumeMount()}, pgPassword,
1225-
[]string{naming.PGBackRestPGDataLogPath}, true)
1225+
[]string{naming.PGBackRestPGDataLogPath}, true, true)
12261226
}
12271227

12281228
// Add postgres-exporter to the instance Pod spec

internal/controller/postgrescluster/pgbackrest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ func (r *Reconciler) generateRepoHostIntent(ctx context.Context, postgresCluster
698698
collector.AddToPod(ctx, postgresCluster.Spec.Instrumentation, postgresCluster.Spec.ImagePullPolicy,
699699
&corev1.ConfigMap{ObjectMeta: naming.PGBackRestConfig(postgresCluster)},
700700
&repo.Spec.Template, []corev1.VolumeMount{}, "",
701-
[]string{pgBackRestLogPath}, true)
701+
[]string{pgBackRestLogPath}, true, false)
702702

703703
containersToAdd = append(containersToAdd, naming.ContainerCollector)
704704
}

internal/controller/standalone_pgadmin/statefulset.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ func statefulset(
134134
}
135135

136136
collector.AddToPod(ctx, pgadmin.Spec.Instrumentation, pgadmin.Spec.ImagePullPolicy,
137-
configmap, &sts.Spec.Template, volumeMounts, "", []string{LogDirectoryAbsolutePath}, false)
137+
configmap, &sts.Spec.Template, volumeMounts, "", []string{LogDirectoryAbsolutePath},
138+
false, false)
138139
}
139140

140141
postgrescluster.AddTMPEmptyDir(&sts.Spec.Template)

internal/pgbouncer/reconcile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ func Pod(
192192

193193
if feature.Enabled(ctx, feature.OpenTelemetryLogs) || feature.Enabled(ctx, feature.OpenTelemetryMetrics) {
194194
collector.AddToPod(ctx, inCluster.Spec.Instrumentation, inCluster.Spec.ImagePullPolicy, inConfigMap,
195-
template, []corev1.VolumeMount{configVolumeMount}, string(inSecret.Data["pgbouncer-password"]), []string{naming.PGBouncerLogPath},
196-
true)
195+
template, []corev1.VolumeMount{configVolumeMount}, string(inSecret.Data["pgbouncer-password"]),
196+
[]string{naming.PGBouncerLogPath}, true, true)
197197
}
198198
}
199199

0 commit comments

Comments
 (0)