-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_page.py
70 lines (59 loc) · 2.49 KB
/
generate_page.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import datetime
import json
from http import HTTPStatus
from pathlib import Path
import urllib.request
from string import Template
ICON_OK = "✅"
ICON_WARN = "⚠️"
ICON_ERROR = "❌"
MSG_OK = "Normal"
MSG_WARN = "Limited Availability"
MSG_ERROR = "Unavailable"
TEMPLATE_FILE = Path(__file__).parent / "status_page_template.html"
OUTPUT_FILE = Path(__file__).parent / "build" / "index.html"
def default_check(url: str) -> tuple[str, str]:
response = urllib.request.urlopen(url)
if response.code != HTTPStatus.OK:
return ICON_ERROR, MSG_ERROR
return ICON_OK, MSG_OK
def frontend_check(url: str) -> tuple[str, str]:
response = urllib.request.urlopen(url)
if response.code != HTTPStatus.OK:
return ICON_ERROR, MSG_ERROR
if "<title>OpenML</title>" in response.fp.read().decode("utf-8"):
return ICON_OK, MSG_OK
return ICON_WARN, "Server reachable, website unavailable."
def elastic_search_check(url: str) -> tuple[str, str]:
response = urllib.request.urlopen(url)
if response.code != HTTPStatus.OK:
return ICON_ERROR, MSG_ERROR
status = json.load(response)
match status:
case {"status": "green"}:
return ICON_OK, MSG_OK
case {"status": "yellow", "unassigned_shards": n}:
return ICON_OK, MSG_OK # Current Production is permanently yellow. Nothing to worry about.
case {"status": "red", "unassigned_shards": n}:
return ICON_ERROR, "Index and search operations may fail."
case _:
return ICON_ERROR, "Unknown error while fetching cluster health."
if __name__ == "__main__":
template_page = Template(TEMPLATE_FILE.read_text())
checks = {
("WEBSITE", "https://www.openml.org/"): frontend_check,
("MINIO", "https://data.openml.org/minio/health/live"): default_check,
("REST", "https://www.openml.org/api/v1/json/evaluationmeasure/list"): default_check,
("TEST", "https://test.openml.org/"): frontend_check,
("ES", "https://es.openml.org/_cluster/health?wait_for_status=yellow&timeout=10s&pretty"): elastic_search_check,
}
statuses = {}
for (name, url), check in checks.items():
icon, msg = check(url)
statuses.update({f"{name}_STATUS": msg, f"{name}_STATUS_ICON": icon})
now = datetime.datetime.now(datetime.timezone.utc)
timestamp = now.isoformat(sep=" ", timespec="seconds")
statuses["TIMESTAMP"] = timestamp[:-len("+00:00")]
OUTPUT_FILE.write_text(
template_page.substitute(**statuses)
)