feat(metrics): distinguish received and acknowledged CDRs

This commit is contained in:
2026-09-20 10:40:24 +03:30
parent 6ce567646b
commit f45c457dc8
5 changed files with 63 additions and 8 deletions

View File

@@ -160,6 +160,7 @@ class TestIngestionAPIServer(unittest.IsolatedAsyncioTestCase):
self.assertEqual(status, 200)
content = body.decode("utf-8")
self.assertIn("cdr_api_received_total", content)
self.assertIn("cdr_api_acknowledged_total", content)
async def test_stats_endpoint(self):
status, _, body = await self._http_request("GET", "/stats")
@@ -168,6 +169,26 @@ class TestIngestionAPIServer(unittest.IsolatedAsyncioTestCase):
self.assertIn("pipeline", data)
self.assertIn("breakdown", data)
self.assertIn("total_received", data["pipeline"])
self.assertIn("total_acknowledged", data["pipeline"])
async def test_metrics_separated_counters(self):
from app.api.metrics import api_metrics
received_before = api_metrics.total_received
ack_before = api_metrics.total_acknowledged
# Send invalid payload (400 Bad Request)
status, _, _ = await self._http_request("POST", "/api/v1/cdr/raw", body=b"{}", headers={"Content-Type": "application/json"})
self.assertEqual(status, 400)
self.assertEqual(api_metrics.total_received, received_before + 1)
self.assertEqual(api_metrics.total_acknowledged, ack_before)
# Send valid payload (202 Accepted)
from tests.test_api_delivery import payload
valid_body = json.dumps(payload()).encode("utf-8")
status, _, _ = await self._http_request("POST", "/api/v1/cdr/raw", body=valid_body, headers={"Content-Type": "application/json"})
self.assertEqual(status, 202)
self.assertEqual(api_metrics.total_received, received_before + 2)
self.assertEqual(api_metrics.total_acknowledged, ack_before + 1)
async def test_not_found_returns_404(self):
status, _, body = await self._http_request("GET", "/unknown/route")