Skip to content

chore: add metrics test for NiFi 2.x #823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions tests/templates/kuttl/smoke_v2/50-install-test-nifi.yaml

This file was deleted.

78 changes: 78 additions & 0 deletions tests/templates/kuttl/smoke_v2/50-install-test-nifi.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: test-nifi
labels:
app: test-nifi
spec:
replicas: 1
selector:
matchLabels:
app: test-nifi
template:
metadata:
labels:
app: test-nifi
spec:
serviceAccountName: "tls-sa"
securityContext:
fsGroup: 1000
containers:
- name: test-nifi
image: oci.stackable.tech/sdp/testing-tools:0.2.0-stackable0.0.0-dev
command: ["sleep", "infinity"]
resources:
requests:
memory: "128Mi"
cpu: "100m"
limits:
memory: "128Mi"
cpu: "400m"
volumeMounts:
- name: tls
mountPath: /stackable/tls
volumes:
- name: tls
ephemeral:
volumeClaimTemplate:
metadata:
annotations:
secrets.stackable.tech/class: tls
secrets.stackable.tech/scope: pod
spec:
storageClassName: secrets.stackable.tech
accessModes:
- ReadWriteOnce
resources:
requests:
storage: "1"
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: tls-sa
{% if test_scenario['values']['openshift'] == 'true' %}
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: use-integration-tests-scc
rules:
- apiGroups: ["security.openshift.io"]
resources: ["securitycontextconstraints"]
resourceNames: ["privileged"]
verbs: ["use"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: use-integration-tests-scc
subjects:
- kind: ServiceAccount
name: tls-sa
roleRef:
kind: Role
name: use-integration-tests-scc
apiGroup: rbac.authorization.k8s.io
{% endif %}
1 change: 1 addition & 0 deletions tests/templates/kuttl/smoke_v2/60-assert.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ kind: TestAssert
timeout: 300
commands:
- script: kubectl exec -n $NAMESPACE test-nifi-0 -- python /tmp/test_nifi.py -u admin -p 'passwordWithSpecialCharacter\@<&>"'"'" -n $NAMESPACE -c 3
- script: kubectl exec -n $NAMESPACE test-nifi-0 -- python /tmp/test_nifi_metrics.py -n $NAMESPACE
1 change: 1 addition & 0 deletions tests/templates/kuttl/smoke_v2/60-prepare-test-nifi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: kubectl cp -n $NAMESPACE ./test_nifi_metrics.py test-nifi-0:/tmp
- script: kubectl cp -n $NAMESPACE ./test_nifi.py test-nifi-0:/tmp
- script: kubectl cp -n $NAMESPACE ./cacert.pem test-nifi-0:/tmp
67 changes: 67 additions & 0 deletions tests/templates/kuttl/smoke_v2/test_nifi_metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python
import requests
import time
import argparse

if __name__ == "__main__":
# Construct an argument parser
all_args = argparse.ArgumentParser()

# Add arguments to the parser
all_args.add_argument(
"-m",
"--metric",
required=False,
default="nifi_amount_bytes_read",
help="The name of a certain metric to check",
)
all_args.add_argument(
"-n", "--namespace", required=True, help="The namespace the test is running in"
)
all_args.add_argument(
"-p",
"--port",
required=False,
default="8443",
help="The port where metrics are exposed",
)
all_args.add_argument(
"-t",
"--timeout",
required=False,
default="120",
help="The timeout in seconds to wait for the metrics port to be opened",
)

args = vars(all_args.parse_args())
metric_name = args["metric"]
namespace = args["namespace"]
port = args["port"]
timeout = int(args["timeout"])

url = f"https://nifi-node-default-metrics.{args['namespace']}.svc.cluster.local:{port}/nifi-api/flow/metrics/prometheus"

# wait for 'timeout' seconds
t_end = time.time() + timeout
while time.time() < t_end:
try:
response = requests.get(
url,
cert=("/stackable/tls/tls.crt", "/stackable/tls/tls.key"),
verify="/stackable/tls/ca.crt",
)
response.raise_for_status()
if metric_name in response.text:
print("Test metrics succeeded!")
exit(0)
else:
print(
f"Could not find metric [{metric_name}] in response:\n {response.text}"
)
time.sleep(timeout)
except ConnectionError:
# NewConnectionError is expected until metrics are available
time.sleep(10)

print("Test failed")
exit(-1)