Skip to content

Commit 3c85e10

Browse files
committed
Add kuttl tests for lightspeed-app-server /metrics endpoint
The kuttl test asserts that the endpoint is reachable and responds with a valid Prometheus format.
1 parent e2975e3 commit 3c85e10

6 files changed

Lines changed: 88 additions & 0 deletions

File tree

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestAssert
4+
commands:
5+
- script: |
6+
#!/bin/bash
7+
set -euo pipefail
8+
9+
NAMESPACE="openstack-lightspeed"
10+
CONTAINER="lightspeed-service-api"
11+
METRICS_PORT=8443
12+
METRICS_PATH="/metrics"
13+
SA_NAME="lightspeed-metrics-test"
14+
15+
echo "Creating test ServiceAccount and RBAC for metrics access..."
16+
oc create serviceaccount "$SA_NAME" -n "$NAMESPACE" --dry-run=client -o yaml | oc apply -f -
17+
cat <<EOF | oc apply -f -
18+
apiVersion: rbac.authorization.k8s.io/v1
19+
kind: ClusterRole
20+
metadata:
21+
name: ${SA_NAME}-role
22+
rules:
23+
- nonResourceURLs: ["/ls-access"]
24+
verbs: ["get"]
25+
---
26+
apiVersion: rbac.authorization.k8s.io/v1
27+
kind: ClusterRoleBinding
28+
metadata:
29+
name: ${SA_NAME}-binding
30+
roleRef:
31+
apiGroup: rbac.authorization.k8s.io
32+
kind: ClusterRole
33+
name: ${SA_NAME}-role
34+
subjects:
35+
- kind: ServiceAccount
36+
name: ${SA_NAME}
37+
namespace: ${NAMESPACE}
38+
EOF
39+
40+
echo "Getting bearer token..."
41+
TOKEN="$(oc create token "$SA_NAME" -n "$NAMESPACE")"
42+
43+
echo "Waiting for lightspeed-stack-deployment pod to be ready..."
44+
oc wait --for=condition=Ready pod \
45+
-l app.kubernetes.io/name=openstack-lightspeed-app-server \
46+
-n "$NAMESPACE" \
47+
--timeout=120s
48+
49+
echo "Getting pod name..."
50+
POD_NAME="$(oc get pods \
51+
-l app.kubernetes.io/name=openstack-lightspeed-app-server \
52+
-n "$NAMESPACE" \
53+
-o jsonpath='{.items[0].metadata.name}')"
54+
55+
if [ -z "$POD_NAME" ]; then
56+
echo "ERROR: No pod found for lightspeed-app-server"
57+
exit 1
58+
fi
59+
60+
echo "Fetching metrics from pod $POD_NAME (container: $CONTAINER)..."
61+
METRICS_OUTPUT="$(oc exec -n "$NAMESPACE" "$POD_NAME" \
62+
-c "$CONTAINER" -- \
63+
curl -sk -H "Authorization: Bearer ${TOKEN}" \
64+
"https://localhost:${METRICS_PORT}${METRICS_PATH}")"
65+
66+
if [ -z "$METRICS_OUTPUT" ]; then
67+
echo "ERROR: Empty response from /metrics endpoint"
68+
exit 1
69+
fi
70+
71+
echo "Validating response is valid Prometheus exposition format..."
72+
if ! echo "$METRICS_OUTPUT" | grep -q "^# HELP "; then
73+
echo "ERROR: Response does not contain Prometheus HELP declarations"
74+
echo "Response (first 500 chars):"
75+
echo "$METRICS_OUTPUT" | head -c 500
76+
exit 1
77+
fi
78+
79+
if ! echo "$METRICS_OUTPUT" | grep -q "^# TYPE "; then
80+
echo "ERROR: Response does not contain Prometheus TYPE declarations"
81+
echo "Response (first 500 chars):"
82+
echo "$METRICS_OUTPUT" | head -c 500
83+
exit 1
84+
fi
85+
86+
echo "Metrics endpoint is reachable and returns valid Prometheus format"
87+
timeout: 180
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../common/openstack-lightspeed-instance/assert-metrics-endpoint.yaml

test/kuttl/tests/basic-openstack-lightspeed-configuration/07-cleanup-openstack-lightspeed-instance.yaml renamed to test/kuttl/tests/basic-openstack-lightspeed-configuration/08-cleanup-openstack-lightspeed-instance.yaml

File renamed without changes.

test/kuttl/tests/basic-openstack-lightspeed-configuration/08-errors-openstack-lightspeed-instance.yaml renamed to test/kuttl/tests/basic-openstack-lightspeed-configuration/09-errors-openstack-lightspeed-instance.yaml

File renamed without changes.

test/kuttl/tests/basic-openstack-lightspeed-configuration/09-cleanup-mock-objects.yaml renamed to test/kuttl/tests/basic-openstack-lightspeed-configuration/10-cleanup-mock-objects.yaml

File renamed without changes.

test/kuttl/tests/basic-openstack-lightspeed-configuration/10-errors-mock-objects.yaml renamed to test/kuttl/tests/basic-openstack-lightspeed-configuration/11-errors-mock-objects.yaml

File renamed without changes.

0 commit comments

Comments
 (0)