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
18 changes: 18 additions & 0 deletions kernel_ai/services/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@
}
_TRACEROUTE_CACHE_DEFAULT = {}
_TRACEROUTE_CACHE_TTL_SECONDS_DEFAULT = 60
_FALLBACK_COUNTS = {}


def _record_fallback(fallback_name: str, reason: str):
count = int(_FALLBACK_COUNTS.get(fallback_name, 0)) + 1
_FALLBACK_COUNTS[fallback_name] = count
# Log first occurrence and then sparse checkpoints to avoid noisy logs.
if count in (1, 10, 100, 1000):
log_event(
logger,
"INFO",
"service_fallback_activated",
event_dataset="kernel_ai.app",
component="services.network",
operation=fallback_name,
event_data={"count": count, "reason": reason},
)


def get_active_connections():
Expand Down Expand Up @@ -74,6 +91,7 @@ def hex_to_ip(hex_str):
operation="get_active_connections",
event_data={"error": str(exc)},
)
_record_fallback("get_active_connections", str(exc))
return get_mock_active_connections()


Expand Down
17 changes: 17 additions & 0 deletions kernel_ai/services/processes_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@
from kernel_ai.logging_helpers import log_event

logger = logging.getLogger(__name__)
_DEGRADATION_COUNTS = {}


def _record_degradation(name: str, reason: str):
count = int(_DEGRADATION_COUNTS.get(name, 0)) + 1
_DEGRADATION_COUNTS[name] = count
if count in (1, 10, 100, 1000):
log_event(
logger,
"WARNING",
"service_degradation",
event_dataset="kernel_ai.app",
component="services.processes_runtime",
operation=name,
event_data={"count": count, "reason": reason},
)


def get_processes_detailed_data() -> list[dict]:
Expand Down Expand Up @@ -493,6 +509,7 @@ def _add_edge(src_pid, dst_pid, edge_type, weight):
operation="collect_processes_realtime",
event_data={"error": str(exc)},
)
_record_degradation("memory_visual_fallback", str(exc))
memory_visual = {
"layout": "strips",
"rows": [],
Expand Down
Loading