Skip to content

Commit

Permalink
feat(metrics): building blocks for postgres exporter (#53)
Browse files Browse the repository at this point in the history
## Description

This PR enhances the package by introducing a metrics endpoint to the
PostgreSQL cluster pods. The implementation involves adding a sidecar to
the pods, which exposes a port for Prometheus to scrape using a
configured PodMonitor.

The changes avoid using the package CR to expose the metrics endpoint
due to its complexity, particularly the need to exempt from
uds/skip-mutate: "true" and to configure the PeerAuthentication CR to
carve out a permissive mTLS port for the PodMonitor.

Monitoring can be enabled, but defaults to false.

## Related Issue

Relates to #51 

## Type of change

- [ ] New feature (non-breaking change which adds functionality)

## Checklist before merging

- [ ] Test, docs, adr added or updated as needed
- [ ] [Contributor Guide
Steps](https://github.com/defenseunicorns/uds-package-postgres-operator/blob/main/CONTRIBUTING.md#developer-workflow)
followed

---------

Co-authored-by: Wayne Starr <Racer159@users.noreply.github.com>
  • Loading branch information
rwh85 and Racer159 authored Jul 30, 2024
1 parent 84d4c33 commit c2a47bc
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 0 deletions.
30 changes: 30 additions & 0 deletions chart/templates/postgres-minimal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,34 @@ spec:
{{- toYaml .Values.postgresql.databases | nindent 4 }}
postgresql:
version: {{ .Values.postgresql.version | quote }}
sidecars:
- name: "exporter"
image: {{ .Values.metrics.image | quote }}
ports:
- name: exporter
containerPort: 9187
protocol: TCP
resources:
limits:
cpu: 500m
memory: 256M
requests:
cpu: 100m
memory: 200M
securityContext:
runAsUser: 37
runAsGroup: 37
env:
- name: "DATA_SOURCE_URI"
value: "$(POD_NAME)/postgres"
- name: "DATA_SOURCE_USER"
valueFrom:
secretKeyRef:
name: postgres.pg-cluster.credentials.postgresql.acid.zalan.do
key: username
- name: "DATA_SOURCE_PASS"
valueFrom:
secretKeyRef:
name: postgres.pg-cluster.credentials.postgresql.acid.zalan.do
key: password
{{- end }}
19 changes: 19 additions & 0 deletions chart/templates/postgres-monitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- if .Capabilities.APIVersions.Has "monitoring.coreos.com/v1" }}
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: postgres-exporter
namespace: postgres
spec:
scrapeClass: istio-certs
namespaceSelector:
matchNames:
- postgres
podMetricsEndpoints:
- port: exporter
scheme: https
enableHttp2: false
selector:
matchLabels:
application: spilo
{{- end }}
9 changes: 9 additions & 0 deletions chart/templates/uds-package-postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ spec:
remoteSelector:
app.kubernetes.io/name: postgres-operator

- direction: Ingress
selector:
application: spilo
remoteNamespace: monitoring
remoteSelector:
app: prometheus
port: 9187
description: "Postgres Exporter Port"

- direction: Egress
selector:
cluster-name: pg-cluster
Expand Down
2 changes: 2 additions & 0 deletions values/registry1-config-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
metrics:
image: "registry1.dso.mil/ironbank/opensource/prometheus/postgres-exporter:v0.15.0"
2 changes: 2 additions & 0 deletions values/upstream-config-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
metrics:
image: "quay.io/prometheuscommunity/postgres-exporter:v0.15.0"
10 changes: 10 additions & 0 deletions zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ components:
- name: postgres-operator
valuesFiles:
- ./values/registry1-values.yaml
- name: uds-postgres-config
valuesFiles:
- ./values/registry1-config-values.yaml
images:
# Iron Bank
- registry1.dso.mil/ironbank/opensource/zalando/postgres-operator:v1.12.2
- registry1.dso.mil/ironbank/opensource/zalando/logical-backup:v1.8.2
- registry1.dso.mil/ironbank/opensource/zalando/pgbouncer:1.21.0
# Docker image that provides PostgreSQL and Patroni bundled together for PostgreSQL HA
- ghcr.io/zalando/spilo-15:3.2-p1
# Container iamge that provides the postgres-exporter sidecar to create a metrics endpoint
- registry1.dso.mil/ironbank/opensource/prometheus/postgres-exporter:v0.15.0

- name: postgres-operator
required: true
Expand All @@ -48,9 +53,14 @@ components:
- name: postgres-operator
valuesFiles:
- ./values/upstream-values.yaml
- name: uds-postgres-config
valuesFiles:
- ./values/upstream-config-values.yaml
images:
- ghcr.io/zalando/postgres-operator:v1.12.2
- ghcr.io/zalando/postgres-operator/logical-backup:v1.12.2
- docker.io/bitnami/pgbouncer:1.23.0
# Docker image that provides PostgreSQL and Patroni bundled together for PostgreSQL HA
- ghcr.io/zalando/spilo-15:3.2-p1
# Container iamge that provides the postgres-exporter sidecar to create a metrics endpoint
- quay.io/prometheuscommunity/postgres-exporter:v0.15.0

0 comments on commit c2a47bc

Please sign in to comment.