Skip to content
10 changes: 2 additions & 8 deletions logsight/enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,8 @@ class AnomalyScore:
def score_event(event: EnrichedLog, recent: list[EnrichedLog]) -> AnomalyScore:
"""Combine frequency and structural signals into a deterministic score."""
template = event.template or extract_template(event.message)
same = sum(
1
for item in recent
if (item.template or extract_template(item.message)) == template
)
error_rate = sum(
item.level in {"ERROR", "CRITICAL"} for item in recent
) / max(len(recent), 1)
same = sum(1 for item in recent if (item.template or extract_template(item.message)) == template)
error_rate = sum(item.level in {"ERROR", "CRITICAL"} for item in recent) / max(len(recent), 1)
rarity = 1.0 / (same + 1)
severity = 1.0 if event.level in {"ERROR", "CRITICAL"} else 0.0
score = min(1.0, 0.45 * rarity + 0.35 * error_rate + 0.20 * severity)
Expand Down
13 changes: 3 additions & 10 deletions logsight/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@


class ClickHouseStore:
def __init__(
self, base_url: str = "http://localhost:8123", database: str = "logsight"
) -> None:
def __init__(self, base_url: str = "http://localhost:8123", database: str = "logsight") -> None:
self.base_url = base_url.rstrip("/")
self.database = database

Expand All @@ -38,17 +36,12 @@ def insert_events(self, events: list[dict[str, Any]]) -> None:


class QdrantStore:
def __init__(
self, base_url: str = "http://localhost:6333", collection: str = "logsight"
) -> None:
def __init__(self, base_url: str = "http://localhost:6333", collection: str = "logsight") -> None:
self.base_url = base_url.rstrip("/")
self.collection = collection

def upsert(self, points: list[dict[str, Any]]) -> dict[str, Any]:
url = (
f"{self.base_url}/collections/"
f"{urllib.parse.quote(self.collection, safe='')}/points"
)
url = f"{self.base_url}/collections/{urllib.parse.quote(self.collection, safe='')}/points"
body = json.dumps({"points": points}).encode()
request = urllib.request.Request(
url,
Expand Down
Loading