test(pki): measure container CPU and memory during lifecycle load
This commit is contained in:
@@ -6,6 +6,7 @@ import json
|
|||||||
import math
|
import math
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
|
import threading
|
||||||
import time
|
import time
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
from datetime import UTC, datetime
|
from datetime import UTC, datetime
|
||||||
@@ -50,6 +51,8 @@ def main():
|
|||||||
}
|
}
|
||||||
started = time.time()
|
started = time.time()
|
||||||
load = None
|
load = None
|
||||||
|
resource_stop = threading.Event()
|
||||||
|
resource_thread = None
|
||||||
lb_stopped = False
|
lb_stopped = False
|
||||||
bao_sealed = False
|
bao_sealed = False
|
||||||
with httpx.Client(
|
with httpx.Client(
|
||||||
@@ -93,6 +96,66 @@ def main():
|
|||||||
chat = r.json()["id"]
|
chat = r.json()["id"]
|
||||||
load = Workload(client, headers, chat)
|
load = Workload(client, headers, chat)
|
||||||
load.start()
|
load.start()
|
||||||
|
resource_ids = compose(
|
||||||
|
"ps", "-q", "api", "worker", "otel", "openbao"
|
||||||
|
).split()
|
||||||
|
report["resource_limits"] = [
|
||||||
|
{
|
||||||
|
"role": info["Config"]["Labels"][
|
||||||
|
"com.docker.compose.service"
|
||||||
|
],
|
||||||
|
"container": info["Name"],
|
||||||
|
"cpu_nano": info["HostConfig"]["NanoCpus"],
|
||||||
|
"memory_bytes": info["HostConfig"]["Memory"],
|
||||||
|
}
|
||||||
|
for info in json.loads(
|
||||||
|
command(["docker", "inspect", *resource_ids])
|
||||||
|
)
|
||||||
|
]
|
||||||
|
report["resource_measurement"] = (
|
||||||
|
"Docker stats snapshots: 15-second delay plus command duration; "
|
||||||
|
"CPU 100% is one core; memory is sampled usage, not an absolute peak"
|
||||||
|
)
|
||||||
|
report["resource_samples"] = []
|
||||||
|
|
||||||
|
def sample_resources():
|
||||||
|
while not resource_stop.is_set():
|
||||||
|
began = time.time()
|
||||||
|
try:
|
||||||
|
raw = command(
|
||||||
|
[
|
||||||
|
"docker",
|
||||||
|
"stats",
|
||||||
|
"--no-stream",
|
||||||
|
"--format",
|
||||||
|
"json",
|
||||||
|
*resource_ids,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
observations = [
|
||||||
|
json.loads(line) for line in raw.splitlines()
|
||||||
|
]
|
||||||
|
report["resource_samples"].append(
|
||||||
|
{
|
||||||
|
"started_at": began,
|
||||||
|
"ended_at": time.time(),
|
||||||
|
"phase": load.phase,
|
||||||
|
"containers": observations,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
except Exception as error:
|
||||||
|
report.setdefault(
|
||||||
|
"resource_sampling_errors", []
|
||||||
|
).append(
|
||||||
|
{
|
||||||
|
"at": began,
|
||||||
|
"error_type": type(error).__name__,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
resource_stop.wait(15)
|
||||||
|
|
||||||
|
resource_thread = threading.Thread(target=sample_resources)
|
||||||
|
resource_thread.start()
|
||||||
|
|
||||||
def renewal():
|
def renewal():
|
||||||
before = pki.metadata()
|
before = pki.metadata()
|
||||||
@@ -308,6 +371,11 @@ def main():
|
|||||||
report["failure_type"] = type(error).__name__
|
report["failure_type"] = type(error).__name__
|
||||||
raise
|
raise
|
||||||
finally:
|
finally:
|
||||||
|
resource_stop.set()
|
||||||
|
if resource_thread is not None:
|
||||||
|
resource_thread.join(15)
|
||||||
|
if resource_thread.is_alive():
|
||||||
|
report["resource_sampler_did_not_stop"] = True
|
||||||
if load is not None:
|
if load is not None:
|
||||||
load.close()
|
load.close()
|
||||||
report["request_statuses"] = dict(
|
report["request_statuses"] = dict(
|
||||||
|
|||||||
Reference in New Issue
Block a user