Repository navigation
Expand file tree
/
Copy pathgenerate-build-farm-monitor-config.py
More file actions
228 lines (205 loc) · 8.94 KB
/
Copy pathgenerate-build-farm-monitor-config.py
File metadata and controls
228 lines (205 loc) · 8.94 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/env python3
# Regenerates build-farm entries in ship-status configs from _clusters.yaml.
# Run from repo root.
import sys
import yaml
# Console URLs must match blackbox targets (see clusters/app.ci/.../blackbox_probe.yaml).
# Clusters with blocked: true in _clusters.yaml are emitted as commented YAML blocks.
CONSOLE_URLS = {
"build01": "https://console.build01.ci.openshift.org",
"build02": "https://console.build02.ci.openshift.org",
"build03": "https://console-openshift-console.apps.build03.ci.devcluster.openshift.com",
"build04": "https://console.build04.ci.openshift.org",
"build05": "https://console-openshift-console.apps.build05.ci.devcluster.openshift.com",
"build06": "https://console-openshift-console.apps.build06.ci.devcluster.openshift.com",
"build07": "https://console-openshift-console.apps.build07.ci.devcluster.openshift.com",
"build08": "https://console.build08.ci.openshift.org",
"build09": "https://console-openshift-console.apps.build09.ci.devcluster.openshift.com",
"build10": "https://console-openshift-console.apps.build10.ci.devcluster.openshift.com",
"build11": "https://console-openshift-console.apps.build11.ci.devcluster.openshift.com",
"build12": "https://console-openshift-console.apps.build12.ci.devcluster.openshift.com",
"build13": "https://console.build13.ci.openshift.org",
"hosted-mgmt": "https://console-openshift-console.apps.hosted-mgmt.ci.devcluster.openshift.com",
}
BUILD_ORDER = [f"build{i:02d}" for i in range(1, 14)]
MGMT_CLUSTERS = ["hosted-mgmt"]
CLUSTER_ORDER = BUILD_ORDER + MGMT_CLUSTERS
def splice(path, begin, end, body):
with open(path, encoding="utf-8") as fh:
t = fh.read()
bi, ei = t.find(begin), t.find(end)
if bi == -1 or ei == -1:
sys.exit(f"markers not found in {path}")
with open(path, "w", encoding="utf-8") as fh:
fh.write(t[:bi] + begin + body + end + t[ei + len(end) :])
def yaml_comment_block(body: str) -> str:
out = []
for line in body.splitlines(keepends=True):
if line.endswith("\n"):
core, nl = line[:-1], "\n"
else:
core, nl = line, ""
if core.strip() == "":
out.append("#\n")
else:
out.append("# " + core + nl)
return "".join(out)
def monitor_entry(cluster_name: str, console_url: str) -> str:
return f"""\
- component_slug: "build-farm"
sub_component_slug: "{cluster_name}"
prometheus_monitor:
prometheus_location:
cluster: "app.ci"
namespace: "openshift-monitoring"
route: "thanos-querier"
queries:
- query: "probe_success{{job=\\"blackbox\\",instance=\\"{console_url}\\"}} > 0"
duration: "5m"
step: "30s"
severity: "Down"
- query: "rate(prowjob_state_transitions{{cluster=\\"{cluster_name}\\",state=\\"success\\"}}[2h]) > 0"
duration: "2h"
step: "5m"
severity: "Degraded"
junit_monitor:
job_name: "periodic-build-farm-canary-{cluster_name}"
max_age: "2h"
severity: "Degraded"
artifact_url_style: "gcs"
history_runs: 5
failed_runs_threshold: 3
- component_slug: "build-farm"
sub_component_slug: "{cluster_name}"
prometheus_monitor:
prometheus_location:
cluster: "{cluster_name}"
namespace: "openshift-monitoring"
route: "thanos-querier"
queries:
- query: "kube_deployment_status_replicas_available{{namespace=\\"openshift-machine-api\\",deployment=\\"cluster-autoscaler-default\\"}} > 0 or absent(kube_deployment_status_replicas_available{{namespace=\\"openshift-machine-api\\",deployment=\\"cluster-autoscaler-default\\"}})"
failure_query: "kube_deployment_status_replicas_available{{namespace=\\"openshift-machine-api\\",deployment=\\"cluster-autoscaler-default\\"}}"
duration: "5m"
step: "30s"
severity: "Degraded"
- query: "(increase(cluster_autoscaler_failed_scale_ups_total[30m]) or vector(0)) == 0"
failure_query: "increase(cluster_autoscaler_failed_scale_ups_total[30m])"
duration: "5m"
step: "1m"
severity: "Degraded"
- query: "(cluster_autoscaler_unschedulable_pods_count or vector(0)) <= 20"
failure_query: "cluster_autoscaler_unschedulable_pods_count"
duration: "15m"
step: "1m"
severity: "Degraded"
- query: "kube_deployment_status_replicas_available{{namespace=\\"ci-scheduling-webhook\\",deployment=\\"ci-scheduling-admission-webhook\\"}} > 0 or absent(kube_deployment_status_replicas_available{{namespace=\\"ci-scheduling-webhook\\",deployment=\\"ci-scheduling-admission-webhook\\"}})"
failure_query: "kube_deployment_status_replicas_available{{namespace=\\"ci-scheduling-webhook\\",deployment=\\"ci-scheduling-admission-webhook\\"}}"
duration: "5m"
step: "30s"
severity: "Degraded"
"""
def mgmt_monitor_entry(cluster_name: str, console_url: str) -> str:
return f"""\
- component_slug: "build-farm"
sub_component_slug: "{cluster_name}"
prometheus_monitor:
prometheus_location:
cluster: "app.ci"
namespace: "openshift-monitoring"
route: "thanos-querier"
queries:
- query: "probe_success{{job=\\"blackbox\\",instance=\\"{console_url}\\"}} > 0"
duration: "5m"
step: "30s"
severity: "Down"
- component_slug: "build-farm"
sub_component_slug: "{cluster_name}"
prometheus_monitor:
prometheus_location:
cluster: "{cluster_name}"
namespace: "openshift-monitoring"
route: "thanos-querier"
queries:
- query: "kube_deployment_status_replicas_available{{namespace=\\"openshift-machine-api\\",deployment=\\"cluster-autoscaler-default\\"}} > 0 or absent(kube_deployment_status_replicas_available{{namespace=\\"openshift-machine-api\\",deployment=\\"cluster-autoscaler-default\\"}})"
failure_query: "kube_deployment_status_replicas_available{{namespace=\\"openshift-machine-api\\",deployment=\\"cluster-autoscaler-default\\"}}"
duration: "5m"
step: "30s"
severity: "Degraded"
- query: "(increase(cluster_autoscaler_failed_scale_ups_total[30m]) or vector(0)) == 0"
failure_query: "increase(cluster_autoscaler_failed_scale_ups_total[30m])"
duration: "5m"
step: "1m"
severity: "Degraded"
- query: "(cluster_autoscaler_unschedulable_pods_count or vector(0)) <= 20"
failure_query: "cluster_autoscaler_unschedulable_pods_count"
duration: "15m"
step: "1m"
severity: "Degraded"
"""
def dash_entry(cluster_name: str) -> str:
display = "Build" + cluster_name[5:]
return f"""\
- name: "{display}"
description: "Build cluster {cluster_name}"
monitoring:
frequency: 5m
component_monitor: "app-ci-component-monitor"
auto_resolve: true
requires_confirmation: false
"""
def mgmt_dash_entry(cluster_name: str) -> str:
display = "-".join(w.capitalize() for w in cluster_name.split("-"))
return f"""\
- name: "{display}"
description: "Management cluster {cluster_name}"
monitoring:
frequency: 5m
component_monitor: "app-ci-component-monitor"
auto_resolve: true
requires_confirmation: false
"""
with open("core-services/sanitize-prow-jobs/_clusters.yaml", encoding="utf-8") as f:
data = yaml.safe_load(f)
blocked_by_name = {
c["name"]: c.get("blocked", False) for entries in data.values() for c in entries if "name" in c
}
monitor_body = ""
dash_body = ""
for name in BUILD_ORDER:
if name not in CONSOLE_URLS:
continue
console = CONSOLE_URLS[name]
blocked = blocked_by_name.get(name, False)
if blocked:
monitor_body += yaml_comment_block(monitor_entry(name, console))
monitor_body += "#\n"
dash_body += yaml_comment_block(dash_entry(name))
dash_body += "#\n"
else:
monitor_body += monitor_entry(name, console)
dash_body += dash_entry(name)
for name in MGMT_CLUSTERS:
if name not in CONSOLE_URLS:
continue
console = CONSOLE_URLS[name]
monitor_body += mgmt_monitor_entry(name, console)
dash_body += mgmt_dash_entry(name)
splice(
"core-services/ship-status/component-monitor-config.yaml",
" # BEGIN: auto-generated build-farm entries (hack/generate-build-farm-monitor-config.py)\n",
" # END: auto-generated build-farm entries\n",
monitor_body,
)
splice(
"core-services/ship-status/dashboard-config.yaml",
" # BEGIN: auto-generated build-farm sub_components (hack/generate-build-farm-monitor-config.py)\n",
" # END: auto-generated build-farm sub_components\n",
dash_body,
)
for name in CLUSTER_ORDER:
if name not in CONSOLE_URLS:
continue
if blocked_by_name.get(name, False):
print(f" {name}: commented-out (blocked in _clusters.yaml)")
else:
print(f" {name}: active")