Skip to content

Feat/webhook delivery stats#253

Open
amandapada wants to merge 3 commits intoSoroScan:mainfrom
amandapada:feat/webhook-delivery-stats
Open

Feat/webhook delivery stats#253
amandapada wants to merge 3 commits intoSoroScan:mainfrom
amandapada:feat/webhook-delivery-stats

Conversation

@amandapada
Copy link
Copy Markdown

Summary
Closes #184

Adds GET /api/webhooks/{id}/stats/ — a cached endpoint returning delivery health statistics for a webhook subscription.

Changes

models.py

  • Added duration_ms (FloatField, nullable) to WebhookDeliveryLog to track HTTP request duration per attempt

tasks.py

  • Updated _log_delivery_attempt to accept and store duration_ms
  • All 4 call sites inside dispatch_webhook now pass (time.monotonic() - _start) * 1000 as duration_ms

views.py

  • Added stats action to WebhookSubscriptionViewSet
  • Returns: total_deliveries, successful, failed, success_rate, avg_latency_ms, last_delivery_at
  • Response cached for 60s per subscription

migrations/

  • New migration for duration_ms field on WebhookDeliveryLog

tests/test_views.py

  • test_webhook_stats_empty — zero state returns correct defaults
  • test_webhook_stats — correct aggregation across success/failure logs
  • test_webhook_stats_cached — verifies 60s cache is set after first request
  • test_webhook_stats_404_for_missing_webhook — non-existent ID returns 404

Acceptance Criteria

  • Endpoint returns all stats
  • Success rate calculated correctly
  • Latency accurate (recorded at actual dispatch time via time.monotonic())
  • Cached for 60s

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Mar 30, 2026

@amandapada Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@DokaIzk
Copy link
Copy Markdown
Contributor

DokaIzk commented Mar 30, 2026

@amandapada please resolve conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add GET /api/webhooks/{id}/stats/ for delivery statistics

2 participants