Feat: Add API endpoint for trending attackers. Progresses #1071#1338
Feat: Add API endpoint for trending attackers. Progresses #1071#1338rootp1 wants to merge 3 commits into
Conversation
|
@regulartim, The api changes related to #1071 are here |
There was a problem hiding this comment.
Pull request overview
This pull request adds a new “Trending Feeds” API endpoint (and related request serializer + tests) to expose ranked “trending attackers” by comparing interaction counts across two consecutive, hour-aligned time windows. It also includes backend cleanup by reusing the existing greedybear.cronjobs.trending logic and adds test coverage around throttling and trending caching behavior.
Changes:
- Added
/api/feeds/trending/endpoint with caching + ranking output for trending attackers. - Introduced
TrendingAttackersRequestSerializerand shared feed-type list validation to reduce duplication. - Expanded test coverage for throttling behavior and added a full test suite for the new trending endpoint (including cache behavior and version bump invalidation).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
api/views/feeds.py |
Adds the feeds_trending API view, caching helpers, and integrates ranking via cronjob utilities. |
api/serializers.py |
Adds TrendingAttackersRequestSerializer and refactors feed-type list validation into a shared helper. |
api/urls.py |
Wires up the new /feeds/trending/ route. |
tests/api/views/test_feeds_view.py |
Adds regression tests ensuring feeds endpoints are protected by FeedsThrottle. |
tests/api/views/test_feeds_trending_view.py |
Adds end-to-end tests for trending response shape, filtering, caching, cache version invalidation, and throttling behavior. |
tests/test_serializers.py |
Adds unit tests for trending request serializer defaults and validation rules. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
regulartim
left a comment
There was a problem hiding this comment.
Hey @rootp1 ! Looks really good. Thanks! :) Found only one minor thing.
| return normalized_feed_type | ||
|
|
||
| def validate_window_minutes(self, window_minutes): | ||
| max_window_minutes = int(getattr(settings, "TRENDING_MAX_WINDOW_MINUTES", 60 * 24 * 30)) |
There was a problem hiding this comment.
Isn't this redundant? TRENDING_MAX_WINDOW_MINUTES always get's a default value in settings.py, right?
|
Ah, also: we need to update the wiki after the merge. Have you already written a section for the "usage" chapter? |
Description
This pull request introduces the API backend for retrieving trending attackers, addressing API inclusions.
Specifically:
feeds/trending/inapi/urls.pyandapi/views/feeds.py, with caching and rate limiting.TrendingAttackersRequestSerializerand rate limiting checks inapi/serializers.pyto validate trending feed requests.tests/api/views/test_feeds_trending_view.py), rate limiting (tests/api/views/test_feeds_view.py), and serializers (tests/test_serializers.py).ruff fix.Related issues
Progresses #1071
Type of change
Checklist
Formalities
<feature name>. Closes #999develop.develop.Docs and tests
Ruff) gave 0 errors. If you have correctly installed pre-commit, it does these checks and adjustments on your behalf.GUI changes
Ignore this section if you did not make any changes to the GUI.
Review process