Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions kernel_ai/services/frontend_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,27 @@ def write_frontend_event(event_payload, frontend_log_file, write_lock):
with write_lock:
with open(frontend_log_file, "a", encoding="utf-8") as f:
f.write(line + "\n")


def ingest_frontend_logs_payload(payload, write_event_fn, max_batch=100):
"""Validate frontend log payload and persist accepted events.

Returns ``(response_payload, status_code)`` for HTTP layer serialization.
"""
if payload is None:
return {"error": "Invalid JSON payload"}, 400

events = payload.get("events", payload if isinstance(payload, list) else [payload])
if not isinstance(events, list):
return {"error": "Expected event object or list of events"}, 400
if len(events) > max_batch:
return {"error": "Batch too large"}, 413

accepted = 0
for raw in events:
if not isinstance(raw, dict):
continue
write_event_fn(raw)
accepted += 1

return {"status": "ok", "accepted": accepted}, 200
81 changes: 81 additions & 0 deletions kernel_ai/services/telemetry_orchestration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""Cross-service orchestration for telemetry endpoints."""

from __future__ import annotations

import os

from kernel_ai.services import core_observability as _core_observability_service
from kernel_ai.services import execution as _execution_service
from kernel_ai.services import kernel_maps as _kernel_maps_service
from kernel_ai.services import syscalls as _syscalls_service

try:
import openai

OPENAI_AVAILABLE = True
except ImportError:
OPENAI_AVAILABLE = False


SYSCALL_NAMES = _kernel_maps_service.SYSCALL_NAMES
KERNEL_DNA_MAX_PROCS = int(os.environ.get("KERNEL_DNA_MAX_PROCS", "1200"))


def map_syscall_to_subsystem(syscall_name):
return _kernel_maps_service.map_syscall_to_subsystem(syscall_name)


def map_interrupt_to_subsystem(interrupt_name):
return _kernel_maps_service.map_interrupt_to_subsystem(interrupt_name)


def get_mock_system_calls():
return _core_observability_service.get_mock_system_calls()


def get_real_system_calls():
return _syscalls_service.get_real_system_calls(
syscall_names=SYSCALL_NAMES,
map_syscall_to_subsystem_fn=map_syscall_to_subsystem,
kernel_dna_max_procs=KERNEL_DNA_MAX_PROCS,
fallback_mock_calls_fn=get_mock_system_calls,
)


def get_kernel_subsystem_status():
return _core_observability_service.get_kernel_subsystem_status()


def get_process_kernel_map():
return _core_observability_service.get_process_kernel_map(
openai_available=OPENAI_AVAILABLE,
openai_module=openai if OPENAI_AVAILABLE else None,
)


def get_nginx_open_files():
return _core_observability_service.get_nginx_open_files()


def _kernel_dna_softirq_nucleotides(limit=8):
return _syscalls_service.get_softirq_nucleotides(
map_interrupt_to_subsystem_fn=map_interrupt_to_subsystem,
limit=limit,
)


def get_kernel_dna_data():
return _execution_service.get_kernel_dna_data(
get_real_system_calls_fn=get_real_system_calls,
map_syscall_to_subsystem_fn=map_syscall_to_subsystem,
map_interrupt_to_subsystem_fn=map_interrupt_to_subsystem,
softirq_nucleotides_fn=_kernel_dna_softirq_nucleotides,
)


def get_execution_context_data(exec_context_prev):
return _execution_service.get_execution_context_data(
syscall_names=SYSCALL_NAMES,
map_interrupt_to_subsystem_fn=map_interrupt_to_subsystem,
exec_context_prev=exec_context_prev,
)
Loading