Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/update_indexer_cookie_policy #308

Merged
merged 2 commits into from
Feb 29, 2024
Merged

Conversation

aarmoa
Copy link
Collaborator

@aarmoa aarmoa commented Feb 29, 2024

  • Updated cookie assistant logic to support the Indexer exchange server not using cookies and the chain server using them

Summary by CodeRabbit

  • New Features

    • Updated cookie assistant logic to support environments with and without cookie usage.
  • Bug Fixes

    • Improved error handling for cookie retrieval and verification processes.
  • Tests

    • Added tests for the updated cookie assistant logic, ensuring reliable network communication handling.

@aarmoa aarmoa requested a review from nicolasbaum February 29, 2024 14:35
Copy link
Contributor

coderabbitai bot commented Feb 29, 2024

Walkthrough

The update primarily refines the handling of cookies within network communication, accommodating scenarios where cookies are not used by the Indexer exchange server but are required by the chain server. It introduces checks and error handling for cookie-related operations, ensuring robustness in network metadata management. Additionally, the removal of asyncio dependency in a previous version suggests a shift towards simplifying the codebase or changing the approach to asynchronous programming.

Changes

File Summary
CHANGELOG.md Updated cookie assistant logic; Removed asyncio dependency.
pyinjective/core/network.py Enhanced cookie handling in exchange_metadata; Improved error handling and checks for cookie expiration.
tests/core/test_network.py Added tests for cookie handling in network communication.

🐇💻
In the land of code, where the snippets roam free,
A rabbit hopped in, with changes to see.
"No more waiting," it said, with a twirl,
For cookies to crumble, in this digital world.
With a hop and a skip, it went on its way,
Leaving behind code, more robust today.
🍪🔧


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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

codecov bot commented Feb 29, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 74.92%. Comparing base (9aae397) to head (8cebde5).

Files Patch % Lines
pyinjective/core/network.py 80.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #308      +/-   ##
==========================================
+ Coverage   73.06%   74.92%   +1.85%     
==========================================
  Files          48       48              
  Lines        3416     3422       +6     
  Branches      304      306       +2     
==========================================
+ Hits         2496     2564      +68     
+ Misses        839      772      -67     
- Partials       81       86       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

expiration_time = 0
else:
expiration_time = datetime.datetime.strptime(
cookie["GCLB"]["expires"], "%a, %d-%b-%Y %H:%M:%S %Z"
Copy link

@nicolasbaum nicolasbaum Feb 29, 2024

Choose a reason for hiding this comment

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

Is there any chance "GCLB" key is present, but "expires" sub-key is not?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not in the examples I checked. If that happens the expiration check should fail, since that would be unexpected.
There is no way to test it correctly now because there are no k8s servers supported

Copy link
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9aae397 and cee3bfb.
Files ignored due to path filters (1)
  • pyproject.toml is excluded by: !**/*.toml
Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • pyinjective/core/network.py (4 hunks)
  • tests/core/test_network.py (1 hunks)
Additional comments: 14
tests/core/test_network.py (8)
  • 6-18: The test test_chain_metadata in the TestBareMetalLoadBalancedCookieAssistant class correctly simulates the scenario where a cookie is present in the server response and asserts that the metadata is correctly formed. This test is well-structured and follows best practices for asynchronous testing with pytest.
  • 20-29: The test test_chain_metadata_fails_when_cookie_info_not_included_in_server_response in the TestBareMetalLoadBalancedCookieAssistant class effectively simulates a failure scenario where the server response does not include cookie information. The use of pytest.raises to expect a RuntimeError is appropriate and correctly implemented.
  • 31-42: The test test_exchange_metadata in the TestBareMetalLoadBalancedCookieAssistant class correctly simulates the scenario where a cookie is present in the server response for exchange metadata. The test is well-structured, and the assertion validates the expected behavior correctly.
  • 44-54: The test test_exchange_metadata_is_none_when_cookie_info_not_included_in_server_response in the TestBareMetalLoadBalancedCookieAssistant class effectively tests the scenario where no cookie information is included in the server response for exchange metadata. The assertion that metadata is None is correct and aligns with the expected behavior.
  • 57-69: The test test_chain_metadata in the TestKubernetesLoadBalancedCookieAssistant class correctly simulates the scenario where a cookie is present in the server response and asserts that the metadata is correctly formed. This test mirrors the structure and logic of the corresponding test in the TestBareMetalLoadBalancedCookieAssistant class, maintaining consistency across tests.
  • 71-80: The test test_chain_metadata_fails_when_cookie_info_not_included_in_server_response in the TestKubernetesLoadBalancedCookieAssistant class effectively simulates a failure scenario where the server response does not include cookie information. The use of pytest.raises to expect a RuntimeError is appropriate and correctly implemented, mirroring the structure of the corresponding test in the TestBareMetalLoadBalancedCookieAssistant class.
  • 82-93: The test test_exchange_metadata in the TestKubernetesLoadBalancedCookieAssistant class correctly simulates the scenario where a cookie is present in the server response for exchange metadata. The test is well-structured, and the assertion validates the expected behavior correctly, mirroring the structure of the corresponding test in the TestBareMetalLoadBalancedCookieAssistant class.
  • 95-105: The test test_exchange_metadata_is_none_when_cookie_info_not_included_in_server_response in the TestKubernetesLoadBalancedCookieAssistant class effectively tests the scenario where no cookie information is included in the server response for exchange metadata. The assertion that metadata is None is correct and aligns with the expected behavior, mirroring the structure of the corresponding test in the TestBareMetalLoadBalancedCookieAssistant class.
CHANGELOG.md (2)
  • 5-9: The changelog entry for version 1.3.1 clearly outlines the changes made to the cookie assistant logic to accommodate the different cookie policies of the Indexer exchange server and the chain server. This entry is concise and informative, providing a clear summary of the changes and their impact.
  • 9-9: The changelog entry for version 1.3.0 mentions the removal of asyncio from the dependencies. This entry is clear and concise, accurately reflecting a significant change that could affect users and developers working with the software.
pyinjective/core/network.py (4)
  • 26-29: The modification in the exchange_metadata method to return None when the cookie is either None or an empty string is a logical and clean way to handle scenarios where cookies are not applicable. This change ensures that the method's behavior is consistent with the expected functionality in environments where cookies are not used.
  • 73-73: Setting cookie_info to an empty string when no cookie is present in the _fetch_exchange_cookie method of the KubernetesLoadBalancedCookieAssistant class is a sensible default. This change prevents potential NoneType errors in subsequent operations involving cookie_info.
  • 89-94: The addition of a check for the "GCLB" key in the cookie before accessing its expiration time in the _is_cookie_expired method enhances the robustness of the cookie expiration logic. This change ensures that the method only operates on valid cookie data, preventing potential KeyError exceptions.
  • 141-141: Similar to the KubernetesLoadBalancedCookieAssistant class, setting cookie_info to an empty string when no cookie is present in the _fetch_exchange_cookie method of the BareMetalLoadBalancedCookieAssistant class is a prudent choice. This ensures consistency in handling cookie information across different assistant classes.

…s assistant to tackle the suggestion in the PR review
@aarmoa aarmoa requested a review from nicolasbaum February 29, 2024 14:51
@aarmoa aarmoa merged commit 83152b2 into master Feb 29, 2024
12 checks passed
@aarmoa aarmoa deleted the fix/update_indexer_cookie_policy branch February 29, 2024 14:53
Copy link
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between cee3bfb and 8cebde5.
Files selected for processing (1)
  • pyinjective/core/network.py (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • pyinjective/core/network.py

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