Skip to content

Commit 03f7acd

Browse files
committed
Add kuttl test
1 parent c90f1e2 commit 03f7acd

30 files changed

+408
-20
lines changed

testing/kuttl/e2e/otel-logging-and-metrics/11--add-logs-exporter.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
apply:
4+
- files/11--add-per-db-metrics.yaml
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestAssert
3+
commands:
4+
# First, check that all containers in the instance pod are ready.
5+
# Then, grab the collector metrics output and check that the per-db metrics
6+
# are present for the single added target.
7+
- script: |
8+
retry() { bash -ceu 'printf "$1\nSleeping...\n" && sleep 5' - "$@"; }
9+
check_containers_ready() { bash -ceu 'echo "$1" | jq -e ".[] | select(.type==\"ContainersReady\") | .status==\"True\""' - "$@"; }
10+
contains() { bash -ceu '[[ "$1" == *"$2"* ]]' - "$@"; }
11+
12+
pod=$(kubectl get pods -o name -n "${NAMESPACE}" \
13+
-l postgres-operator.crunchydata.com/cluster=otel-cluster,postgres-operator.crunchydata.com/data=postgres)
14+
[ "$pod" = "" ] && retry "Pod not found" && exit 1
15+
16+
condition_json=$(kubectl get "${pod}" -n "${NAMESPACE}" -o jsonpath="{.status.conditions}")
17+
[ "$condition_json" = "" ] && retry "conditions not found" && exit 1
18+
{ check_containers_ready "$condition_json"; } || {
19+
retry "containers not ready"
20+
exit 1
21+
}
22+
23+
scrape_metrics=$(kubectl exec "${pod}" -c collector -n "${NAMESPACE}" -- \
24+
curl --insecure --silent http://localhost:9187/metrics)
25+
{ contains "${scrape_metrics}" 'ccp_table_size_bytes{dbname="pikachu"'; } || {
26+
retry "ccp_table_size_bytes not found for pikachu"
27+
exit 1
28+
}
29+
{ ! contains "${scrape_metrics}" 'ccp_table_size_bytes{dbname="onix"'; } || {
30+
retry "ccp_table_size_bytes found for onix"
31+
exit 1
32+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
apply:
4+
- files/13--add-per-db-metrics.yaml

testing/kuttl/e2e/otel-logging-and-metrics/13--cluster-no-backups.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestAssert
3+
commands:
4+
# First, check that all containers in the instance pod are ready.
5+
# Then, grab the collector metrics output and check that the per-db metrics
6+
# are present for both added targets.
7+
- script: |
8+
retry() { bash -ceu 'printf "$1\nSleeping...\n" && sleep 5' - "$@"; }
9+
check_containers_ready() { bash -ceu 'echo "$1" | jq -e ".[] | select(.type==\"ContainersReady\") | .status==\"True\""' - "$@"; }
10+
contains() { bash -ceu '[[ "$1" == *"$2"* ]]' - "$@"; }
11+
12+
pod=$(kubectl get pods -o name -n "${NAMESPACE}" \
13+
-l postgres-operator.crunchydata.com/cluster=otel-cluster,postgres-operator.crunchydata.com/data=postgres)
14+
[ "$pod" = "" ] && retry "Pod not found" && exit 1
15+
16+
condition_json=$(kubectl get "${pod}" -n "${NAMESPACE}" -o jsonpath="{.status.conditions}")
17+
[ "$condition_json" = "" ] && retry "conditions not found" && exit 1
18+
{ check_containers_ready "$condition_json"; } || {
19+
retry "containers not ready"
20+
exit 1
21+
}
22+
23+
scrape_metrics=$(kubectl exec "${pod}" -c collector -n "${NAMESPACE}" -- \
24+
curl --insecure --silent http://localhost:9187/metrics)
25+
{ contains "${scrape_metrics}" 'ccp_table_size_bytes{dbname="pikachu"'; } || {
26+
retry "ccp_table_size_bytes not found for pikachu"
27+
exit 1
28+
}
29+
{ contains "${scrape_metrics}" 'ccp_table_size_bytes{dbname="onix"'; } || {
30+
retry "ccp_table_size_bytes not found for onix"
31+
exit 1
32+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
apply:
4+
- files/15--remove-per-db-metrics.yaml
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestAssert
3+
commands:
4+
# First, check that all containers in the instance pod are ready.
5+
# Then, grab the collector metrics output and check that the per-db metrics
6+
# are absent from the targets since they've been removed.
7+
- script: |
8+
retry() { bash -ceu 'printf "$1\nSleeping...\n" && sleep 5' - "$@"; }
9+
check_containers_ready() { bash -ceu 'echo "$1" | jq -e ".[] | select(.type==\"ContainersReady\") | .status==\"True\""' - "$@"; }
10+
contains() { bash -ceu '[[ "$1" == *"$2"* ]]' - "$@"; }
11+
12+
pod=$(kubectl get pods -o name -n "${NAMESPACE}" \
13+
-l postgres-operator.crunchydata.com/cluster=otel-cluster,postgres-operator.crunchydata.com/data=postgres)
14+
[ "$pod" = "" ] && retry "Pod not found" && exit 1
15+
16+
condition_json=$(kubectl get "${pod}" -n "${NAMESPACE}" -o jsonpath="{.status.conditions}")
17+
[ "$condition_json" = "" ] && retry "conditions not found" && exit 1
18+
{ check_containers_ready "$condition_json"; } || {
19+
retry "containers not ready"
20+
exit 1
21+
}
22+
23+
scrape_metrics=$(kubectl exec "${pod}" -c collector -n "${NAMESPACE}" -- \
24+
curl --insecure --silent http://localhost:9187/metrics)
25+
{ ! contains "${scrape_metrics}" 'ccp_table_size_bytes{dbname="pikachu"'; } || {
26+
retry "ccp_table_size_bytes found for pikachu"
27+
exit 1
28+
}
29+
{ ! contains "${scrape_metrics}" 'ccp_table_size_bytes{dbname="onix"'; } || {
30+
retry "ccp_table_size_bytes found for onix"
31+
exit 1
32+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
apply:
4+
- files/17--add-custom-queries-per-db.yaml
5+
assert:
6+
- files/17-custom-queries-per-db-added.yaml
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestAssert
3+
commands:
4+
# First, check that all containers in the instance pod are ready.
5+
# Then, grab the collector metrics output and check that the two metrics that we
6+
# checked for earlier are no longer there.
7+
# Then, check that the two custom metrics that we added are present
8+
# only for the targets that were specified.
9+
- script: |
10+
retry() { bash -ceu 'printf "$1\nSleeping...\n" && sleep 5' - "$@"; }
11+
check_containers_ready() { bash -ceu 'echo "$1" | jq -e ".[] | select(.type==\"ContainersReady\") | .status==\"True\""' - "$@"; }
12+
contains() { bash -ceu '[[ "$1" == *"$2"* ]]' - "$@"; }
13+
14+
pod=$(kubectl get pods -o name -n "${NAMESPACE}" \
15+
-l postgres-operator.crunchydata.com/cluster=otel-cluster,postgres-operator.crunchydata.com/data=postgres)
16+
[ "$pod" = "" ] && retry "Pod not found" && exit 1
17+
18+
condition_json=$(kubectl get "${pod}" -n "${NAMESPACE}" -o jsonpath="{.status.conditions}")
19+
[ "$condition_json" = "" ] && retry "conditions not found" && exit 1
20+
{ check_containers_ready "$condition_json"; } || {
21+
retry "containers not ready"
22+
exit 1
23+
}
24+
25+
scrape_metrics=$(kubectl exec "${pod}" -c collector -n "${NAMESPACE}" -- \
26+
curl --insecure --silent http://localhost:9187/metrics)
27+
{ contains "${scrape_metrics}" 'ccp_table_size_bytes_1{dbname="pikachu"'; } || {
28+
retry "custom metric not found for pikachu db"
29+
exit 1
30+
}
31+
{ ! contains "${scrape_metrics}" 'ccp_table_size_bytes_1{dbname="onix"'; } || {
32+
retry "custom metric found for onix db"
33+
exit 1
34+
}
35+
{ contains "${scrape_metrics}" 'ccp_table_size_bytes_2{dbname="onix"'; } || {
36+
retry "custom metric not found for onix db"
37+
exit 1
38+
}
39+
{ ! contains "${scrape_metrics}" 'ccp_table_size_bytes_2{dbname="pikachu"'; } || {
40+
retry "custom metric found for pikachu db"
41+
exit 1
42+
}

0 commit comments

Comments
 (0)