fix memory usage redis
This commit is contained in:
+34
-1
@@ -83,7 +83,7 @@ class StoreTests(unittest.TestCase):
|
||||
row = store.recent(1)[0]
|
||||
self.assertEqual(row["hit_count"], 1)
|
||||
self.assertEqual(row["first_seen"], "2026-08-13T10:00:00+00:00")
|
||||
self.assertEqual(store.database_info()["schema_version"], 11)
|
||||
self.assertEqual(store.database_info()["schema_version"], 12)
|
||||
store.close()
|
||||
|
||||
def test_normalizes_timezone_to_utc(self):
|
||||
@@ -188,6 +188,39 @@ class StoreTests(unittest.TestCase):
|
||||
self.assertIsNone(store.get_web_session("old"))
|
||||
store.close()
|
||||
|
||||
def test_archives_traffic_events_and_throughput_on_disk(self):
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
path = os.path.join(td, "alerts.db")
|
||||
store = AlertStore(path)
|
||||
now = 1_800_000_000_000
|
||||
event = {"id": "evt", "ts_ms": now, "type": "dns", "proto": "UDP", "app_proto": "dns", "direction": "outbound", "src_ip": "10.0.0.2", "dest_ip": "8.8.8.8"}
|
||||
sample = {"ts_ms": now, "interval_ms": 1000, "bytes_total": 125000, "bytes_in": 25000, "bytes_out": 100000, "packets_total": 100}
|
||||
self.assertEqual(store.archive_traffic_events([("event-key", event)]), 1)
|
||||
self.assertEqual(store.archive_traffic_events([("event-key", event)]), 0)
|
||||
self.assertEqual(store.archive_traffic_throughput([("sample-key", sample)]), 1)
|
||||
status = store.traffic_archive_status()
|
||||
self.assertEqual(status["events"], 1)
|
||||
self.assertEqual(status["throughput_samples"], 1)
|
||||
self.assertEqual(store.traffic_event_page(now - 1, now + 1)[0]["id"], "evt")
|
||||
self.assertEqual(store.traffic_throughput_page(now - 1, now + 1)[0]["bytes_total"], 125000)
|
||||
store.close()
|
||||
|
||||
def test_traffic_archive_drops_dashboard_decoder_noise(self):
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
path = os.path.join(td, "alerts.db")
|
||||
store = AlertStore(path)
|
||||
noise = {
|
||||
"id": "noise",
|
||||
"ts_ms": 1_800_000_000_000,
|
||||
"type": "alert",
|
||||
"signature": "SURICATA IPv4 truncated packet",
|
||||
"src_ip": "10.0.0.2",
|
||||
"dest_ip": "1.1.1.1",
|
||||
}
|
||||
self.assertEqual(store.archive_traffic_events([("noise-key", noise)]), 0)
|
||||
self.assertEqual(store.traffic_archive_status()["events"], 0)
|
||||
store.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user