From fd9d4799ee59477f03c805d33843ced62873512e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D1=81=D0=BB=D0=BE=D0=B2?= Date: Fri, 20 Nov 2026 21:34:26 +0300 Subject: [PATCH] test(pki): measure container CPU and memory during lifecycle load --- scripts/research_security.py | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/scripts/research_security.py b/scripts/research_security.py index d1d942c..91b514f 100644 --- a/scripts/research_security.py +++ b/scripts/research_security.py @@ -6,6 +6,7 @@ import json import math import socket import ssl +import threading import time from collections import Counter from datetime import UTC, datetime @@ -50,6 +51,8 @@ def main(): } started = time.time() load = None + resource_stop = threading.Event() + resource_thread = None lb_stopped = False bao_sealed = False with httpx.Client( @@ -93,6 +96,66 @@ def main(): chat = r.json()["id"] load = Workload(client, headers, chat) 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(): before = pki.metadata() @@ -308,6 +371,11 @@ def main(): report["failure_type"] = type(error).__name__ raise 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: load.close() report["request_statuses"] = dict(