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

feat: expose bundle retry settings #268

Merged
merged 5 commits into from
Jan 15, 2025
Merged

Conversation

karlprieb
Copy link
Collaborator

No description provided.

@karlprieb karlprieb requested a review from djwhitt January 13, 2025 19:44
Copy link

codecov bot commented Jan 13, 2025

Codecov Report

Attention: Patch coverage is 45.28302% with 29 lines in your changes missing coverage. Please review.

Project coverage is 71.59%. Comparing base (cb2f03e) to head (a7e552b).
Report is 18 commits behind head on develop.

Files with missing lines Patch % Lines
src/data/gateways-data-source.ts 23.68% 29 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #268      +/-   ##
===========================================
- Coverage    71.75%   71.59%   -0.16%     
===========================================
  Files           37       37              
  Lines         9280     9330      +50     
  Branches       537      537              
===========================================
+ Hits          6659     6680      +21     
- Misses        2617     2646      +29     
  Partials         4        4              

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

Copy link
Contributor

coderabbitai bot commented Jan 13, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

error @permaweb/[email protected]: The engine "yarn" is incompatible with this module. Expected version "please-use-npm". Got "1.22.22"
error Found incompatible module.

📝 Walkthrough

Walkthrough

This pull request introduces new configuration options for an AR.IO node by adding environment variables and updating corresponding configuration files. The changes focus on three main areas: trusted gateway request timeouts, bundle repair retry intervals, and bundle repair batch sizes. These modifications allow for more granular control over gateway request handling and bundle repair processes by enabling external configuration through environment variables with sensible default values.

Changes

File Change Summary
docker-compose.yaml Added three new environment variables for core service: TRUSTED_GATEWAYS_REQUEST_TIMEOUT_MS, BUNDLE_REPAIR_RETRY_INTERVAL_SECONDS, and BUNDLE_REPAIR_RETRY_BATCH_SIZE
docs/envs.md Updated documentation with new environment variables and their default values
src/config.ts Added three new exported constants matching the new environment variables
src/data/gateways-data-source.ts Updated constructor to use new TRUSTED_GATEWAYS_REQUEST_TIMEOUT_MS config, added request/response interceptors for logging
src/workers/bundle-repair-worker.ts Replaced hardcoded constants with configuration-driven values for retry interval and batch size

Possibly related PRs

  • feat(post-chunk): post chunks to secondary urls #257: The changes in this PR also introduce new environment variables related to the core service in the docker-compose.yaml file, similar to the main PR, which adds environment variables for managing bundle repair processes.

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.

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. (Beta)
  • @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.

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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
docs/envs.md (1)

79-80: Enhance documentation for bundle repair settings.

The descriptions for the bundle repair settings could be more detailed to help users understand their impact.

Consider updating the descriptions to:

-| BUNDLE_REPAIR_RETRY_INTERVAL_SECONDS | String | "300" | Interval in seconds for retrying bundles |
-| BUNDLE_REPAIR_RETRY_BATCH_SIZE | String | "1000" | Batch size for retrying bundles |
+| BUNDLE_REPAIR_RETRY_INTERVAL_SECONDS | String | "300" | Time interval in seconds between attempts to repair failed bundle processing |
+| BUNDLE_REPAIR_RETRY_BATCH_SIZE | String | "1000" | Maximum number of failed bundles to process in each repair attempt |
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4bcdacb and 14e70be.

📒 Files selected for processing (6)
  • docker-compose.yaml (2 hunks)
  • docs/envs.md (2 hunks)
  • src/config.ts (2 hunks)
  • src/data/gateways-data-source.test.ts (4 hunks)
  • src/data/gateways-data-source.ts (3 hunks)
  • src/workers/bundle-repair-worker.ts (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test (macos-latest)
🔇 Additional comments (12)
src/workers/bundle-repair-worker.ts (3)

19-19: LGTM!

The import statement is correctly added and follows the project's import style.


68-68: LGTM!

The retry interval is correctly configured using the environment variable, with proper conversion from seconds to milliseconds.


106-106: LGTM!

The batch size is correctly configured using the environment variable.

src/data/gateways-data-source.ts (2)

32-32: LGTM!

The import statement is correctly added and follows the project's import style.


42-42: LGTM!

The request timeout is correctly configured using the environment variable.

src/data/gateways-data-source.test.ts (3)

28-34: LGTM!

The helper function correctly encapsulates common mock parameters and follows TypeScript conventions.


56-56: LGTM!

The mock setup correctly uses the helper function.


138-138: LGTM!

The mock setup in test cases correctly uses the helper function.

Also applies to: 176-176

src/config.ts (2)

90-93: LGTM!

The gateway request timeout configuration is correctly added with a sensible default value of 10 seconds.


260-263: LGTM!

The bundle repair retry interval configuration is correctly added with a sensible default value of 5 minutes.

docs/envs.md (1)

12-12: LGTM! Well-documented timeout setting.

The new timeout setting is properly documented with a clear type, default value, and description.

docker-compose.yaml (1)

50-50: LGTM! Environment variables are properly configured.

The new environment variables are:

  • Added to the correct service
  • Follow the established pattern for variable declaration
  • Logically grouped with related settings

Also applies to: 121-122

Comment on lines +106 to +140
gatewayAxios.interceptors.request.use((config) => {
this.log.debug('Axios request initiated', {
url: config.url,
method: config.method,
headers: config.headers,
params: config.params,
timeout: config.timeout,
});
return config;
});

gatewayAxios.interceptors.response.use(
(response) => {
this.log.debug('Axios response received', {
url: response.config.url,
status: response.status,
headers: response.headers,
});
return response;
},
(error) => {
if (error.response) {
this.log.error('Axios response error', {
url: error.response.config.url,
status: error.response.status,
headers: error.response.headers,
});
} else {
this.log.error('Axios network error', {
message: error.message,
});
}
return Promise.reject(error);
},
);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve logging security and consistency.

The interceptors enhance observability but have some concerns:

  1. Avoid logging sensitive information in headers that might contain auth tokens.
  2. Use consistent log levels - consider using debug for successful responses and warn for errors.

Apply this diff to improve the logging implementation:

 gatewayAxios.interceptors.request.use((config) => {
   this.log.debug('Axios request initiated', {
     url: config.url,
     method: config.method,
-    headers: config.headers,
     params: config.params,
     timeout: config.timeout,
   });
   return config;
 });

 gatewayAxios.interceptors.response.use(
   (response) => {
     this.log.debug('Axios response received', {
       url: response.config.url,
       status: response.status,
-      headers: response.headers,
     });
     return response;
   },
   (error) => {
     if (error.response) {
-      this.log.error('Axios response error', {
+      this.log.warn('Axios response error', {
         url: error.response.config.url,
         status: error.response.status,
-        headers: error.response.headers,
       });
     } else {
-      this.log.error('Axios network error', {
+      this.log.warn('Axios network error', {
         message: error.message,
       });
     }
     return Promise.reject(error);
   },
 );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
gatewayAxios.interceptors.request.use((config) => {
this.log.debug('Axios request initiated', {
url: config.url,
method: config.method,
headers: config.headers,
params: config.params,
timeout: config.timeout,
});
return config;
});
gatewayAxios.interceptors.response.use(
(response) => {
this.log.debug('Axios response received', {
url: response.config.url,
status: response.status,
headers: response.headers,
});
return response;
},
(error) => {
if (error.response) {
this.log.error('Axios response error', {
url: error.response.config.url,
status: error.response.status,
headers: error.response.headers,
});
} else {
this.log.error('Axios network error', {
message: error.message,
});
}
return Promise.reject(error);
},
);
gatewayAxios.interceptors.request.use((config) => {
this.log.debug('Axios request initiated', {
url: config.url,
method: config.method,
params: config.params,
timeout: config.timeout,
});
return config;
});
gatewayAxios.interceptors.response.use(
(response) => {
this.log.debug('Axios response received', {
url: response.config.url,
status: response.status,
});
return response;
},
(error) => {
if (error.response) {
this.log.warn('Axios response error', {
url: error.response.config.url,
status: error.response.status,
});
} else {
this.log.warn('Axios network error', {
message: error.message,
});
}
return Promise.reject(error);
},
);

src/config.ts Outdated Show resolved Hide resolved
karlprieb and others added 2 commits January 13, 2025 18:23
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/config.ts (1)

265-268: Add a comment explaining the default batch size.

Consider adding a comment to explain why 1000 was chosen as the default batch size, similar to how the retry interval is documented.

 export const BUNDLE_REPAIR_RETRY_BATCH_SIZE = +env.varOrDefault(
   'BUNDLE_REPAIR_RETRY_BATCH_SIZE',
-  '1000',
+  '1000', // Process 1000 items per batch to balance throughput and memory usage
 );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 30deac3 and a7e552b.

📒 Files selected for processing (1)
  • src/config.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test (macos-latest)
  • GitHub Check: test (ubuntu-latest)
🔇 Additional comments (2)
src/config.ts (2)

90-93: LGTM! The timeout configuration looks good.

The default timeout of 10 seconds is reasonable for HTTP requests to trusted gateways.


260-263: LGTM! Well-documented retry interval configuration.

The default interval of 5 minutes is reasonable for retry operations, and the comment clearly explains the value.

@djwhitt djwhitt merged commit 14fc452 into develop Jan 15, 2025
6 checks passed
@djwhitt djwhitt deleted the PE-7419-bundle-retry-settings branch January 15, 2025 19:01
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