Skip to content

chore(audits): return queue pre-fetch results#9731

Merged
christyjacob4 merged 1 commit into1.7.xfrom
PLA-2683
Jun 4, 2025
Merged

chore(audits): return queue pre-fetch results#9731
christyjacob4 merged 1 commit into1.7.xfrom
PLA-2683

Conversation

@basert
Copy link
Copy Markdown
Contributor

@basert basert commented May 7, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved batch processing logic for audit logs, ensuring batches are processed based on the total number of logs and time elapsed.
    • Enhanced reliability by handling errors during log processing without interrupting the update of processing intervals.
  • Chores
    • Adjusted batch size configuration to be dynamically set via environment variables for better flexibility.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 7, 2025

Walkthrough

The batch processing logic in the Audits worker was refactored to dynamically determine batch size from an environment variable, update type declarations, and refine control flow. The action method now returns result objects based on whether a batch was processed, and batch processing is triggered by the total log count rather than project count.

Changes

File(s) Change Summary
src/Appwrite/Platform/Workers/Audits.php Removed fixed batch size constants; batch size now parsed from environment variable. Changed action method return type to `Commit

Sequence Diagram(s)

sequenceDiagram
    participant Worker as Audits Worker
    participant Env as Environment
    participant ProjectDB as Project Database
    participant Logger as Logger

    Worker->>Env: Get _APP_QUEUE_PREFETCH_COUNT
    Env-->>Worker: Return batch size
    Worker->>Worker: Count total logs across projects
    alt Batch should be processed
        loop For each project with logs
            Worker->>ProjectDB: getProjectDB(project)
            Worker->>ProjectDB: Log batch
            alt Error occurs
                Worker->>Logger: Log error
            end
        end
        Worker->>Worker: Update last triggered time
        Worker-->>Caller: Return Commit
    else Batch not processed
        Worker-->>Caller: Return NoCommit
    end
Loading

Poem

In the warren of code, a batch hops anew,
Guided by env vars, not constants it knew.
With Commit or NoCommit, the action is clear,
Logs counted in total, the logic sincere.
A rabbit’s delight—refactored, precise,
This audit trail now runs quite nice!
🐇✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ccc84cb and fc14144.

📒 Files selected for processing (1)
  • src/Appwrite/Platform/Workers/Audits.php (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Appwrite/Platform/Workers/Audits.php
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: E2E Service Test (Migrations)
  • GitHub Check: E2E Service Test (Messaging)
  • GitHub Check: E2E Service Test (Webhooks)
  • GitHub Check: E2E Service Test (Sites)
  • GitHub Check: E2E Service Test (Projects)
  • GitHub Check: E2E Service Test (Avatars)
  • GitHub Check: E2E Service Test (Console)
  • GitHub Check: E2E Service Test (Databases)
  • GitHub Check: E2E General Test
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 7, 2025

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
binutils 2.42-r0 CVE-2025-0840 HIGH
libexpat 2.6.4-r0 CVE-2024-8176 HIGH
libxml2 2.12.7-r0 CVE-2024-56171 HIGH
libxml2 2.12.7-r0 CVE-2025-24928 HIGH
libxml2 2.12.7-r0 CVE-2025-27113 HIGH
libxml2 2.12.7-r0 CVE-2025-32414 HIGH
libxml2 2.12.7-r0 CVE-2025-32415 HIGH
sqlite-libs 3.45.3-r1 CVE-2025-29087 HIGH
xz 5.6.2-r0 CVE-2025-31115 HIGH
xz-libs 5.6.2-r0 CVE-2025-31115 HIGH
golang.org/x/crypto v0.31.0 CVE-2025-22869 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 7, 2025

✨ Benchmark results

  • Requests per second: 940
  • Requests with 200 status code: 169,215
  • P99 latency: 0.200376074

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 940 1,138
200 169,215 204,880
P99 0.200376074 0.166661453

@basert basert force-pushed the PLA-2683 branch 3 times, most recently from 0174614 to 1f346f5 Compare May 8, 2025 08:20
@basert basert changed the base branch from 1.6.x to 1.7.x June 3, 2025 09:31
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b47ab90 and ccc84cb.

📒 Files selected for processing (1)
  • src/Appwrite/Platform/Workers/Audits.php (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (7)
src/Appwrite/Platform/Workers/Audits.php (7)

15-16: LGTM: Import statements for new result types.

The new imports for Commit and NoCommit are correctly added to support the updated return type of the action method.


21-21: LGTM: Explicit type declaration for constant.

Adding explicit int typing to the constant improves code clarity and type safety.


30-30: LGTM: Safe environment variable parsing.

Using intval() ensures the environment variable is properly cast to an integer, providing better type safety and handling of invalid values.


58-58: LGTM: Updated return type matches new implementation.

The return type change from void to Commit|NoCommit correctly reflects the new behavior where the method returns result objects based on processing decisions.

Also applies to: 64-64


125-132: LGTM: Improved early return logic.

The new early return pattern with NoCommit is a good optimization that avoids unnecessary processing when the batch criteria aren't met.


134-148: Consider the error handling strategy.

The try-catch block correctly logs errors but continues processing and updates the trigger time even when errors occur. This might mask issues but prevents the worker from getting stuck.

Please verify this is the intended behavior - should the lastTriggeredTime be updated even when processing fails? This could potentially lead to lost audit logs if errors persist.


149-150: LGTM: Proper result object return.

Returning Commit after successful processing follows the expected pattern for queue result handling.

@christyjacob4 christyjacob4 merged commit 3a1cd22 into 1.7.x Jun 4, 2025
38 checks passed
@christyjacob4 christyjacob4 deleted the PLA-2683 branch June 4, 2025 09:44
@coderabbitai coderabbitai bot mentioned this pull request Aug 31, 2025
2 tasks
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.

2 participants