logreducer 3.5.5__tar.gz → 3.5.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {logreducer-3.5.5 → logreducer-3.5.6}/PKG-INFO +4 -4
- {logreducer-3.5.5 → logreducer-3.5.6}/docs/pypi.md +3 -3
- {logreducer-3.5.5 → logreducer-3.5.6}/pyproject.toml +17 -14
- {logreducer-3.5.5 → logreducer-3.5.6}/pyproject.toml.orig +17 -14
- {logreducer-3.5.5 → logreducer-3.5.6}/src/logreducer/anomaly.py +4 -1
- {logreducer-3.5.5 → logreducer-3.5.6}/src/logreducer/cli.py +2 -2
- {logreducer-3.5.5 → logreducer-3.5.6}/src/logreducer/config.py +2 -1
- {logreducer-3.5.5 → logreducer-3.5.6}/src/logreducer/core.py +31 -30
- {logreducer-3.5.5 → logreducer-3.5.6}/src/logreducer/kafka.py +118 -56
- {logreducer-3.5.5 → logreducer-3.5.6}/src/logreducer/patterns.py +142 -23
- {logreducer-3.5.5 → logreducer-3.5.6}/src/logreducer/sampling.py +59 -28
- {logreducer-3.5.5 → logreducer-3.5.6}/src/logreducer/sql.py +31 -6
- {logreducer-3.5.5 → logreducer-3.5.6}/src/logreducer/target.py +5 -4
- {logreducer-3.5.5 → logreducer-3.5.6}/src/logreducer/temporal.py +29 -14
- {logreducer-3.5.5 → logreducer-3.5.6}/LICENSE +0 -0
- {logreducer-3.5.5 → logreducer-3.5.6}/NOTICE +0 -0
- {logreducer-3.5.5 → logreducer-3.5.6}/src/logreducer/__init__.py +0 -0
- {logreducer-3.5.5 → logreducer-3.5.6}/src/logreducer/clickhouse.py +0 -0
- {logreducer-3.5.5 → logreducer-3.5.6}/src/logreducer/logging_config.py +0 -0
- {logreducer-3.5.5 → logreducer-3.5.6}/src/logreducer/memory.py +0 -0
- {logreducer-3.5.5 → logreducer-3.5.6}/src/logreducer/py.typed +0 -0
- {logreducer-3.5.5 → logreducer-3.5.6}/src/logreducer/sinks.py +0 -0
- {logreducer-3.5.5 → logreducer-3.5.6}/src/logreducer/sources.py +0 -0
- {logreducer-3.5.5 → logreducer-3.5.6}/src/logreducer/template_mining.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: logreducer
|
|
3
|
-
Version: 3.5.
|
|
3
|
+
Version: 3.5.6
|
|
4
4
|
Summary: Reduce GB-scale logs to a representative sample - streaming Python library and CLI with pattern mining and anomaly detection
|
|
5
5
|
Keywords: log,logging,reduction,analysis,pattern-extraction,memory-efficient,streaming,anomaly-detection
|
|
6
6
|
Author: HyperI Team
|
|
@@ -49,10 +49,10 @@ It ships as a CLI and as a Python library with an IO-agnostic core.
|
|
|
49
49
|
## What it gives you
|
|
50
50
|
|
|
51
51
|
- A `logreducer` command that reduces a file, a SQL or ClickHouse query, or a Kafka topic, straight from the shell.
|
|
52
|
-
- Pattern mode streams through a bounded dedup cache and template store, so memory
|
|
52
|
+
- Pattern mode streams through a bounded dedup cache, fuzzy index and template store, so memory does not grow with the line count or the number of distinct lines.
|
|
53
53
|
- A memory budget that decides how a file is read: whole, in chunks, or reservoir-sampled once it passes five times the budget.
|
|
54
54
|
- Four modes: pattern (Drain3 template mining), anomaly (Isolation Forest), temporal (one example per template per time window) and hybrid.
|
|
55
|
-
- ERROR, FATAL
|
|
55
|
+
- Lines naming ERROR, FATAL or CRITICAL as a whole word, in any case, always come through, one per distinct shape and ahead of the reduced output, in every mode and however a file is read. A SQL or ClickHouse source samples in the database first, so only the lines it returns are seen.
|
|
56
56
|
- A core with no IO dependencies: anything re-iterable that yields `str` lines is a source, and anything with `write(lines)` is a sink.
|
|
57
57
|
- Seeded SQL sampling and ClickHouse `SAMPLE` for tables too big to scan in full.
|
|
58
58
|
- `reduce_to_target` to collect about N representative lines from a large source, holding roughly one batch in memory.
|
|
@@ -90,7 +90,7 @@ From the shell it is `logreducer app.log -o reduced.log`. `level` is `standard`,
|
|
|
90
90
|
|
|
91
91
|
| Extra | Adds |
|
|
92
92
|
|---|---|
|
|
93
|
-
| `enhanced` | Fuzzy dedup with MinHash LSH, whose index
|
|
93
|
+
| `enhanced` | Fuzzy dedup with MinHash LSH, whose index holds the last `dedup_cache_size` near-unique lines, and faster hashing |
|
|
94
94
|
| `sql` | `SQLSource` over SQLAlchemy, with your own DBAPI driver |
|
|
95
95
|
| `clickhouse` | `ClickHouseSource` over clickhouse-connect |
|
|
96
96
|
| `kafka` | `KafkaSource` and `KafkaSink` over confluent-kafka |
|
|
@@ -7,10 +7,10 @@ It ships as a CLI and as a Python library with an IO-agnostic core.
|
|
|
7
7
|
## What it gives you
|
|
8
8
|
|
|
9
9
|
- A `logreducer` command that reduces a file, a SQL or ClickHouse query, or a Kafka topic, straight from the shell.
|
|
10
|
-
- Pattern mode streams through a bounded dedup cache and template store, so memory
|
|
10
|
+
- Pattern mode streams through a bounded dedup cache, fuzzy index and template store, so memory does not grow with the line count or the number of distinct lines.
|
|
11
11
|
- A memory budget that decides how a file is read: whole, in chunks, or reservoir-sampled once it passes five times the budget.
|
|
12
12
|
- Four modes: pattern (Drain3 template mining), anomaly (Isolation Forest), temporal (one example per template per time window) and hybrid.
|
|
13
|
-
- ERROR, FATAL
|
|
13
|
+
- Lines naming ERROR, FATAL or CRITICAL as a whole word, in any case, always come through, one per distinct shape and ahead of the reduced output, in every mode and however a file is read. A SQL or ClickHouse source samples in the database first, so only the lines it returns are seen.
|
|
14
14
|
- A core with no IO dependencies: anything re-iterable that yields `str` lines is a source, and anything with `write(lines)` is a sink.
|
|
15
15
|
- Seeded SQL sampling and ClickHouse `SAMPLE` for tables too big to scan in full.
|
|
16
16
|
- `reduce_to_target` to collect about N representative lines from a large source, holding roughly one batch in memory.
|
|
@@ -48,7 +48,7 @@ From the shell it is `logreducer app.log -o reduced.log`. `level` is `standard`,
|
|
|
48
48
|
|
|
49
49
|
| Extra | Adds |
|
|
50
50
|
|---|---|
|
|
51
|
-
| `enhanced` | Fuzzy dedup with MinHash LSH, whose index
|
|
51
|
+
| `enhanced` | Fuzzy dedup with MinHash LSH, whose index holds the last `dedup_cache_size` near-unique lines, and faster hashing |
|
|
52
52
|
| `sql` | `SQLSource` over SQLAlchemy, with your own DBAPI driver |
|
|
53
53
|
| `clickhouse` | `ClickHouseSource` over clickhouse-connect |
|
|
54
54
|
| `kafka` | `KafkaSource` and `KafkaSink` over confluent-kafka |
|
|
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "logreducer"
|
|
7
|
-
version = "3.5.
|
|
7
|
+
version = "3.5.6"
|
|
8
8
|
description = "Reduce GB-scale logs to a representative sample - streaming Python library and CLI with pattern mining and anomaly detection"
|
|
9
9
|
readme = "docs/pypi.md"
|
|
10
10
|
license = "Apache-2.0"
|
|
@@ -83,10 +83,10 @@ module-name = "logreducer"
|
|
|
83
83
|
module-root = "src"
|
|
84
84
|
|
|
85
85
|
[tool.uv.exclude-newer-package]
|
|
86
|
-
|
|
86
|
+
scalo = "2026-11-01T06:00:00Z"
|
|
87
87
|
|
|
88
88
|
[tool.ruff]
|
|
89
|
-
target-version = "
|
|
89
|
+
target-version = "py314"
|
|
90
90
|
line-length = 120
|
|
91
91
|
indent-width = 4
|
|
92
92
|
src = ["src"]
|
|
@@ -187,7 +187,7 @@ skip-magic-trailing-comma = false
|
|
|
187
187
|
line-ending = "auto"
|
|
188
188
|
|
|
189
189
|
[tool.mypy]
|
|
190
|
-
python_version = "3.
|
|
190
|
+
python_version = "3.14"
|
|
191
191
|
ignore_missing_imports = true
|
|
192
192
|
warn_return_any = true
|
|
193
193
|
warn_unused_configs = true
|
|
@@ -216,6 +216,7 @@ markers = [
|
|
|
216
216
|
"""slow: marks tests as slow (deselect with '-m "not slow"')""",
|
|
217
217
|
"integration: marks tests as integration tests",
|
|
218
218
|
]
|
|
219
|
+
shared_service_repo = "logreducer"
|
|
219
220
|
|
|
220
221
|
[tool.coverage.run]
|
|
221
222
|
source = ["logreducer"]
|
|
@@ -263,35 +264,36 @@ skips = [
|
|
|
263
264
|
]
|
|
264
265
|
|
|
265
266
|
[tool.ty.environment]
|
|
266
|
-
python-version = "3.
|
|
267
|
+
python-version = "3.14"
|
|
267
268
|
|
|
268
269
|
[tool.ty.src]
|
|
269
270
|
exclude = [
|
|
270
271
|
"examples/",
|
|
271
272
|
"docs/",
|
|
272
273
|
"scripts/",
|
|
274
|
+
"tests/testdata/build_quiet_golden.py",
|
|
273
275
|
]
|
|
274
276
|
|
|
275
277
|
[tool.vulture]
|
|
276
278
|
min_confidence = 80
|
|
277
279
|
|
|
278
280
|
[tool.vermin]
|
|
279
|
-
targets = ["3.
|
|
281
|
+
targets = ["3.14"]
|
|
280
282
|
no_tips = true
|
|
281
283
|
|
|
282
284
|
[tool.hatch.build.targets.sdist]
|
|
283
285
|
exclude = [
|
|
286
|
+
"/.claude",
|
|
287
|
+
"/GEMINI.md",
|
|
284
288
|
"/CURSOR.md",
|
|
289
|
+
"/.windsurf",
|
|
285
290
|
"/CLAUDE.md",
|
|
286
|
-
"
|
|
287
|
-
"/ci",
|
|
288
|
-
"/.github/copilot-instructions.md",
|
|
289
|
-
"/.claude",
|
|
291
|
+
"/.gemini",
|
|
290
292
|
"/hyperi-ai",
|
|
293
|
+
"/.github/copilot-instructions.md",
|
|
291
294
|
"/.cursor",
|
|
292
|
-
"
|
|
293
|
-
"
|
|
294
|
-
"/GEMINI.md",
|
|
295
|
+
"/STATE.md",
|
|
296
|
+
"/ci",
|
|
295
297
|
]
|
|
296
298
|
|
|
297
299
|
[dependency-groups]
|
|
@@ -311,7 +313,8 @@ dev = [
|
|
|
311
313
|
"sqlalchemy>=2.1.3",
|
|
312
314
|
"clickhouse-connect>=1.9.0",
|
|
313
315
|
"confluent-kafka>=2.15.1",
|
|
314
|
-
"
|
|
316
|
+
"scalo>=2.32.4",
|
|
317
|
+
"testcontainers[postgres,mysql]>=4.15.0",
|
|
315
318
|
"psycopg[binary]>=3.2",
|
|
316
319
|
"pymysql>=1.1.0",
|
|
317
320
|
"python-dotenv>=1.0.0",
|
|
@@ -6,7 +6,7 @@ build-backend = "uv_build"
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "logreducer"
|
|
9
|
-
version = "3.5.
|
|
9
|
+
version = "3.5.6"
|
|
10
10
|
authors = [
|
|
11
11
|
{ name = "HyperI Team", email = "dev@hyperi.io" },
|
|
12
12
|
]
|
|
@@ -87,10 +87,10 @@ module-name = "logreducer"
|
|
|
87
87
|
module-root = "src"
|
|
88
88
|
|
|
89
89
|
[tool.uv.exclude-newer-package]
|
|
90
|
-
|
|
90
|
+
scalo = "2026-11-01T06:00:00Z"
|
|
91
91
|
|
|
92
92
|
[tool.ruff]
|
|
93
|
-
target-version = "
|
|
93
|
+
target-version = "py314"
|
|
94
94
|
line-length = 120
|
|
95
95
|
indent-width = 4
|
|
96
96
|
src = [
|
|
@@ -209,7 +209,7 @@ skip-magic-trailing-comma = false
|
|
|
209
209
|
line-ending = "auto"
|
|
210
210
|
|
|
211
211
|
[tool.mypy]
|
|
212
|
-
python_version = "3.
|
|
212
|
+
python_version = "3.14"
|
|
213
213
|
ignore_missing_imports = true
|
|
214
214
|
warn_return_any = true
|
|
215
215
|
warn_unused_configs = true
|
|
@@ -244,6 +244,7 @@ markers = [
|
|
|
244
244
|
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
|
|
245
245
|
"integration: marks tests as integration tests",
|
|
246
246
|
]
|
|
247
|
+
shared_service_repo = "logreducer"
|
|
247
248
|
|
|
248
249
|
[tool.coverage.run]
|
|
249
250
|
source = [
|
|
@@ -293,13 +294,14 @@ skips = [
|
|
|
293
294
|
]
|
|
294
295
|
|
|
295
296
|
[tool.ty.environment]
|
|
296
|
-
python-version = "3.
|
|
297
|
+
python-version = "3.14"
|
|
297
298
|
|
|
298
299
|
[tool.ty.src]
|
|
299
300
|
exclude = [
|
|
300
301
|
"examples/",
|
|
301
302
|
"docs/",
|
|
302
303
|
"scripts/",
|
|
304
|
+
"tests/testdata/build_quiet_golden.py",
|
|
303
305
|
]
|
|
304
306
|
|
|
305
307
|
[tool.vulture]
|
|
@@ -307,23 +309,23 @@ min_confidence = 80
|
|
|
307
309
|
|
|
308
310
|
[tool.vermin]
|
|
309
311
|
targets = [
|
|
310
|
-
"3.
|
|
312
|
+
"3.14",
|
|
311
313
|
]
|
|
312
314
|
no_tips = true
|
|
313
315
|
|
|
314
316
|
[tool.hatch.build.targets.sdist]
|
|
315
317
|
exclude = [
|
|
318
|
+
"/.claude",
|
|
319
|
+
"/GEMINI.md",
|
|
316
320
|
"/CURSOR.md",
|
|
321
|
+
"/.windsurf",
|
|
317
322
|
"/CLAUDE.md",
|
|
318
|
-
"
|
|
319
|
-
"/ci",
|
|
320
|
-
"/.github/copilot-instructions.md",
|
|
321
|
-
"/.claude",
|
|
323
|
+
"/.gemini",
|
|
322
324
|
"/hyperi-ai",
|
|
325
|
+
"/.github/copilot-instructions.md",
|
|
323
326
|
"/.cursor",
|
|
324
|
-
"
|
|
325
|
-
"
|
|
326
|
-
"/GEMINI.md",
|
|
327
|
+
"/STATE.md",
|
|
328
|
+
"/ci",
|
|
327
329
|
]
|
|
328
330
|
|
|
329
331
|
[dependency-groups]
|
|
@@ -343,7 +345,8 @@ dev = [
|
|
|
343
345
|
"sqlalchemy>=2.1.3",
|
|
344
346
|
"clickhouse-connect>=1.9.0",
|
|
345
347
|
"confluent-kafka>=2.15.1",
|
|
346
|
-
"
|
|
348
|
+
"scalo>=2.32.4",
|
|
349
|
+
"testcontainers[postgres,mysql]>=4.15.0",
|
|
347
350
|
"psycopg[binary]>=3.2",
|
|
348
351
|
"pymysql>=1.1.0",
|
|
349
352
|
"python-dotenv>=1.0.0",
|
|
@@ -4,6 +4,9 @@ import logging
|
|
|
4
4
|
|
|
5
5
|
logger = logging.getLogger(__name__)
|
|
6
6
|
|
|
7
|
+
# Fewer lines than this are returned unscored, all of them normal.
|
|
8
|
+
MIN_SCORED_LINES = 10
|
|
9
|
+
|
|
7
10
|
# Try optional imports
|
|
8
11
|
try:
|
|
9
12
|
from sklearn.ensemble import IsolationForest
|
|
@@ -30,7 +33,7 @@ class AnomalyDetector:
|
|
|
30
33
|
Returns:
|
|
31
34
|
(anomalous_lines, normal_lines)
|
|
32
35
|
"""
|
|
33
|
-
if not self.enabled or len(lines) <
|
|
36
|
+
if not self.enabled or len(lines) < MIN_SCORED_LINES:
|
|
34
37
|
return [], lines
|
|
35
38
|
|
|
36
39
|
# Vectorize
|
|
@@ -189,7 +189,7 @@ def _reduce(
|
|
|
189
189
|
else:
|
|
190
190
|
_err("Error: provide a log file, or --dsn with --query (SQL/ClickHouse) or --topic/--group (Kafka)")
|
|
191
191
|
raise typer.Exit(1)
|
|
192
|
-
except
|
|
192
|
+
except typer.Exit, typer.BadParameter:
|
|
193
193
|
raise # our control-flow exit / typer usage errors - let typer format them
|
|
194
194
|
except KeyboardInterrupt:
|
|
195
195
|
_err("Processing interrupted by user")
|
|
@@ -276,7 +276,7 @@ def _run_target(
|
|
|
276
276
|
close = getattr(source, "close", None)
|
|
277
277
|
if callable(close):
|
|
278
278
|
close()
|
|
279
|
-
except
|
|
279
|
+
except typer.Exit, typer.BadParameter:
|
|
280
280
|
raise
|
|
281
281
|
except KeyboardInterrupt:
|
|
282
282
|
_err("Processing interrupted by user")
|
|
@@ -47,6 +47,7 @@ class BigDialConfig:
|
|
|
47
47
|
# measured reductions use tens of MB, so the default is deliberately low
|
|
48
48
|
# and container-friendly.
|
|
49
49
|
max_memory_gb: float = 1.0
|
|
50
|
+
# Lines exact dedup remembers, and lines the fuzzy index holds. Both drop the oldest first.
|
|
50
51
|
dedup_cache_size: int = 100000
|
|
51
52
|
|
|
52
53
|
# Speed Control
|
|
@@ -101,7 +102,7 @@ class BigDialConfig:
|
|
|
101
102
|
self.max_memory_gb = clamped
|
|
102
103
|
|
|
103
104
|
@classmethod
|
|
104
|
-
def from_env(cls, *prefixes: str) ->
|
|
105
|
+
def from_env(cls, *prefixes: str) -> BigDialConfig:
|
|
105
106
|
"""Build a config from environment variables, cascade-aware.
|
|
106
107
|
|
|
107
108
|
``from_env()`` reads ``LOGREDUCER_<FIELD>`` (upper-cased field names,
|
|
@@ -11,8 +11,8 @@ from enum import Enum
|
|
|
11
11
|
from pathlib import Path
|
|
12
12
|
from typing import Any, Literal, overload
|
|
13
13
|
|
|
14
|
-
from .anomaly import AnomalyDetector
|
|
15
|
-
from .config import BigDialConfig, OutputFormat, ProcessingLevel, ProcessingMode, get_preset_config
|
|
14
|
+
from .anomaly import MIN_SCORED_LINES, AnomalyDetector
|
|
15
|
+
from .config import BigDialConfig, OutputFormat, ProcessingLevel, ProcessingMode, get_preset_config
|
|
16
16
|
from .logging_config import get_logger, setup_logging
|
|
17
17
|
from .memory import BoundedDeduplicator, MemoryMonitor
|
|
18
18
|
from .patterns import FuzzyDeduplicator, PatternExtractor, SevereShapes, is_severe, pattern_priority
|
|
@@ -64,24 +64,23 @@ class LogReducer:
|
|
|
64
64
|
self.mode = mode
|
|
65
65
|
|
|
66
66
|
# Base config: an injected one wins over the level preset.
|
|
67
|
-
|
|
67
|
+
base = config if config is not None else get_preset_config(level)
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
overrides: dict[str, Any] = {}
|
|
70
70
|
if max_memory_gb is not None:
|
|
71
|
-
|
|
71
|
+
overrides["max_memory_gb"] = max_memory_gb
|
|
72
72
|
if max_patterns is not None:
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
overrides["max_patterns"] = max_patterns
|
|
75
74
|
for key, value in kwargs.items():
|
|
76
75
|
# Fail fast on typos: silently dropping an unknown override means a
|
|
77
76
|
# user's tuning quietly does nothing.
|
|
78
|
-
if not hasattr(
|
|
77
|
+
if not hasattr(base, key):
|
|
79
78
|
raise ValueError(f"Unknown config option {key!r} (see BigDialConfig for valid fields)")
|
|
80
|
-
# Special handling for output_format to convert string to enum
|
|
81
79
|
if key == "output_format" and isinstance(value, str):
|
|
82
80
|
value = OutputFormat(value.lower())
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
overrides[key] = value
|
|
82
|
+
# replace() builds a new config, so overrides are validated and memory-clamped like any other.
|
|
83
|
+
self.config = replace(base, **overrides)
|
|
85
84
|
|
|
86
85
|
# Setup logging based on config (after overrides applied)
|
|
87
86
|
setup_logging(
|
|
@@ -124,7 +123,7 @@ class LogReducer:
|
|
|
124
123
|
self.deduplicator = BoundedDeduplicator(self.config.dedup_cache_size, self.config.hash_algorithm)
|
|
125
124
|
self.pattern_extractor = PatternExtractor(self.config)
|
|
126
125
|
if self.config.fuzzy_threshold and self.level != ProcessingLevel.STANDARD:
|
|
127
|
-
self.fuzzy_dedup = FuzzyDeduplicator(self.config.fuzzy_threshold)
|
|
126
|
+
self.fuzzy_dedup = FuzzyDeduplicator(self.config.fuzzy_threshold, self.config.dedup_cache_size)
|
|
128
127
|
else:
|
|
129
128
|
self.fuzzy_dedup = None
|
|
130
129
|
if self.mode in [ProcessingMode.TEMPORAL, ProcessingMode.HYBRID]:
|
|
@@ -349,7 +348,7 @@ class LogReducer:
|
|
|
349
348
|
|
|
350
349
|
# Collect the examples of quiet patterns (the extractor has already applied max_patterns to
|
|
351
350
|
# them). Severe lines come from the severe shapes that reduce() adds, one per shape.
|
|
352
|
-
result = []
|
|
351
|
+
result: list[str] = []
|
|
353
352
|
for pattern in patterns:
|
|
354
353
|
result.extend(line for line in pattern.examples if not is_severe(line))
|
|
355
354
|
|
|
@@ -391,13 +390,18 @@ class LogReducer:
|
|
|
391
390
|
self.logger.info("Reading, deduplicating and anomaly detection")
|
|
392
391
|
anomalous, normal = self._detect_quiet_anomalies(self.anomaly_detector, source)
|
|
393
392
|
|
|
394
|
-
|
|
395
|
-
|
|
393
|
+
cap = self.config.max_patterns
|
|
394
|
+
if not anomalous and len(normal) < MIN_SCORED_LINES:
|
|
395
|
+
# Too few lines to score, so they fill the cap.
|
|
396
|
+
result = []
|
|
397
|
+
normal_budget = cap
|
|
398
|
+
else:
|
|
399
|
+
# Half the cap (rounded up) for anomalies, then a quarter, at least one, for normal context.
|
|
400
|
+
result = anomalous[: (cap + 1) // 2]
|
|
401
|
+
normal_budget = min(cap - len(result), max(cap // 4, 1))
|
|
396
402
|
|
|
397
|
-
#
|
|
398
|
-
|
|
399
|
-
# guarantees elsewhere); there is no security requirement here.
|
|
400
|
-
normal_sample_size = min(len(normal), self.config.max_patterns // 4)
|
|
403
|
+
# Seeded so a re-run over the same input yields the same sample.
|
|
404
|
+
normal_sample_size = min(len(normal), normal_budget)
|
|
401
405
|
if normal_sample_size > 0:
|
|
402
406
|
result.extend(random.Random(0).sample(normal, normal_sample_size))
|
|
403
407
|
|
|
@@ -419,14 +423,10 @@ class LogReducer:
|
|
|
419
423
|
self.logger.info("Phase 2/2: Temporal processing")
|
|
420
424
|
temporal_results = self.temporal_processor.process_temporal(lines)
|
|
421
425
|
|
|
422
|
-
# One example per (window, template), the most important first.
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
result = [p["example"] for p in rank(temporal_results["temporal_patterns"])[: self.config.max_patterns]]
|
|
427
|
-
result.extend(p["example"] for p in rank(temporal_results["timeless_patterns"])[:100])
|
|
428
|
-
|
|
429
|
-
return result
|
|
426
|
+
# One example per (window, template) or timeless template, the most important first, under one cap.
|
|
427
|
+
candidates = temporal_results["temporal_patterns"] + temporal_results["timeless_patterns"]
|
|
428
|
+
ranked = sorted(candidates, key=lambda p: pattern_priority(p["template"], p["count"]), reverse=True)
|
|
429
|
+
return [p["example"] for p in ranked[: self.config.max_patterns]]
|
|
430
430
|
|
|
431
431
|
def _process_hybrid_mode(self, source: Source) -> list[str]:
|
|
432
432
|
"""Process using combined approach."""
|
|
@@ -444,9 +444,10 @@ class LogReducer:
|
|
|
444
444
|
self.deduplicator = BoundedDeduplicator(self.config.dedup_cache_size, self.config.hash_algorithm)
|
|
445
445
|
anomalous, _ = self._detect_quiet_anomalies(self.anomaly_detector, source)
|
|
446
446
|
|
|
447
|
-
#
|
|
448
|
-
|
|
449
|
-
result
|
|
447
|
+
# Anomalies take half the cap (rounded up), patterns half, at least one, of what is left.
|
|
448
|
+
cap = self.config.max_patterns
|
|
449
|
+
result = anomalous[: (cap + 1) // 2]
|
|
450
|
+
result.extend(pattern_lines[: min(cap - len(result), max(cap // 2, 1))])
|
|
450
451
|
else:
|
|
451
452
|
result = pattern_lines
|
|
452
453
|
|