fix(ci): rename otelrecv→otel-receiver, fix teardown hang

Rename ci/otelrecv.py to ci/otel-receiver.py for readability.

Replace SIGTERM+wait shutdown (which could hang indefinitely) with an
HTTP-based approach: add GET /shutdown to otel-receiver.py that calls
self.server.shutdown() directly. After dagger call returns, curl that
endpoint so the receiver prints its timing report and exits cleanly.
Cleanup is reduced to a SIGKILL fallback in case the process is already
gone.

Also fix the do_GET handler to reference self.server instead of the
local variable server, which was inaccessible from the handler class.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Thomas SharedInbox
2026-05-21 15:18:34 +02:00
co-authored by Claude Sonnet 4.6
parent f2d24a8514
commit 041e496e58
2 changed files with 13 additions and 9 deletions
+4 -4
View File
@@ -291,12 +291,10 @@ tasks:
exit $RC
fi
PORTFILE=$(mktemp)
python3 ci/otelrecv.py --port-file="$PORTFILE" &
python3 ci/otel-receiver.py --port-file="$PORTFILE" &
RECV_PID=$!
cleanup() {
kill "$RECV_PID" 2>/dev/null
wait "$RECV_PID" 2>/dev/null || true
pkill -9 -f "otelrecv.py" 2>/dev/null || true
kill -9 "$RECV_PID" 2>/dev/null || true
rm -f "$PORTFILE" "$DAGGER_OUT" "$RC_FILE"
}
trap cleanup EXIT
@@ -307,6 +305,8 @@ tasks:
OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf" \
dagger call --progress=plain -q -m ci --source=. check
RC=$?
curl -sf "http://127.0.0.1:$PORT/shutdown" >/dev/null 2>&1 || true
wait "$RECV_PID" 2>/dev/null || true
exit $RC
integration-android:
+9 -5
View File
@@ -3,7 +3,7 @@
Minimal OTLP HTTP/protobuf trace receiver for Dagger CI timing.
Usage:
python3 ci/otelrecv.py --port-file=/tmp/otel.port
python3 ci/otel-receiver.py --port-file=/tmp/otel.port
Caller sets:
OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:<port>
@@ -127,6 +127,12 @@ class _Handler(BaseHTTPRequestHandler):
if body:
self.wfile.write(body)
def do_GET(self):
if self.path != "/shutdown":
self._respond(404); return
self._respond(200, b"shutting down")
threading.Thread(target=self.server.shutdown, daemon=True).start()
def do_POST(self):
if self.path != "/v1/traces":
self._respond(404); return
@@ -135,7 +141,7 @@ class _Handler(BaseHTTPRequestHandler):
try:
decoded = _decode(body)
except Exception as exc:
print(f"[otelrecv] decode error: {exc}", file=sys.stderr, flush=True)
print(f"[otel-receiver] decode error: {exc}", file=sys.stderr, flush=True)
self._respond(400, str(exc).encode()); return
with _lock:
_spans.extend(decoded)
@@ -150,7 +156,7 @@ class _Handler(BaseHTTPRequestHandler):
def _report():
with _lock:
if not _spans:
print("otelrecv: no spans received", file=sys.stderr)
print("otel-receiver: no spans received", file=sys.stderr)
return
rows = sorted(_spans, key=lambda r: r["dur"], reverse=True)
NAME_W = 38
@@ -181,9 +187,7 @@ def main():
signal.signal(signal.SIGTERM, _shutdown)
signal.signal(signal.SIGINT, _shutdown)
print(f"[otelrecv] listening on port {server.server_address[1]}", file=sys.stderr, flush=True)
server.serve_forever()
print("[otelrecv] server stopped, printing report", file=sys.stderr, flush=True)
_report()