Skip to content

Conversation

@SAKURA-CAT
Copy link
Member

@SAKURA-CAT SAKURA-CAT commented Dec 11, 2025

为了实现私有化后端对接多种对象存储,现将对象存储签名改为后端签名

同时优化了API部分的代码,为 #1369 做准备

Removed boto3/botocore dependencies and the CosClient, replacing direct COS upload logic with a new API-based approach using presigned URLs. Moved experiment state update logic to a dedicated API module and updated all usages. Refactored Client to remove COS logic, simplified session handling, and updated uploader and callback code to use the new APIs. Updated imports and tests to reflect file moves and API changes.
Added buffer.seek(0) before uploading to COS to ensure the buffer pointer is at the start. Also removed unused COS upload tests and related imports from test_client.py for code cleanup.
@SAKURA-CAT SAKURA-CAT self-assigned this Dec 11, 2025
@SAKURA-CAT SAKURA-CAT added 💪 enhancement New feature or request 👾 network Something caused by network errors labels Dec 11, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @SAKURA-CAT, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在增强SwanLab SDK的对象存储兼容性,通过将对象存储签名过程转移到后端,实现对多种私有对象存储解决方案的支持。这一改动涉及核心客户端的重构、引入新的API层来处理实验状态和文件上传,并清理了不再需要的客户端对象存储依赖和相关代码,从而提升了系统的灵活性和可扩展性。

Highlights

  • 对象存储签名机制变更: 为支持私有化部署和对接多种对象存储服务,对象存储的签名逻辑已从客户端迁移至后端处理。
  • 移除客户端COS模块: 原有的 swanlab.core_python.client.cos.py 模块及其 CosClient 类已被完全移除,相关的客户端上传逻辑也已从 Client 类中剥离。
  • 新增API模块: 新增了 swanlab/core_python/api/experiment.pyswanlab/core_python/api/service.py 两个模块,分别用于处理实验状态更新和通过后端签名URL进行文件上传。
  • 核心客户端重构: swanlab.core_python.client.Client 类进行了重构,移除了直接的对象存储操作方法和相关属性,转而调用新的API模块进行后端交互。同时,session.py 模块被移动到 swanlab/core_python/client/session.py
  • 依赖项更新: 由于不再进行客户端对象存储操作,requirements.txt 中移除了 boto3botocore 依赖。
  • 错误处理装饰器重命名: sync_error_handler 装饰器已重命名为 safe_request,并在代码库中进行了相应的更新。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

本次PR的核心改动是将对象存储的签名和上传逻辑从SDK端转移到了后端。现在SDK会从后端获取预签名URL,然后直接上传文件。这大大简化了SDK的逻辑,移除了对boto3等库的依赖,是一个很好的重构。

代码结构更加清晰,将API调用相关的函数移动到了新的swanlab/core_python/api目录中,例如update_experiment_stateupload_to_cos

我发现了一个在文件上传重试逻辑中的潜在bug,可能会导致重试失败或上传不完整的文件。除此之外,整体改动看起来很不错。

Relocated the buffer.seek(0) call from upload_to_cos to the _upload function to ensure the buffer is reset before uploading. This centralizes buffer handling and prevents redundant seeks.
Copy link

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 PR refactors the object storage upload mechanism to use backend-signed URLs instead of client-side signing with AWS credentials. This architectural change removes the dependency on boto3/botocore libraries and simplifies the client by delegating signing responsibilities to the backend server, which is important for supporting multiple object storage providers in private deployments.

Key Changes

  • Replaced client-side AWS credential-based signing (boto3) with backend pre-signed URL generation
  • Refactored client architecture by extracting session management and API endpoints into separate modules
  • Updated experiment state management to use a dedicated API function instead of client methods

Reviewed changes

Copilot reviewed 11 out of 13 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
swanlab/core_python/api/service.py New service API implementing backend-signed COS uploads with presigned URLs
swanlab/core_python/api/experiment.py New API module for experiment state updates
swanlab/core_python/client/session.py Extracted session creation logic from client module
swanlab/core_python/client/__init__.py Removed COS client logic, cleaned up API methods, simplified client structure
swanlab/core_python/client/cos.py Deleted boto3-based COS client implementation
swanlab/core_python/uploader/upload.py Updated to use new upload_to_cos function and renamed decorator
swanlab/data/porter/__init__.py Updated to use new experiment state API
swanlab/data/callbacker/cloud.py Updated to use new experiment state API
swanlab/core_python/auth/providers/api_key.py Updated import path for session module
swanlab/core_python/__init__.py Removed create_session export (now in client submodule)
test/unit/core_python/test_session.py Updated import path and removed trailing whitespace
test/unit/core_python/test_client.py Removed COS tests and updated exception type assertion
requirements.txt Removed boto3 and botocore dependencies

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Enhanced the file upload function with retry logic and exponential backoff for robustness against network errors. Added comprehensive unit tests to verify upload success, retry behavior, exception handling, and server error scenarios.
Enhanced the upload_to_cos function to better handle exceptions during concurrent uploads. Failed uploads are now logged with warnings and retried, with errors on retry attempts also logged for improved reliability and debugging.
@SAKURA-CAT
Copy link
Member Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

这个 Pull Request 主要重构了对象存储的实现,将签名过程移至后端,客户端通过获取预签名 URL 的方式上传文件。这使得客户端不再需要依赖 boto3,简化了依赖管理和客户端逻辑。相关的代码也进行了优化和拆分,例如将文件上传和实验状态更新的逻辑分别封装到了 swanlab/core_python/api/service.pyswanlab/core_python/api/experiment.py 中,使得 Client 类的职责更单一,代码结构更清晰。整体来看,这是一个很好的重构,提高了代码的可维护性和扩展性。我在代码中发现了一些可以改进的地方,主要涉及重试策略的实现和代码注释的清晰度,具体请看我的评论。

Changed the retry delay in upload_file to use exponential backoff (2^(attempt-1) seconds) instead of linear. Also removed a redundant comment in upload_to_cos for clarity.
Deleted the import of get_host_api and related code that handled URL prefixing for private environments, as it is no longer needed.
@SAKURA-CAT SAKURA-CAT merged commit ed3c13a into main Dec 12, 2025
5 checks passed
@SAKURA-CAT SAKURA-CAT deleted the feature/s3 branch December 12, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💪 enhancement New feature or request 👾 network Something caused by network errors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants