Skip to content

Commit 889ca09

Browse files
committed
add metrics integration test
1 parent fc89544 commit 889ca09

3 files changed

Lines changed: 70 additions & 0 deletions

File tree

tests/templates/kuttl/smoke/50-assert.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ metadata:
55
name: test-hbase
66
commands:
77
- script: kubectl exec --namespace=$NAMESPACE hbase-test-runner-0 -- python /tmp/test-hbase.py http://test-hbase-restserver-default:8080
8+
- script: kubectl exec --namespace=$NAMESPACE hbase-test-runner-0 -- python /tmp/test_prometheus_metrics.py $NAMESPACE
89
timeout: 240

tests/templates/kuttl/smoke/50-test-hbase.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ apiVersion: kuttl.dev/v1beta1
33
kind: TestStep
44
commands:
55
- script: kubectl cp --namespace=$NAMESPACE ./test-hbase.py hbase-test-runner-0:/tmp
6+
- script: kubectl cp --namespace=$NAMESPACE ./test_prometheus_metrics.py hbase-test-runner-0:/tmp
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Fetch metrics from the built-in Prometheus endpoint of HDFS components.
2+
3+
import logging
4+
import sys
5+
6+
import requests
7+
8+
9+
def check_metrics(
10+
namespace: str, role: str, port: int, expected_metrics: list[str]
11+
) -> None:
12+
response: requests.Response = requests.get(
13+
f"http://test-hbase-{role}-default-0.test-hbase-{role}-default.{namespace}.svc.cluster.local:{port}/prometheus",
14+
timeout=10,
15+
)
16+
assert response.ok, "Requesting metrics failed"
17+
18+
# Split the response into lines to check for metric names at the beginning of each line.
19+
# This is a bit slower than using a regex but it allows to use special characters like "{}" in metric names
20+
# without needing to escape them.
21+
response_lines = response.text.splitlines()
22+
for metric in expected_metrics:
23+
# Use any() with a generator to stop early if the metric is found.
24+
assert any((line.startswith(metric) for line in response_lines)) is True, (
25+
f"Metric '{metric}' not found for {role}"
26+
)
27+
28+
29+
def check_master_metrics(
30+
namespace: str,
31+
) -> None:
32+
expected_metrics: list[str] = ["master_queue_size"]
33+
34+
check_metrics(namespace, "master", 16010, expected_metrics)
35+
36+
37+
def check_regionserver_metrics(
38+
namespace: str,
39+
) -> None:
40+
expected_metrics: list[str] = [
41+
"table_requests_namespace_hbase_table_meta_table_write_query_per_second_count"
42+
]
43+
44+
check_metrics(namespace, "regionserver", 16030, expected_metrics)
45+
46+
47+
def check_restserver_metrics(
48+
namespace: str,
49+
) -> None:
50+
expected_metrics: list[str] = ["ugi_metrics_get_groups_num_ops"]
51+
52+
check_metrics(namespace, "restserver", 8085, expected_metrics)
53+
54+
55+
if __name__ == "__main__":
56+
namespace_arg: str = sys.argv[1]
57+
58+
logging.basicConfig(
59+
level="DEBUG",
60+
format="%(asctime)s %(levelname)s: %(message)s",
61+
stream=sys.stdout,
62+
)
63+
64+
check_master_metrics(namespace_arg)
65+
check_regionserver_metrics(namespace_arg)
66+
check_restserver_metrics(namespace_arg)
67+
68+
print("All expected metrics found")

0 commit comments

Comments
 (0)