Skip to content

Commit 1435e7a

Browse files
benjaminjbvbeaucha
authored andcommitted
Add process name to OTel (CrunchyData#4192)
* Add process name to OTel Issue: [PGO-2426]
1 parent d6800dd commit 1435e7a

File tree

11 files changed

+49
-10
lines changed

11 files changed

+49
-10
lines changed

internal/collector/patroni.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func EnablePatroniLogging(ctx context.Context,
6565
{"action": "insert", "key": "k8s.container.name", "value": naming.ContainerDatabase},
6666
{"action": "insert", "key": "k8s.namespace.name", "value": "${env:K8S_POD_NAMESPACE}"},
6767
{"action": "insert", "key": "k8s.pod.name", "value": "${env:K8S_POD_NAME}"},
68+
{"action": "insert", "key": "process.executable.name", "value": "patroni"},
6869
},
6970
}
7071

internal/collector/patroni_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ processors:
6363
- action: insert
6464
key: k8s.pod.name
6565
value: ${env:K8S_POD_NAME}
66+
- action: insert
67+
key: process.executable.name
68+
value: patroni
6669
resourcedetection:
6770
detectors: []
6871
override: false
@@ -163,6 +166,9 @@ processors:
163166
- action: insert
164167
key: k8s.pod.name
165168
value: ${env:K8S_POD_NAME}
169+
- action: insert
170+
key: process.executable.name
171+
value: patroni
166172
resourcedetection:
167173
detectors: []
168174
override: false

internal/collector/pgadmin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func EnablePgAdminLogging(ctx context.Context, spec *v1beta1.InstrumentationSpec
5454
{"action": "insert", "key": "k8s.container.name", "value": naming.ContainerPGAdmin},
5555
{"action": "insert", "key": "k8s.namespace.name", "value": "${env:K8S_POD_NAMESPACE}"},
5656
{"action": "insert", "key": "k8s.pod.name", "value": "${env:K8S_POD_NAME}"},
57+
{"action": "insert", "key": "process.executable.name", "value": "pgadmin"},
5758
},
5859
}
5960

internal/collector/pgadmin_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ collector.yaml: |
6767
- action: insert
6868
key: k8s.pod.name
6969
value: ${env:K8S_POD_NAME}
70+
- action: insert
71+
key: process.executable.name
72+
value: pgadmin
7073
resourcedetection:
7174
detectors: []
7275
override: false
@@ -192,6 +195,9 @@ collector.yaml: |
192195
- action: insert
193196
key: k8s.pod.name
194197
value: ${env:K8S_POD_NAME}
198+
- action: insert
199+
key: process.executable.name
200+
value: pgadmin
195201
resourcedetection:
196202
detectors: []
197203
override: false

internal/collector/pgbackrest.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func NewConfigForPgBackrestRepoHostPod(
8787
{"action": "insert", "key": "k8s.container.name", "value": naming.PGBackRestRepoContainerName},
8888
{"action": "insert", "key": "k8s.namespace.name", "value": "${env:K8S_POD_NAMESPACE}"},
8989
{"action": "insert", "key": "k8s.pod.name", "value": "${env:K8S_POD_NAME}"},
90+
{"action": "insert", "key": "process.executable.name", "value": "pgbackrest"},
9091
},
9192
}
9293

internal/collector/pgbackrest_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ processors:
6565
- action: insert
6666
key: k8s.pod.name
6767
value: ${env:K8S_POD_NAME}
68+
- action: insert
69+
key: process.executable.name
70+
value: pgbackrest
6871
resourcedetection:
6972
detectors: []
7073
override: false
@@ -172,6 +175,9 @@ processors:
172175
- action: insert
173176
key: k8s.pod.name
174177
value: ${env:K8S_POD_NAME}
178+
- action: insert
179+
key: process.executable.name
180+
value: pgbackrest
175181
resourcedetection:
176182
detectors: []
177183
override: false

internal/collector/pgbouncer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func EnablePgBouncerLogging(ctx context.Context,
9090
{"action": "insert", "key": "k8s.container.name", "value": naming.ContainerPGBouncer},
9191
{"action": "insert", "key": "k8s.namespace.name", "value": "${env:K8S_POD_NAMESPACE}"},
9292
{"action": "insert", "key": "k8s.pod.name", "value": "${env:K8S_POD_NAME}"},
93+
{"action": "insert", "key": "process.executable.name", "value": "pgbouncer"},
9394
},
9495
}
9596

internal/collector/pgbouncer_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ processors:
6262
- action: insert
6363
key: k8s.pod.name
6464
value: ${env:K8S_POD_NAME}
65+
- action: insert
66+
key: process.executable.name
67+
value: pgbouncer
6568
resourcedetection:
6669
detectors: []
6770
override: false
@@ -162,6 +165,9 @@ processors:
162165
- action: insert
163166
key: k8s.pod.name
164167
value: ${env:K8S_POD_NAME}
168+
- action: insert
169+
key: process.executable.name
170+
value: pgbouncer
165171
resourcedetection:
166172
detectors: []
167173
override: false

internal/collector/postgres.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ func EnablePostgresLogging(
197197
{"action": "insert", "key": "k8s.container.name", "value": naming.ContainerDatabase},
198198
{"action": "insert", "key": "k8s.namespace.name", "value": "${env:K8S_POD_NAMESPACE}"},
199199
{"action": "insert", "key": "k8s.pod.name", "value": "${env:K8S_POD_NAME}"},
200+
{"action": "insert", "key": "process.executable.name", "value": "postgres"},
200201

201202
// https://github.com/open-telemetry/semantic-conventions/blob/v1.29.0/docs/database#readme
202203
{"action": "insert", "key": "db.system", "value": "postgresql"},
@@ -276,6 +277,7 @@ func EnablePostgresLogging(
276277
{"action": "insert", "key": "k8s.container.name", "value": naming.ContainerDatabase},
277278
{"action": "insert", "key": "k8s.namespace.name", "value": "${env:K8S_POD_NAMESPACE}"},
278279
{"action": "insert", "key": "k8s.pod.name", "value": "${env:K8S_POD_NAME}"},
280+
{"action": "insert", "key": "process.executable.name", "value": "pgbackrest"},
279281
},
280282
}
281283

internal/collector/postgres_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ processors:
7171
- action: insert
7272
key: k8s.pod.name
7373
value: ${env:K8S_POD_NAME}
74+
- action: insert
75+
key: process.executable.name
76+
value: pgbackrest
7477
resource/postgres:
7578
attributes:
7679
- action: insert
@@ -82,6 +85,9 @@ processors:
8285
- action: insert
8386
key: k8s.pod.name
8487
value: ${env:K8S_POD_NAME}
88+
- action: insert
89+
key: process.executable.name
90+
value: postgres
8591
- action: insert
8692
key: db.system
8793
value: postgresql
@@ -331,6 +337,9 @@ processors:
331337
- action: insert
332338
key: k8s.pod.name
333339
value: ${env:K8S_POD_NAME}
340+
- action: insert
341+
key: process.executable.name
342+
value: pgbackrest
334343
resource/postgres:
335344
attributes:
336345
- action: insert
@@ -342,6 +351,9 @@ processors:
342351
- action: insert
343352
key: k8s.pod.name
344353
value: ${env:K8S_POD_NAME}
354+
- action: insert
355+
key: process.executable.name
356+
value: postgres
345357
- action: insert
346358
key: db.system
347359
value: postgresql

internal/controller/postgrescluster/instance.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,11 @@ type instanceSorter struct {
164164
func (s *instanceSorter) Len() int {
165165
return len(s.instances)
166166
}
167+
167168
func (s *instanceSorter) Less(i, j int) bool {
168169
return s.less(s.instances[i], s.instances[j])
169170
}
171+
170172
func (s *instanceSorter) Swap(i, j int) {
171173
s.instances[i], s.instances[j] = s.instances[j], s.instances[i]
172174
}
@@ -484,7 +486,6 @@ func (r *Reconciler) deleteInstances(
484486
// have a "spec.replicas" field with the same meaning.
485487
patch := client.RawPatch(client.Merge.Type(), []byte(`{"spec":{"replicas":0}}`))
486488
err := errors.WithStack(r.patch(ctx, instance, patch))
487-
488489
// When the pod controller is missing, requeue rather than return an
489490
// error. The garbage collector will stop the pod, and it is not our
490491
// mistake that something else is deleting objects. Use RequeueAfter to
@@ -594,7 +595,6 @@ func (r *Reconciler) reconcileInstanceSets(
594595
backupsSpecFound bool,
595596
otelConfig *collector.Config,
596597
) error {
597-
598598
// Go through the observed instances and check if a primary has been determined.
599599
// If the cluster is being shutdown and this instance is the primary, store
600600
// the instance name as the startup instance. If the primary can be determined
@@ -708,8 +708,8 @@ func (r *Reconciler) cleanupPodDisruptionBudgets(
708708
// for the instance set specified that are not currently associated with an instance, and then
709709
// returning the instance names associated with those PVC's.
710710
func findAvailableInstanceNames(set v1beta1.PostgresInstanceSetSpec,
711-
observedInstances *observedInstances, clusterVolumes []*corev1.PersistentVolumeClaim) []string {
712-
711+
observedInstances *observedInstances, clusterVolumes []*corev1.PersistentVolumeClaim,
712+
) []string {
713713
availableInstanceNames := []string{}
714714

715715
// first identify any PGDATA volumes for the instance set specified
@@ -969,7 +969,6 @@ func (r *Reconciler) scaleDownInstances(
969969
cluster *v1beta1.PostgresCluster,
970970
observedInstances *observedInstances,
971971
) error {
972-
973972
// want defines the number of replicas we want for each instance set
974973
want := map[string]int{}
975974
for _, set := range cluster.Spec.InstanceSets {
@@ -1008,7 +1007,6 @@ func (r *Reconciler) scaleDownInstances(
10081007
// the number of replicas we want for each instance set
10091008
// then returns a list of the pods that we want to keep
10101009
func podsToKeep(instances []corev1.Pod, want map[string]int) []corev1.Pod {
1011-
10121010
f := func(instances []corev1.Pod, want int) []corev1.Pod {
10131011
keep := []corev1.Pod{}
10141012

@@ -1041,7 +1039,6 @@ func podsToKeep(instances []corev1.Pod, want map[string]int) []corev1.Pod {
10411039
}
10421040

10431041
return keepPodList
1044-
10451042
}
10461043

10471044
// +kubebuilder:rbac:groups="apps",resources="statefulsets",verbs={list}
@@ -1220,10 +1217,11 @@ func (r *Reconciler) reconcileInstance(
12201217

12211218
// For now, we are not using logrotate to rotate postgres or patroni logs,
12221219
// but we are using it for pgbackrest logs in the postgres pod, so we will
1223-
// set includeLogrotate to true, but only if backups are enabled.
1220+
// set includeLogrotate to true, but only if backups are enabled and pgbackrest is configured with a repo host volume.
1221+
includeLogrotate := backupsSpecFound && pgbackrest.RepoHostVolumeDefined(cluster)
12241222
collector.AddToPod(ctx, cluster.Spec.Instrumentation, cluster.Spec.ImagePullPolicy, instanceConfigMap, &instance.Spec.Template,
12251223
[]corev1.VolumeMount{postgres.DataVolumeMount()}, pgPassword,
1226-
[]string{naming.PGBackRestPGDataLogPath}, backupsSpecFound, true)
1224+
[]string{naming.PGBackRestPGDataLogPath}, includeLogrotate, true)
12271225
}
12281226

12291227
// Add postgres-exporter to the instance Pod spec
@@ -1238,7 +1236,6 @@ func (r *Reconciler) reconcileInstance(
12381236
config.PostgresContainerImage(cluster),
12391237
cluster.Spec.ImagePullPolicy,
12401238
&instance.Spec.Template)
1241-
12421239
}
12431240
// add an emptyDir volume to the PodTemplateSpec and an associated '/tmp' volume mount to
12441241
// all containers included within that spec

0 commit comments

Comments
 (0)