Skip to content

Commit 0488267

Browse files
committed
chore: add test and docs for metrics
1 parent 54f80b5 commit 0488267

8 files changed

Lines changed: 206 additions & 0 deletions

File tree

docs/modules/trino/pages/usage-guide/monitoring.adoc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,38 @@
33

44
The managed Trino instances are automatically configured to export Prometheus metrics.
55
See xref:operators:monitoring.adoc[] for more details.
6+
7+
== Metrics
8+
9+
Trino automatically exposes built-in Prometheus metrics on coordinators and workers. The metrics are available on the `http` (`8080/metrics`) or
10+
`https` (`8443/metrics`) port, depending on the TLS settings.
11+
12+
The following `ServiceMonitor` example, demonstrates how the metrics could be scraped using the https://prometheus-operator.dev/[Prometheus Operator].
13+
14+
[source,yaml]
15+
----
16+
apiVersion: monitoring.coreos.com/v1
17+
kind: ServiceMonitor
18+
metadata:
19+
name: scrape-label
20+
spec:
21+
endpoints:
22+
- port: https # or http
23+
scheme: https # or http
24+
path: /metrics
25+
basicAuth: # <1>
26+
username:
27+
name: trino-user-secret
28+
key: username
29+
password:
30+
name: trino-user-secret
31+
key: password
32+
jobLabel: app.kubernetes.io/instance
33+
namespaceSelector:
34+
any: true
35+
selector:
36+
matchLabels:
37+
prometheus.io/scrape: "true"
38+
----
39+
40+
<1> Add user information if Trino is configuration to use authentication

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ commands:
66
- script: kubectl exec -n $NAMESPACE trino-test-helper-0 -- python /tmp/check-active-workers.py -u admin -p admin -n $NAMESPACE -w 1
77
- script: kubectl exec -n $NAMESPACE trino-test-helper-0 -- python /tmp/check-opa.py -n $NAMESPACE
88
- script: kubectl exec -n $NAMESPACE trino-test-helper-0 -- python /tmp/check-s3.py -n $NAMESPACE
9+
- script: kubectl exec -n $NAMESPACE trino-test-helper-0 -- python /tmp/check-metrics.py -n $NAMESPACE

tests/templates/kuttl/smoke/21-copy-scripts.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ commands:
55
- script: kubectl cp -n $NAMESPACE ./check-active-workers.py trino-test-helper-0:/tmp || true
66
- script: kubectl cp -n $NAMESPACE ./check-opa.py trino-test-helper-0:/tmp || true
77
- script: kubectl cp -n $NAMESPACE ./check-s3.py trino-test-helper-0:/tmp || true
8+
- script: kubectl cp -n $NAMESPACE ./check-metrics.py trino-test-helper-0:/tmp || true

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ commands:
66
- script: kubectl exec -n $NAMESPACE trino-test-helper-0 -- python /tmp/check-active-workers.py -u admin -p admin -n $NAMESPACE -w 2
77
- script: kubectl exec -n $NAMESPACE trino-test-helper-0 -- python /tmp/check-opa.py -n $NAMESPACE
88
- script: kubectl exec -n $NAMESPACE trino-test-helper-0 -- python /tmp/check-s3.py -n $NAMESPACE
9+
- script: kubectl exec -n $NAMESPACE trino-test-helper-0 -- python /tmp/check-metrics.py -n $NAMESPACE
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
import requests
4+
import time
5+
6+
7+
def print_request_error_and_sleep(message, err, retry_count):
8+
print("[" + str(retry_count) + "] " + message, err)
9+
time.sleep(5)
10+
11+
12+
def try_get(url):
13+
retries = 3
14+
for i in range(retries):
15+
try:
16+
r = requests.get(url, timeout=5, auth=("trino", ""))
17+
r.raise_for_status()
18+
return r
19+
except requests.exceptions.HTTPError as errh:
20+
print_request_error_and_sleep("Http Error: ", errh, i)
21+
except requests.exceptions.ConnectionError as errc:
22+
print_request_error_and_sleep("Error Connecting: ", errc, i)
23+
except requests.exceptions.Timeout as errt:
24+
print_request_error_and_sleep("Timeout Error: ", errt, i)
25+
except requests.exceptions.RequestException as err:
26+
print_request_error_and_sleep("Error: ", err, i)
27+
28+
exit(-1)
29+
30+
31+
def check_monitoring(hosts):
32+
for host in hosts:
33+
# test for the jmx exporter metrics
34+
url = host + ":8081"
35+
response = try_get(url)
36+
37+
if response.ok:
38+
continue
39+
else:
40+
print("Error for [" + url + "]: could not access monitoring")
41+
exit(-1)
42+
43+
# test for the native metrics
44+
url = host + ":8443/metrics"
45+
response = try_get(url)
46+
47+
if response.ok:
48+
# arbitrary metric was chosen to test if metrics are present in the response
49+
if "io_airlift_node_name_NodeInfo_StartTime" in response.text:
50+
continue
51+
else:
52+
print("Error for [" + url + "]: missing metrics")
53+
exit(-1)
54+
continue
55+
else:
56+
print("Error for [" + url + "]: could not access monitoring")
57+
exit(-1)
58+
59+
60+
if __name__ == "__main__":
61+
all_args = argparse.ArgumentParser(description="Test Trino metrics.")
62+
all_args.add_argument(
63+
"-n", "--namespace", help="The namespace to run in", required=True
64+
)
65+
args = vars(all_args.parse_args())
66+
namespace = args["namespace"]
67+
68+
host_coordinator_0 = (
69+
"http://trino-coordinator-default-0.trino-coordinator-default."
70+
+ namespace
71+
+ ".svc.cluster.local"
72+
)
73+
host_worker_0 = (
74+
"http://trino-worker-default-0.trino-worker-default."
75+
+ namespace
76+
+ ".svc.cluster.local"
77+
)
78+
79+
hosts = [host_coordinator_0, host_worker_0]
80+
81+
check_monitoring(hosts)
82+
83+
print("Test check-metrics.py succeeded!")

tests/templates/kuttl/smoke_aws/21-assert.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ commands:
66
- script: kubectl exec -n $NAMESPACE trino-test-helper-0 -- python /tmp/check-active-workers.py -u admin -p admin -n $NAMESPACE -w 1
77
- script: kubectl exec -n $NAMESPACE trino-test-helper-0 -- python /tmp/check-opa.py -n $NAMESPACE
88
- script: kubectl exec -n $NAMESPACE trino-test-helper-0 -- python /tmp/check-s3.py -n $NAMESPACE
9+
- script: kubectl exec -n $NAMESPACE trino-test-helper-0 -- python /tmp/check-metrics.py -n $NAMESPACE

tests/templates/kuttl/smoke_aws/21-copy-scripts.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ commands:
55
- script: kubectl cp -n $NAMESPACE ./check-active-workers.py trino-test-helper-0:/tmp || true
66
- script: kubectl cp -n $NAMESPACE ./check-opa.py trino-test-helper-0:/tmp || true
77
- script: kubectl cp -n $NAMESPACE ./check-s3.py trino-test-helper-0:/tmp || true
8+
- script: kubectl cp -n $NAMESPACE ./check-metrics.py trino-test-helper-0:/tmp || true
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
import requests
4+
import time
5+
6+
7+
def print_request_error_and_sleep(message, err, retry_count):
8+
print("[" + str(retry_count) + "] " + message, err)
9+
time.sleep(5)
10+
11+
12+
def try_get(url):
13+
retries = 3
14+
for i in range(retries):
15+
try:
16+
r = requests.get(url, timeout=5, auth=("trino", ""))
17+
r.raise_for_status()
18+
return r
19+
except requests.exceptions.HTTPError as errh:
20+
print_request_error_and_sleep("Http Error: ", errh, i)
21+
except requests.exceptions.ConnectionError as errc:
22+
print_request_error_and_sleep("Error Connecting: ", errc, i)
23+
except requests.exceptions.Timeout as errt:
24+
print_request_error_and_sleep("Timeout Error: ", errt, i)
25+
except requests.exceptions.RequestException as err:
26+
print_request_error_and_sleep("Error: ", err, i)
27+
28+
exit(-1)
29+
30+
31+
def check_monitoring(hosts):
32+
for host in hosts:
33+
# test for the jmx exporter metrics
34+
url = host + ":8081"
35+
response = try_get(url)
36+
37+
if response.ok:
38+
continue
39+
else:
40+
print("Error for [" + url + "]: could not access monitoring")
41+
exit(-1)
42+
43+
# test for the native metrics
44+
url = host + ":8443/metrics"
45+
response = try_get(url)
46+
47+
if response.ok:
48+
# arbitrary metric was chosen to test if metrics are present in the response
49+
if "io_airlift_node_name_NodeInfo_StartTime" in response.text:
50+
continue
51+
else:
52+
print("Error for [" + url + "]: missing metrics")
53+
exit(-1)
54+
continue
55+
else:
56+
print("Error for [" + url + "]: could not access monitoring")
57+
exit(-1)
58+
59+
60+
if __name__ == "__main__":
61+
all_args = argparse.ArgumentParser(description="Test Trino metrics.")
62+
all_args.add_argument(
63+
"-n", "--namespace", help="The namespace to run in", required=True
64+
)
65+
args = vars(all_args.parse_args())
66+
namespace = args["namespace"]
67+
68+
host_coordinator_0 = (
69+
"http://trino-coordinator-default-0.trino-coordinator-default."
70+
+ namespace
71+
+ ".svc.cluster.local"
72+
)
73+
host_worker_0 = (
74+
"http://trino-worker-default-0.trino-worker-default."
75+
+ namespace
76+
+ ".svc.cluster.local"
77+
)
78+
79+
hosts = [host_coordinator_0, host_worker_0]
80+
81+
check_monitoring(hosts)
82+
83+
print("Test check-metrics.py succeeded!")

0 commit comments

Comments
 (0)