diff --git a/logsight/enterprise.py b/logsight/enterprise.py index 834e5aa..ceab760 100644 --- a/logsight/enterprise.py +++ b/logsight/enterprise.py @@ -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) diff --git a/logsight/storage.py b/logsight/storage.py index c2a4322..a22329e 100644 --- a/logsight/storage.py +++ b/logsight/storage.py @@ -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 @@ -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,