Skip to content

Commit 1246c1f

Browse files
committed
chore: add metrics tests for NiFi 2.x
1 parent 362114c commit 1246c1f

4 files changed

Lines changed: 89 additions & 0 deletions

File tree

tests/templates/kuttl/smoke_v2/50-install-test-nifi.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ spec:
1515
labels:
1616
app: test-nifi
1717
spec:
18+
securityContext:
19+
fsGroup: 1000
1820
containers:
1921
- name: test-nifi
2022
image: oci.stackable.tech/sdp/testing-tools:0.2.0-stackable0.0.0-dev
@@ -26,3 +28,21 @@ spec:
2628
limits:
2729
memory: "128Mi"
2830
cpu: "400m"
31+
volumeMounts:
32+
- name: tls
33+
mountPath: /stackable/tls
34+
volumes:
35+
- name: tls
36+
ephemeral:
37+
volumeClaimTemplate:
38+
metadata:
39+
annotations:
40+
secrets.stackable.tech/class: tls
41+
secrets.stackable.tech/scope: pod
42+
spec:
43+
storageClassName: secrets.stackable.tech
44+
accessModes:
45+
- ReadWriteOnce
46+
resources:
47+
requests:
48+
storage: "1"

tests/templates/kuttl/smoke_v2/60-assert.yaml.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ kind: TestAssert
44
timeout: 300
55
commands:
66
- script: kubectl exec -n $NAMESPACE test-nifi-0 -- python /tmp/test_nifi.py -u admin -p 'passwordWithSpecialCharacter\@<&>"'"'" -n $NAMESPACE -c 3
7+
- script: kubectl exec -n $NAMESPACE test-nifi-0 -- python /tmp/test_nifi_metrics.py -n $NAMESPACE

tests/templates/kuttl/smoke_v2/60-prepare-test-nifi.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
apiVersion: kuttl.dev/v1beta1
33
kind: TestStep
44
commands:
5+
- script: kubectl cp -n $NAMESPACE ./test_nifi_metrics.py test-nifi-0:/tmp
56
- script: kubectl cp -n $NAMESPACE ./test_nifi.py test-nifi-0:/tmp
67
- script: kubectl cp -n $NAMESPACE ./cacert.pem test-nifi-0:/tmp
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python
2+
import requests
3+
import time
4+
import argparse
5+
6+
if __name__ == "__main__":
7+
# Construct an argument parser
8+
all_args = argparse.ArgumentParser()
9+
10+
# Add arguments to the parser
11+
all_args.add_argument(
12+
"-m",
13+
"--metric",
14+
required=False,
15+
default="nifi_amount_bytes_read",
16+
help="The name of a certain metric to check",
17+
)
18+
all_args.add_argument(
19+
"-n", "--namespace", required=True, help="The namespace the test is running in"
20+
)
21+
all_args.add_argument(
22+
"-p",
23+
"--port",
24+
required=False,
25+
default="8443",
26+
help="The port where metrics are exposed",
27+
)
28+
all_args.add_argument(
29+
"-t",
30+
"--timeout",
31+
required=False,
32+
default="120",
33+
help="The timeout in seconds to wait for the metrics port to be opened",
34+
)
35+
36+
args = vars(all_args.parse_args())
37+
metric_name = args["metric"]
38+
namespace = args["namespace"]
39+
port = args["port"]
40+
timeout = int(args["timeout"])
41+
42+
url = f"https://nifi-node-default-metrics.{args['namespace']}.svc.cluster.local:{port}/nifi-api/flow/metrics/prometheus"
43+
44+
# wait for 'timeout' seconds
45+
t_end = time.time() + timeout
46+
while time.time() < t_end:
47+
try:
48+
response = requests.get(
49+
url,
50+
cert=("/stackable/tls/tls.crt", "/stackable/tls/tls.key"),
51+
verify="/stackable/tls/ca.crt",
52+
)
53+
response.raise_for_status()
54+
if metric_name in response.text:
55+
print("Test metrics succeeded!")
56+
exit(0)
57+
else:
58+
print(
59+
f"Could not find metric [{metric_name}] in response:\n {response.text}"
60+
)
61+
time.sleep(timeout)
62+
except ConnectionError:
63+
# NewConnectionError is expected until metrics are available
64+
time.sleep(10)
65+
66+
print("Test failed")
67+
exit(-1)

0 commit comments

Comments
 (0)