Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions hack/preflight-refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

Exit 1 if any reference is unresolvable.
"""
import base64, json, os, re, sys, urllib.error, urllib.request
import base64, json, os, re, sys, time, urllib.error, urllib.request

import yaml

Expand Down Expand Up @@ -52,14 +52,33 @@ def is_placeholder_ref(host, path):

def ghcr_token(repo):
url = "https://%s/token?scope=repository:%s:pull" % ("ghcr.io", repo)
try:
with urllib.request.urlopen(url, timeout=TIMEOUT) as r:
return json.load(r).get("token", "")
except Exception:
return ""
for delay in (0, 3, 8): # a token endpoint that errors once is not a missing package
time.sleep(delay)
try:
with urllib.request.urlopen(url, timeout=TIMEOUT) as r:
return json.load(r).get("token", "")
except Exception:
pass
return ""


def registry_get(host, repo, ref):
"""registry_get_once, retried when the answer says the NETWORK failed, not the registry.

Status 0 (no HTTP response at all: reset, timeout, DNS) and 429/5xx are the registry or the
runner's path to it having a bad moment; 401 and 404 are answers about the reference and are
never retried, so a missing or private package still fails on the first try.
"""
st = 0
for delay in (0, 3, 8):
time.sleep(delay)
st = registry_get_once(host, repo, ref)
if not (st == 0 or st == 429 or st >= 500):
return st
return st


def registry_get_once(host, repo, ref):
"""HEAD-ish GET of a manifest, ANONYMOUSLY. Returns HTTP status.

401 counts as a failure and that is deliberate: the child's kubelet and core-provider
Expand Down
57 changes: 51 additions & 6 deletions tests/clickstack-upgrade-kind.py
Original file line number Diff line number Diff line change
Expand Up @@ -1340,14 +1340,59 @@ def main():
"apiVersion": "v1", "kind": "ConfigMap",
"metadata": {"name": "e2e-dashboard", "namespace": NS, "labels": {"hyperdx.io/dashboard": "true"}},
"data": {"e2e-provisioned.json": json.dumps({"name": "e2e-provisioned", "tiles": [], "tags": ["e2e"]})}}))
# The sidecar syncs first, then the provisioner's minute tick writes the dashboard; then a further
# minute and a half so a ConfigMap it was going to read would have been.
wait("the provisioner to write the dashboard",
lambda: "Created provisioned dashboard" in kube.kn("logs", name, "-c", "app").stdout, timeout=420, every=10)
# The real condition is the dashboard in HyperDX, not a log line in THIS pod: the old release
# (0.1.67 on) ran the same provisioner, and the team is registered seconds before the upgrade, so
# the old pod, still serving while the new one starts (about two minutes), can create the dashboard
# in a tick of its own, and the new pod then has nothing to "Create". (Run 46986599979 waited
# 420 s for a "Created" line that this pod was never going to log.) So: wait for the dashboard to
# exist (bound: watcher sync + one minute tick + slack, with the pod already Ready); delete it; and
# require THIS pod to create it again, within one tick + the same slack. That proves this pod's
# watcher and provisioner whoever created it first.
def dump(why):
print(f" {why}: diagnostics")
for c in ("app", "dashboard-watcher"):
r = kube.kn("logs", name, "-c", c, check_=False)
lines = (r.stdout or r.stderr).splitlines()
print(f" {c} log, {len(lines)} lines, last 60:")
for l in lines[-60:]:
print(f" | {l[:300]}")
print(f" pod {name} started {p['status'].get('startTime')}, now {time.strftime('%H:%M:%S', time.gmtime())}Z")

hxp = HyperDX(kube, email, password)
try:
hxp.register_or_login(register=False)

def slo_dashboards():
st, ds = hxp.v2("GET", "/dashboards", key=key)
return [d for d in ds if d["name"] == "CMP performance SLOs"] if st == 200 else False

try:
wait("the dashboard CMP performance SLOs to exist in HyperDX", slo_dashboards, timeout=240, every=10)
except SystemExit:
dump("the dashboard never appeared")
raise
def created_lines():
# pino logs {"name":"CMP performance SLOs","msg":"Created provisioned dashboard"}
return sum(1 for l in kube.kn("logs", name, "-c", "app").stdout.splitlines()
if "Created provisioned dashboard" in l and "CMP performance SLOs" in l)

created_before = created_lines()
print(f" the dashboard exists; this pod has logged Created {created_before} time(s) so far")
for d in slo_dashboards():
st, _ = hxp.v2("DELETE", f"/dashboards/{d['id']}", key=key)
check(st in (200, 204), f"deleted the provisioned dashboard {d['id']} (HTTP {st})")
try:
wait("this pod's provisioner to create the deleted dashboard again",
lambda: created_lines() > created_before and slo_dashboards(),
timeout=150, every=5)
except SystemExit:
dump("the provisioner did not re-create the dashboard")
raise
finally:
hxp.close()
time.sleep(90)
log = kube.kn("logs", name, "-c", "app").stdout
check("Created provisioned dashboard" in log and "CMP performance SLOs" in log,
"the provisioner logged Created provisioned dashboard for CMP performance SLOs")
check(created_lines() >= 1, "the provisioner logged Created provisioned dashboard for CMP performance SLOs")
check("Skipping invalid dashboard file" not in log, "and skipped no dashboard file as invalid")
ps = kube.kn("exec", name, "-c", "app", "--", "sh", "-c", "ps -eo args 2>/dev/null || ps").stdout
check("provision-dashboards" in ps, "the provision-dashboards process runs")
Expand Down
Loading