Skip to content

Feat: Add API endpoint for trending attackers. Progresses #1071#1338

Open
rootp1 wants to merge 3 commits into
GreedyBear-Project:developfrom
rootp1:fix/issue-1071
Open

Feat: Add API endpoint for trending attackers. Progresses #1071#1338
rootp1 wants to merge 3 commits into
GreedyBear-Project:developfrom
rootp1:fix/issue-1071

Conversation

@rootp1
Copy link
Copy Markdown
Contributor

@rootp1 rootp1 commented May 13, 2026

Description

This pull request introduces the API backend for retrieving trending attackers, addressing API inclusions.
Specifically:

  • Adds a new endpoint feeds/trending/ in api/urls.py and api/views/feeds.py, with caching and rate limiting.
  • Implements TrendingAttackersRequestSerializer and rate limiting checks in api/serializers.py to validate trending feed requests.
  • Contains comprehensive tests for the trending views (tests/api/views/test_feeds_trending_view.py), rate limiting (tests/api/views/test_feeds_view.py), and serializers (tests/test_serializers.py).
  • Fixes linter errors and unused imports using ruff fix.

Related issues

Progresses #1071

Type of change

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).
  • Chore (refactoring, dependency updates, CI/CD changes, code cleanup, docs-only changes).

Checklist

Formalities

  • I have read and understood the rules about how to Contribute to this project.
  • I chose an appropriate title for the pull request in the form: <feature name>. Closes #999
  • My branch is based on develop.
  • The pull request is for the branch develop.
  • I have reviewed and verified any LLM-generated code included in this PR.

Docs and tests

  • I documented my code changes with docstrings and/or comments.
  • I have checked if my changes affect user-facing behavior that is described in the docs. If so, I also included an update to the wiki in the description of this PR.
  • Linter (Ruff) gave 0 errors. If you have correctly installed pre-commit, it does these checks and adjustments on your behalf.
  • I have added tests for the feature/bug I solved.
  • All the tests gave 0 errors.

GUI changes

Ignore this section if you did not make any changes to the GUI.

  • I have provided a screenshot of the result in the PR.
  • I have created new frontend tests for the new component or updated existing ones.

Review process

  • We encourage you to create a draft PR first, even when your changes are incomplete. This way you refine your code while we can track your progress and actively review and help.
  • If you think your draft PR is ready to be reviewed by the maintainers, click the corresponding button. Your draft PR will become a real PR.
  • If your changes decrease the overall tests coverage (you will know after the Codecov CI job is done), you should add the required tests to fix the problem.
  • Every time you make changes to the PR and you think the work is done, you should explicitly ask for a review. After receiving a "change request", address the feedback and click "request re-review" next to the reviewer's profile picture at the top right.

Copilot AI review requested due to automatic review settings May 13, 2026 00:41
@rootp1
Copy link
Copy Markdown
Contributor Author

rootp1 commented May 13, 2026

@regulartim, The api changes related to #1071 are here

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 TrendingAttackersRequestSerializer and 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.

Comment thread api/views/feeds.py Outdated
@rootp1 rootp1 changed the title Feeds trending feature and code cleanup. Progresses #1071 Feat: Add API endpoint for trending attackers. Progresses #1071 May 13, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread api/serializers.py
Copy link
Copy Markdown
Member

@regulartim regulartim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @rootp1 ! Looks really good. Thanks! :) Found only one minor thing.

Comment thread api/serializers.py
return normalized_feed_type

def validate_window_minutes(self, window_minutes):
max_window_minutes = int(getattr(settings, "TRENDING_MAX_WINDOW_MINUTES", 60 * 24 * 30))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this redundant? TRENDING_MAX_WINDOW_MINUTES always get's a default value in settings.py, right?

@regulartim
Copy link
Copy Markdown
Member

Ah, also: we need to update the wiki after the merge. Have you already written a section for the "usage" chapter?

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.

3 participants