Skip to content

Commit 75be991

Browse files
jmckulkandrewlecuyer
authored andcommitted
Initial test for exporter metrics
Checks that the exporter sidecar is running and the metrics endpoint is available from inside the container. This test also checks that the ccp_monitoring user is available in the database
1 parent 4d367e2 commit 75be991

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: postgres-operator.crunchydata.com/v1beta1
2+
kind: PostgresCluster
3+
metadata:
4+
name: exporter
5+
spec:
6+
postgresVersion: ${KUTTL_PG_VERSION}
7+
instances:
8+
- name: instance1
9+
dataVolumeClaimSpec:
10+
accessModes:
11+
- "ReadWriteOnce"
12+
resources:
13+
requests:
14+
storage: 1Gi
15+
backups:
16+
pgbackrest:
17+
repos:
18+
- name: repo1
19+
volume:
20+
volumeClaimSpec:
21+
accessModes:
22+
- "ReadWriteOnce"
23+
resources:
24+
requests:
25+
storage: 1Gi
26+
monitoring:
27+
pgmonitor:
28+
exporter: {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: postgres-operator.crunchydata.com/v1beta1
2+
kind: PostgresCluster
3+
metadata:
4+
name: exporter
5+
status:
6+
instances:
7+
- name: instance1
8+
readyReplicas: 1
9+
replicas: 1
10+
updatedReplicas: 1
11+
---
12+
apiVersion: batch/v1
13+
kind: Job
14+
metadata:
15+
labels:
16+
postgres-operator.crunchydata.com/cluster: exporter
17+
postgres-operator.crunchydata.com/pgbackrest-backup: replica-create
18+
status:
19+
succeeded: 1
20+
---
21+
apiVersion: v1
22+
kind: Service
23+
metadata:
24+
name: exporter-primary
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestStep
4+
commands:
5+
# Ensure that the metrics endpoint is available from inside the exporter container
6+
- script: |
7+
name=$(kubectl -n ${NAMESPACE} get pods --no-headers -o custom-columns="name:{metadata.name}" \
8+
--selector='postgres-operator.crunchydata.com/cluster=exporter,postgres-operator.crunchydata.com/instance-set=instance1')
9+
kubectl -n ${NAMESPACE} exec $name -it -c exporter -- curl http://localhost:9187/metrics
10+
# Ensure that the ccp_monitoring user exits in the database
11+
- script: |
12+
name=$(kubectl -n ${NAMESPACE} get pods --no-headers -o custom-columns="name:{metadata.name}" \
13+
--selector='postgres-operator.crunchydata.com/cluster=exporter,postgres-operator.crunchydata.com/instance-set=instance1')
14+
kubectl -n ${NAMESPACE} exec $name -it -c database -- \
15+
psql -c "DO \$\$
16+
DECLARE
17+
result boolean;
18+
BEGIN
19+
SELECT 1 from pg_roles where rolname='ccp_monitoring' INTO result;
20+
ASSERT result = 't', 'ccp_monitor not found';
21+
END \$\$;"

0 commit comments

Comments
 (0)