|
| 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 | + if "coordinator" in url: |
| 17 | + r = requests.get( |
| 18 | + url, |
| 19 | + timeout=5, |
| 20 | + headers={"x-trino-user": "admin"}, |
| 21 | + auth=("admin", "admin"), |
| 22 | + verify=False, |
| 23 | + ) |
| 24 | + else: |
| 25 | + r = requests.get( |
| 26 | + url, timeout=5, headers={"x-trino-user": "admin"}, verify=False |
| 27 | + ) |
| 28 | + r.raise_for_status() |
| 29 | + return r |
| 30 | + except requests.exceptions.HTTPError as errh: |
| 31 | + print_request_error_and_sleep("Http Error: ", errh, i) |
| 32 | + except requests.exceptions.ConnectionError as errc: |
| 33 | + print_request_error_and_sleep("Error Connecting: ", errc, i) |
| 34 | + except requests.exceptions.Timeout as errt: |
| 35 | + print_request_error_and_sleep("Timeout Error: ", errt, i) |
| 36 | + except requests.exceptions.RequestException as err: |
| 37 | + print_request_error_and_sleep("Error: ", err, i) |
| 38 | + |
| 39 | + exit(-1) |
| 40 | + |
| 41 | + |
| 42 | +def check_monitoring(hosts): |
| 43 | + for host in hosts: |
| 44 | + # test for the jmx exporter metrics |
| 45 | + url = "http://" + host + ":8081/metrics" |
| 46 | + response = try_get(url) |
| 47 | + |
| 48 | + if not response.ok: |
| 49 | + print("Error for [" + url + "]: could not access monitoring") |
| 50 | + exit(-1) |
| 51 | + |
| 52 | + # test for the native metrics |
| 53 | + url = "https://" + host + ":8443/metrics" |
| 54 | + response = try_get(url) |
| 55 | + |
| 56 | + if response.ok: |
| 57 | + # arbitrary metric was chosen to test if metrics are present in the response |
| 58 | + if "io_airlift_node_name_NodeInfo_StartTime" in response.text: |
| 59 | + continue |
| 60 | + else: |
| 61 | + print("Error for [" + url + "]: missing metrics") |
| 62 | + exit(-1) |
| 63 | + else: |
| 64 | + print("Error for [" + url + "]: could not access monitoring") |
| 65 | + exit(-1) |
| 66 | + |
| 67 | + |
| 68 | +if __name__ == "__main__": |
| 69 | + all_args = argparse.ArgumentParser(description="Test Trino metrics.") |
| 70 | + all_args.add_argument( |
| 71 | + "-n", "--namespace", help="The namespace to run in", required=True |
| 72 | + ) |
| 73 | + args = vars(all_args.parse_args()) |
| 74 | + namespace = args["namespace"] |
| 75 | + |
| 76 | + host_coordinator_0 = f"trino-coordinator-default-0.trino-coordinator-default.{namespace}.svc.cluster.local" |
| 77 | + host_worker_0 = ( |
| 78 | + f"trino-worker-default-0.trino-worker-default.{namespace}.svc.cluster.local" |
| 79 | + ) |
| 80 | + |
| 81 | + hosts = [host_coordinator_0, host_worker_0] |
| 82 | + |
| 83 | + check_monitoring(hosts) |
| 84 | + |
| 85 | + print("Test check-metrics.py succeeded!") |
0 commit comments