Skip to content

Commit 4e5b11e

Browse files
authored
Merge branch 'main' into benjb/otel-feature-gate-revise
2 parents 579f001 + dbdfc9a commit 4e5b11e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1198
-340
lines changed

config/crd/bases/postgres-operator.crunchydata.com_pgadmins.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,12 @@ spec:
15601560
backing this claim.
15611561
type: string
15621562
type: object
1563+
x-kubernetes-map-type: atomic
1564+
x-kubernetes-validations:
1565+
- message: missing accessModes
1566+
rule: 0 < size(self.accessModes)
1567+
- message: missing storage request
1568+
rule: has(self.resources.requests.storage)
15631569
image:
15641570
description: The image name to use for pgAdmin instance.
15651571
type: string
@@ -2042,6 +2048,75 @@ spec:
20422048
- message: must be at least one hour
20432049
rule: duration("1h") <= self && self <= duration("8760h")
20442050
type: object
2051+
metrics:
2052+
description: Metrics is the place for users to configure metrics
2053+
collection.
2054+
properties:
2055+
customQueries:
2056+
description: |-
2057+
Where users can turn off built-in metrics and also provide their own
2058+
custom queries.
2059+
properties:
2060+
add:
2061+
description: User defined queries and metrics.
2062+
items:
2063+
properties:
2064+
collectionInterval:
2065+
default: 5s
2066+
description: How often the queries should be run.
2067+
format: duration
2068+
maxLength: 20
2069+
minLength: 1
2070+
pattern: ^((PT)?( *[0-9]+ *(?i:(ms|s|m)|(milli|sec|min)s?))+|0)$
2071+
type: string
2072+
x-kubernetes-validations:
2073+
- rule: duration("0") <= self && self <= duration("60m")
2074+
name:
2075+
description: |-
2076+
The name of this batch of queries, which will be used in naming the OTel
2077+
SqlQuery receiver.
2078+
maxLength: 20
2079+
pattern: ^[^\pZ\pC\pS]+$
2080+
type: string
2081+
queries:
2082+
description: A ConfigMap holding the yaml file that
2083+
contains the queries.
2084+
properties:
2085+
key:
2086+
description: Name of the data field within the
2087+
ConfigMap.
2088+
maxLength: 253
2089+
minLength: 1
2090+
pattern: ^[-._a-zA-Z0-9]+$
2091+
type: string
2092+
x-kubernetes-validations:
2093+
- message: cannot be "." or start with ".."
2094+
rule: self != "." && !self.startsWith("..")
2095+
name:
2096+
description: Name of the ConfigMap.
2097+
maxLength: 253
2098+
minLength: 1
2099+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?([.][a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
2100+
type: string
2101+
required:
2102+
- key
2103+
- name
2104+
type: object
2105+
x-kubernetes-map-type: atomic
2106+
required:
2107+
- name
2108+
- queries
2109+
type: object
2110+
type: array
2111+
remove:
2112+
description: |-
2113+
A list of built-in queries that should be removed. If all queries for a
2114+
given SQL statement are removed, the SQL statement will no longer be run.
2115+
items:
2116+
type: string
2117+
type: array
2118+
type: object
2119+
type: object
20452120
resources:
20462121
description: Resources holds the resource requirements for the
20472122
collector container.

config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 90 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,13 +3197,12 @@ spec:
31973197
to the PersistentVolume backing this claim.
31983198
type: string
31993199
type: object
3200+
x-kubernetes-map-type: atomic
32003201
x-kubernetes-validations:
32013202
- message: missing accessModes
3202-
rule: has(self.accessModes) && size(self.accessModes)
3203-
> 0
3203+
rule: 0 < size(self.accessModes)
32043204
- message: missing storage request
3205-
rule: has(self.resources) && has(self.resources.requests)
3206-
&& has(self.resources.requests.storage)
3205+
rule: has(self.resources.requests.storage)
32073206
required:
32083207
- volumeClaimSpec
32093208
type: object
@@ -6524,13 +6523,12 @@ spec:
65246523
to the PersistentVolume backing this claim.
65256524
type: string
65266525
type: object
6526+
x-kubernetes-map-type: atomic
65276527
x-kubernetes-validations:
65286528
- message: missing accessModes
6529-
rule: has(self.accessModes) && size(self.accessModes)
6530-
> 0
6529+
rule: 0 < size(self.accessModes)
65316530
- message: missing storage request
6532-
rule: has(self.resources) && has(self.resources.requests)
6533-
&& has(self.resources.requests.storage)
6531+
rule: has(self.resources.requests.storage)
65346532
required:
65356533
- volumeClaimSpec
65366534
type: object
@@ -10412,12 +10410,12 @@ spec:
1041210410
PersistentVolume backing this claim.
1041310411
type: string
1041410412
type: object
10413+
x-kubernetes-map-type: atomic
1041510414
x-kubernetes-validations:
1041610415
- message: missing accessModes
10417-
rule: has(self.accessModes) && size(self.accessModes) > 0
10416+
rule: 0 < size(self.accessModes)
1041810417
- message: missing storage request
10419-
rule: has(self.resources) && has(self.resources.requests)
10420-
&& has(self.resources.requests.storage)
10418+
rule: has(self.resources.requests.storage)
1042110419
metadata:
1042210420
description: Metadata contains metadata for custom resources
1042310421
properties:
@@ -10797,13 +10795,12 @@ spec:
1079710795
the PersistentVolume backing this claim.
1079810796
type: string
1079910797
type: object
10798+
x-kubernetes-map-type: atomic
1080010799
x-kubernetes-validations:
1080110800
- message: missing accessModes
10802-
rule: has(self.accessModes) && size(self.accessModes)
10803-
> 0
10801+
rule: 0 < size(self.accessModes)
1080410802
- message: missing storage request
10805-
rule: has(self.resources) && has(self.resources.requests)
10806-
&& has(self.resources.requests.storage)
10803+
rule: has(self.resources.requests.storage)
1080710804
name:
1080810805
description: |-
1080910806
The name for the tablespace, used as the path name for the volume.
@@ -11238,12 +11235,12 @@ spec:
1123811235
PersistentVolume backing this claim.
1123911236
type: string
1124011237
type: object
11238+
x-kubernetes-map-type: atomic
1124111239
x-kubernetes-validations:
1124211240
- message: missing accessModes
11243-
rule: has(self.accessModes) && size(self.accessModes) > 0
11241+
rule: 0 < size(self.accessModes)
1124411242
- message: missing storage request
11245-
rule: has(self.resources) && has(self.resources.requests)
11246-
&& has(self.resources.requests.storage)
11243+
rule: has(self.resources.requests.storage)
1124711244
required:
1124811245
- dataVolumeClaimSpec
1124911246
type: object
@@ -11698,6 +11695,75 @@ spec:
1169811695
- message: must be at least one hour
1169911696
rule: duration("1h") <= self && self <= duration("8760h")
1170011697
type: object
11698+
metrics:
11699+
description: Metrics is the place for users to configure metrics
11700+
collection.
11701+
properties:
11702+
customQueries:
11703+
description: |-
11704+
Where users can turn off built-in metrics and also provide their own
11705+
custom queries.
11706+
properties:
11707+
add:
11708+
description: User defined queries and metrics.
11709+
items:
11710+
properties:
11711+
collectionInterval:
11712+
default: 5s
11713+
description: How often the queries should be run.
11714+
format: duration
11715+
maxLength: 20
11716+
minLength: 1
11717+
pattern: ^((PT)?( *[0-9]+ *(?i:(ms|s|m)|(milli|sec|min)s?))+|0)$
11718+
type: string
11719+
x-kubernetes-validations:
11720+
- rule: duration("0") <= self && self <= duration("60m")
11721+
name:
11722+
description: |-
11723+
The name of this batch of queries, which will be used in naming the OTel
11724+
SqlQuery receiver.
11725+
maxLength: 20
11726+
pattern: ^[^\pZ\pC\pS]+$
11727+
type: string
11728+
queries:
11729+
description: A ConfigMap holding the yaml file that
11730+
contains the queries.
11731+
properties:
11732+
key:
11733+
description: Name of the data field within the
11734+
ConfigMap.
11735+
maxLength: 253
11736+
minLength: 1
11737+
pattern: ^[-._a-zA-Z0-9]+$
11738+
type: string
11739+
x-kubernetes-validations:
11740+
- message: cannot be "." or start with ".."
11741+
rule: self != "." && !self.startsWith("..")
11742+
name:
11743+
description: Name of the ConfigMap.
11744+
maxLength: 253
11745+
minLength: 1
11746+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?([.][a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
11747+
type: string
11748+
required:
11749+
- key
11750+
- name
11751+
type: object
11752+
x-kubernetes-map-type: atomic
11753+
required:
11754+
- name
11755+
- queries
11756+
type: object
11757+
type: array
11758+
remove:
11759+
description: |-
11760+
A list of built-in queries that should be removed. If all queries for a
11761+
given SQL statement are removed, the SQL statement will no longer be run.
11762+
items:
11763+
type: string
11764+
type: array
11765+
type: object
11766+
type: object
1170111767
resources:
1170211768
description: Resources holds the resource requirements for the
1170311769
collector container.
@@ -17328,6 +17394,12 @@ spec:
1732817394
PersistentVolume backing this claim.
1732917395
type: string
1733017396
type: object
17397+
x-kubernetes-map-type: atomic
17398+
x-kubernetes-validations:
17399+
- message: missing accessModes
17400+
rule: 0 < size(self.accessModes)
17401+
- message: missing storage request
17402+
rule: has(self.resources.requests.storage)
1733117403
image:
1733217404
description: |-
1733317405
Name of a container image that can run pgAdmin 4. Changing this value causes

internal/collector/generated/postgres_5s_metrics.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/collector/instance.go

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ func AddToPod(
4343
spec *v1beta1.InstrumentationSpec,
4444
pullPolicy corev1.PullPolicy,
4545
inInstanceConfigMap *corev1.ConfigMap,
46-
outPod *corev1.PodSpec,
46+
template *corev1.PodTemplateSpec,
4747
volumeMounts []corev1.VolumeMount,
4848
sqlQueryPassword string,
4949
logDirectories []string,
5050
includeLogrotate bool,
51+
thisPodServesMetrics bool,
5152
) {
5253
if !OpenTelemetryLogsOrMetricsEnabled(ctx, spec) {
5354
return
@@ -74,14 +75,13 @@ func AddToPod(
7475
}},
7576
}
7677

77-
// If the user has specified files to be mounted in the spec, add them to the projected config volume
78-
if spec != nil && spec.Config != nil && spec.Config.Files != nil {
79-
configVolume.Projected.Sources = append(configVolume.Projected.Sources, spec.Config.Files...)
78+
// If the user has specified files to be mounted in the spec, add them to
79+
// the projected config volume
80+
if spec.Config != nil && spec.Config.Files != nil {
81+
configVolume.Projected.Sources = append(configVolume.Projected.Sources,
82+
spec.Config.Files...)
8083
}
8184

82-
// Add configVolume to the pod's volumes
83-
outPod.Volumes = append(outPod.Volumes, configVolume)
84-
8585
// Create collector container
8686
container := corev1.Container{
8787
Name: naming.ContainerCollector,
@@ -111,6 +111,28 @@ func AddToPod(
111111
VolumeMounts: append(volumeMounts, configVolumeMount),
112112
}
113113

114+
// If metrics feature is enabled and this Pod serves metrics, add the
115+
// Prometheus port to this container
116+
if feature.Enabled(ctx, feature.OpenTelemetryMetrics) && thisPodServesMetrics {
117+
container.Ports = []corev1.ContainerPort{{
118+
ContainerPort: int32(PrometheusPort),
119+
Name: "otel-metrics",
120+
Protocol: corev1.ProtocolTCP,
121+
}}
122+
123+
// If the user has specified custom queries to add, put the queries
124+
// file(s) in the projected config volume
125+
if spec.Metrics != nil && spec.Metrics.CustomQueries != nil &&
126+
spec.Metrics.CustomQueries.Add != nil {
127+
for _, querySet := range spec.Metrics.CustomQueries.Add {
128+
projection := querySet.Queries.AsProjection(querySet.Name +
129+
"/" + querySet.Queries.Key)
130+
configVolume.Projected.Sources = append(configVolume.Projected.Sources,
131+
corev1.VolumeProjection{ConfigMap: &projection})
132+
}
133+
}
134+
}
135+
114136
// If this is a pod that uses logrotate for log rotation, add config volume
115137
// and mount for logrotate config
116138
if includeLogrotate {
@@ -134,18 +156,17 @@ func AddToPod(
134156
}},
135157
}
136158
container.VolumeMounts = append(container.VolumeMounts, logrotateConfigVolumeMount)
137-
outPod.Volumes = append(outPod.Volumes, logrotateConfigVolume)
159+
template.Spec.Volumes = append(template.Spec.Volumes, logrotateConfigVolume)
138160
}
139161

140-
if feature.Enabled(ctx, feature.OpenTelemetryMetrics) {
141-
container.Ports = []corev1.ContainerPort{{
142-
ContainerPort: int32(8889),
143-
Name: "otel-metrics",
144-
Protocol: corev1.ProtocolTCP,
145-
}}
146-
}
162+
// Add configVolume to the Pod's volumes and add the collector container to
163+
// the Pod's containers
164+
template.Spec.Volumes = append(template.Spec.Volumes, configVolume)
165+
template.Spec.Containers = append(template.Spec.Containers, container)
147166

148-
outPod.Containers = append(outPod.Containers, container)
167+
// add the OTel collector label to the Pod
168+
initialize.Labels(template)
169+
template.Labels[naming.LabelCollectorDiscovery] = "true"
149170
}
150171

151172
// startCommand generates the command script used by the collector container
@@ -190,7 +211,8 @@ while read -r -t 5 -u "${fd}" ||:; do
190211
done
191212
`, mkdirScript, configDirectory, logrotateCommand)
192213

193-
wrapper := `monitor() {` + startScript + `}; export directory="$1"; export -f monitor; exec -a "$0" bash -ceu monitor`
214+
wrapper := `monitor() {` + startScript +
215+
`}; export directory="$1"; export -f monitor; exec -a "$0" bash -ceu monitor`
194216

195217
return []string{"bash", "-ceu", "--", wrapper, "collector", configDirectory}
196218
}

internal/collector/naming.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const LogsBatchProcessor = "batch/logs"
1010
const OneSecondBatchProcessor = "batch/1s"
1111
const SubSecondBatchProcessor = "batch/200ms"
1212
const Prometheus = "prometheus"
13+
const PrometheusPort = 9187
1314
const PGBouncerMetrics = "metrics/pgbouncer"
1415
const PostgresMetrics = "metrics/postgres"
1516
const PatroniMetrics = "metrics/patroni"

internal/collector/patroni.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package collector
77
import (
88
"context"
99
"slices"
10+
"strconv"
1011

1112
"github.com/crunchydata/postgres-operator/internal/naming"
1213
"github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
@@ -135,7 +136,7 @@ func EnablePatroniMetrics(ctx context.Context,
135136
if OpenTelemetryMetricsEnabled(ctx, inCluster) {
136137
// Add Prometheus exporter
137138
outConfig.Exporters[Prometheus] = map[string]any{
138-
"endpoint": "0.0.0.0:9187",
139+
"endpoint": "0.0.0.0:" + strconv.Itoa(PrometheusPort),
139140
}
140141

141142
// Add Prometheus Receiver

0 commit comments

Comments
 (0)