Skip to content

Fix: Saving errors status in cache - #28

Merged
syphax-bouazzouni merged 3 commits into
masterfrom
fix/saving-errors-in-cache
May 11, 2025
Merged

syphax-bouazzouni merged 3 commits into
masterfrom
fix/saving-errors-in-cache

Conversation

@syphax-bouazzouni

@syphax-bouazzouni syphax-bouazzouni commented May 11, 2025 •

Copy link
Copy Markdown

Fixes agroportal/project-management#712. In the scope of the federation work (#24), we introduced a status cache to store the availability of federated portals. If a portal is down, its status is cached for 10 minutes to avoid unnecessary requests. However, the issue was that errors from the current portal were also cached, unintentionally blocking it for 10 minutes and requiring to clear the cache.

Summary by CodeRabbit

  • New Features

    • Improved debug logging with a centralized method, making it easier to control and standardize debug output.
    • Enhanced error logging for portal connectivity issues, providing clearer information when a portal is down.
  • Refactor

    • Streamlined how portal parameters are handled and improved detection of internal calls for better reliability.

@syphax-bouazzouni
syphax-bouazzouni merged commit 1d8e1b2 into master May 11, 2025
@coderabbitai

coderabbitai Bot commented May 11, 2025

Copy link
Copy Markdown

Walkthrough

The changes introduce centralized debug logging in the LinkedData::Client::HTTP module by replacing direct puts statements with a new log method that outputs messages only if a global debug flag is set. In the LinkedData::Client::RequestFederation module, error logging is enhanced and parameter handling is refined to use portal-specific parameters. The retrieval of federated portal names is refactored into a new helper method, and a new method is added to detect internal calls for improved caching logic. Method signatures and internal logic are updated to support these changes. No core request or response processing logic is altered.

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
lib/ontologies_api_client/request_federation.rb (1)

31-37: Fixed portal-specific parameter handling and caching behavior

This change addresses the core issue described in the PR by:

  1. Using portal-specific parameters when available (params[portal_name.to_s.downcase])
  2. Conditionally caching portal down status only when the call is not internal

The selective caching prevents the current portal's errors from being cached for 10 minutes, which was blocking access unnecessarily.

However, there's an unused exception variable that should be addressed:

- rescue Exception => e
+ rescue Exception
🧰 Tools
🪛 RuboCop (1.73)

[warning] 33-33: Useless assignment to variable - e.

(Lint/UselessAssignment)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fdd7d48 and 4c8cc9c.

📒 Files selected for processing (2)
  • lib/ontologies_api_client/http.rb (4 hunks)
  • lib/ontologies_api_client/request_federation.rb (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
lib/ontologies_api_client/request_federation.rb (1)
lib/ontologies_api_client/http.rb (4)
  • log (165-167)
  • get (61-102)
  • conn (46-55)
  • delete (153-159)
🪛 RuboCop (1.73)
lib/ontologies_api_client/request_federation.rb

[warning] 33-33: Useless assignment to variable - e.

(Lint/UselessAssignment)

🔇 Additional comments (6)
lib/ontologies_api_client/http.rb (2)

80-80: Improved logging implementation using centralized method

The changes replace direct puts statements with calls to the new centralized log method, ensuring consistent debugging output throughout the HTTP client.

Also applies to: 98-98, 154-154


165-167: Good addition of a centralized logging method

The addition of a centralized log method improves code organization and maintainability by:

  1. Providing a single point of control for debug output
  2. Consistently checking the debug flag before printing
  3. Making it easier to modify logging behavior in the future

This change complements the related improvements in the federation request handling.

lib/ontologies_api_client/request_federation.rb (4)

25-26: Improved error logging for down portals

Changed to use the centralized logging method which provides consistent debug output handling.


45-47: Good extraction of helper method for federation portal names

The new helper method federated_portals_names follows the DRY principle by extracting the common logic for retrieving federation portal names.


49-53: Improved request portals method

The updated request_portals method now uses the new helper method and properly removes the :federate parameter from params, preventing it from being passed to the API.


65-67: Good addition of internal call detection method

The new internal_call? method determines if a connection is for the current portal by comparing URL prefixes. This is a crucial part of fixing the caching issue, as it prevents caching errors for the current portal.

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.

Cache issues?

1 participant