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 exit $RC
fi fi
PORTFILE=$(mktemp) PORTFILE=$(mktemp)
python3 ci/otelrecv.py --port-file="$PORTFILE" & python3 ci/otel-receiver.py --port-file="$PORTFILE" &
RECV_PID=$! RECV_PID=$!
cleanup() { cleanup() {
kill "$RECV_PID" 2>/dev/null kill -9 "$RECV_PID" 2>/dev/null || true
wait "$RECV_PID" 2>/dev/null || true
pkill -9 -f "otelrecv.py" 2>/dev/null || true
rm -f "$PORTFILE" "$DAGGER_OUT" "$RC_FILE" rm -f "$PORTFILE" "$DAGGER_OUT" "$RC_FILE"
} }
trap cleanup EXIT trap cleanup EXIT
@@ -307,6 +305,8 @@ tasks:
OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf" \ OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf" \
dagger call --progress=plain -q -m ci --source=. check dagger call --progress=plain -q -m ci --source=. check
RC=$? RC=$?
curl -sf "http://127.0.0.1:$PORT/shutdown" >/dev/null 2>&1 || true
wait "$RECV_PID" 2>/dev/null || true
exit $RC exit $RC
integration-android: integration-android:
+9 -5
View File
@@ -3,7 +3,7 @@
Minimal OTLP HTTP/protobuf trace receiver for Dagger CI timing. Minimal OTLP HTTP/protobuf trace receiver for Dagger CI timing.
Usage: Usage:
python3 ci/otelrecv.py --port-file=/tmp/otel.port python3 ci/otel-receiver.py --port-file=/tmp/otel.port
Caller sets: Caller sets:
OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:<port> OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:<port>
@@ -127,6 +127,12 @@ class _Handler(BaseHTTPRequestHandler):
if body: if body:
self.wfile.write(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): def do_POST(self):
if self.path != "/v1/traces": if self.path != "/v1/traces":
self._respond(404); return self._respond(404); return
@@ -135,7 +141,7 @@ class _Handler(BaseHTTPRequestHandler):
try: try:
decoded = _decode(body) decoded = _decode(body)
except Exception as exc: 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 self._respond(400, str(exc).encode()); return
with _lock: with _lock:
_spans.extend(decoded) _spans.extend(decoded)
@@ -150,7 +156,7 @@ class _Handler(BaseHTTPRequestHandler):
def _report(): def _report():
with _lock: with _lock:
if not _spans: if not _spans:
print("otelrecv: no spans received", file=sys.stderr) print("otel-receiver: no spans received", file=sys.stderr)
return return
rows = sorted(_spans, key=lambda r: r["dur"], reverse=True) rows = sorted(_spans, key=lambda r: r["dur"], reverse=True)
NAME_W = 38 NAME_W = 38
@@ -181,9 +187,7 @@ def main():
signal.signal(signal.SIGTERM, _shutdown) signal.signal(signal.SIGTERM, _shutdown)
signal.signal(signal.SIGINT, _shutdown) signal.signal(signal.SIGINT, _shutdown)
print(f"[otelrecv] listening on port {server.server_address[1]}", file=sys.stderr, flush=True)
server.serve_forever() server.serve_forever()
print("[otelrecv] server stopped, printing report", file=sys.stderr, flush=True)
_report() _report()