Initial curated ITWorx_MCP_Hub source from 368fba691ea8d23403b4d56b53b5ec670d7c5020
This commit is contained in:
commit
cb5be898ea
663 files changed
+82674
No files matched your search
@@ -0,0 +1,25 @@
|
||||
# syntax=docker/dockerfile:1.7
|
||||
FROM python:3.13.14-slim@sha256:6771159cd4fa5d9bba1258caf0b82e6b73458c694d178ad97c5e925c2d0e1a91
|
||||
|
||||
COPY infrastructure/images/install-base-security-updates.sh /tmp/install-base-security-updates.sh
|
||||
RUN sh /tmp/install-base-security-updates.sh \
|
||||
&& rm /tmp/install-base-security-updates.sh
|
||||
|
||||
ARG GIT_REVISION
|
||||
ARG SOURCE_DATE_EPOCH
|
||||
ARG BUILD_DATE
|
||||
|
||||
RUN groupadd --gid 10001 hub \
|
||||
&& useradd --uid 10001 --gid 10001 --create-home --shell /usr/sbin/nologin hub
|
||||
COPY infrastructure/images/observability/collector.py /opt/hub/collector.py
|
||||
RUN chown -R 10001:10001 /opt/hub
|
||||
|
||||
LABEL org.opencontainers.image.title="itworx-mcp-hub-observability-collector" \
|
||||
org.opencontainers.image.revision="${GIT_REVISION}" \
|
||||
org.opencontainers.image.source="https://gitea.example.com/jens/itworx-mcp-hub" \
|
||||
org.opencontainers.image.created="${BUILD_DATE}" \
|
||||
org.opencontainers.image.vendor="ITWorx"
|
||||
|
||||
USER 10001:10001
|
||||
EXPOSE 4318
|
||||
ENTRYPOINT ["python", "/opt/hub/collector.py"]
|
||||
@@ -0,0 +1,78 @@
|
||||
"""Minimal internal OTLP/HTTP collector for the optional observer profile.
|
||||
|
||||
It accepts bounded trace batches, keeps only counters in memory, and exposes
|
||||
Prometheus text metrics. It never logs request bodies or trace attributes.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from http import HTTPStatus
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
from threading import Lock
|
||||
|
||||
MAX_BODY = 1024 * 1024
|
||||
_lock = Lock()
|
||||
_spans = 0
|
||||
_batches = 0
|
||||
|
||||
|
||||
class CollectorHandler(BaseHTTPRequestHandler):
|
||||
server_version = "ITWorxOTLPCollector/1.0"
|
||||
|
||||
def do_GET(self) -> None: # noqa: N802
|
||||
if self.path == "/healthz":
|
||||
self._write(
|
||||
HTTPStatus.OK,
|
||||
b'{"status":"ok","component":"observability-collector"}',
|
||||
"application/json",
|
||||
)
|
||||
return
|
||||
if self.path == "/metrics":
|
||||
with _lock:
|
||||
body = (
|
||||
f"itworx_otel_batches_total {_batches}\\nitworx_otel_spans_total {_spans}\\n"
|
||||
).encode()
|
||||
self._write(HTTPStatus.OK, body, "text/plain; version=0.0.4")
|
||||
return
|
||||
self.send_error(HTTPStatus.NOT_FOUND)
|
||||
|
||||
def do_POST(self) -> None: # noqa: N802
|
||||
global _batches, _spans
|
||||
if self.path != "/v1/traces":
|
||||
self.send_error(HTTPStatus.NOT_FOUND)
|
||||
return
|
||||
length = int(self.headers.get("Content-Length", "0"))
|
||||
if length <= 0 or length > MAX_BODY:
|
||||
self.send_error(HTTPStatus.REQUEST_ENTITY_TOO_LARGE)
|
||||
return
|
||||
try:
|
||||
document = json.loads(self.rfile.read(length))
|
||||
batches = document.get("resourceSpans", [])
|
||||
spans = sum(
|
||||
len(scope.get("spans", []))
|
||||
for batch in batches
|
||||
for scope in batch.get("scopeSpans", [])
|
||||
)
|
||||
except (ValueError, TypeError, AttributeError):
|
||||
self.send_error(HTTPStatus.BAD_REQUEST)
|
||||
return
|
||||
with _lock:
|
||||
_batches += 1
|
||||
_spans += spans
|
||||
self._write(HTTPStatus.ACCEPTED, b"", "text/plain")
|
||||
|
||||
def _write(self, status: HTTPStatus, body: bytes, content_type: str) -> None:
|
||||
self.send_response(status)
|
||||
self.send_header("Content-Type", content_type)
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.end_headers()
|
||||
if body:
|
||||
self.wfile.write(body)
|
||||
|
||||
def log_message(self, _format: str, *_args: object) -> None:
|
||||
return
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ThreadingHTTPServer(("0.0.0.0", 4318), CollectorHandler).serve_forever() # noqa: S104
|
||||
Reference in new issue
Block a user