Skip to content

Conversation

wdbaruni
Copy link
Member

@wdbaruni wdbaruni commented Feb 5, 2025

Add plain encoding option to S3 Publisher

Description

This PR adds support for publishing job results without gzip compression through a new Encoding type. This enables more efficient data pipelines where subsequent jobs need to access individual files from previous job results.

Previously, all job results were automatically gzip compressed before uploading to S3. While this is efficient for storage and download, it requires downloading and decompressing the entire archive to access any file. This can be inefficient for workflows like map-reduce where jobs only need specific files from previous results.

Changes

  • Added new Encoding type with EncodingGzip (default) and EncodingPlain options
  • Updated validation to check for valid encoding values
  • Maintains gzip compression as default behavior for backwards compatibility

Benefits and Tradeoffs

Benefits

  • Enables efficient access to individual files from job results
  • Better support for data pipelines where jobs consume partial results
  • No decompression overhead when accessing results

Tradeoffs

  • More S3 PUT requests (one per file vs one archive)
  • Higher storage costs (no compression)
  • Higher network costs for full result downloads
  • Cannot use bacalhau job get with pre-signed URLs when using plain encoding (requires individual file URLs)

Usage Recommendations

  • Use plain encoding when:
    • Subsequent jobs need to access individual files
    • Results will be frequently accessed by file
    • Building data pipelines with partial result access
  • Keep default gzip encoding when:
    • Results are typically accessed as a complete set
    • Storage/transfer costs are a concern
    • Using bacalhau job get functionality

Summary by CodeRabbit

  • New Features

    • Enhanced S3 publishing now supports flexible encoding options, allowing for compressed archive uploads (gzip) or individual file uploads (plain).
    • New test cases added to validate different encoding scenarios for both publishing and downloading.
    • Improved handling of publisher specifications with a focus on encoding types.
  • Bug Fixes

    • Addressed error handling for invalid encoding values in publisher specifications.
  • Documentation

    • Updated test cases to reflect changes in encoding handling and improve overall test coverage.

Copy link

linear bot commented Feb 5, 2025

Copy link
Contributor

coderabbitai bot commented Feb 5, 2025

Walkthrough

The changes refactor the S3 publisher configuration and publishing process. The extraction of S3 options is streamlined by replacing individual variable handling with a unified parameters map. Test cases are updated to use lowercase key names and include an encoding field. In the publisher, the PublishResult method now branches based on encoding, invoking either publishArchive for gzip compression or publishDirectory for plain uploads. Additionally, the S3 testing suite and types are updated to incorporate a new Encoding type with validation while removing the older functional options.

Changes

File(s) Change Summary
cmd/util/opts/publisher_specconfig.go
cmd/util/opts/publisher_specconfig_test.go
Refactored S3 publisher option extraction: consolidated bucket and key handling into a single parameters map; updated tests to expect lowercase keys and added an encoding test case.
pkg/publisher/s3/publisher.go
pkg/publisher/s3/publisher_test.go
Enhanced publisher functionality: added publishArchive and publishDirectory methods; updated PublishResult to branch based on encoding; refined test cases for different encoding scenarios.
pkg/s3/test/suite.go Modified helper methods to accept an encoding parameter instead of a boolean flag, changing prefix logic in preparing the publisher specification.
pkg/s3/types.go
pkg/s3/types_test.go
Introduced new Encoding type with constants (gzip and plain) and validation; added the Encoding field to PublisherSpec; removed the functional options pattern; updated tests to cover encoding validation and decoding.
pkg/downloader/s3signed/downloader_test.go Added test for uncompressed downloads; modified existing tests to specify encoding for compressed downloads.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Publisher
    participant S3Service

    Client->>Publisher: Call PublishResult(spec)
    alt Encoding is "plain"
        Publisher->>Publisher: Invoke publishDirectory()
        Publisher->>S3Service: Upload files individually
    else Encoding is "gzip"
        Publisher->>Publisher: Invoke publishArchive()
        Publisher->>S3Service: Upload GZIP archive
    end
    S3Service-->>Publisher: Return upload status
    Publisher-->>Client: Return SpecConfig with results
Loading

Suggested reviewers

  • jamlo

Poem

I'm a bunny with a coding hat,
Hopping through the changes, imagine that!
With options now in a tidy map,
And publisher methods closing the gap.
My whiskers twitch with delight so grand—
Code hops smoother across the S3 land!
🐰✨

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a20383a and 6d94374.

📒 Files selected for processing (1)
  • pkg/downloader/download_test.go (1 hunks)
🔇 Additional comments (2)
pkg/downloader/download_test.go (2)

141-141: LGTM! The encoding parameter updates look good.

The changes correctly update the encoding parameter from boolean to s3helper.EncodingGzip, maintaining backward compatibility.

Also applies to: 149-149


180-220: Add test cases for plain encoding.

The test suite is missing coverage for the new plain encoding functionality. Consider adding test cases to verify that:

  1. Files are uploaded without compression when using plain encoding
  2. Files can be downloaded correctly when using plain encoding
  3. The system handles mixed scenarios (some files with gzip, others with plain encoding)

Here's a script to verify the current test coverage for plain encoding:

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Description: Check if there are any test cases for plain encoding
# Test: Search for EncodingPlain in test files. Expect: Test cases using plain encoding.

echo "Searching for plain encoding test cases in Go files..."
rg -t go "EncodingPlain" .

echo "Searching for test function names related to plain/uncompressed..."
rg -t go "Test.*[Pp]lain|Test.*[Uu]ncompressed" .

Length of output: 1584


Plain encoding tests are adequately covered.

  • Tests in pkg/downloader/s3signed/downloader_test.go (e.g., TestDownloadUncompressed) verify that uncompressed downloads work as intended.
  • Additional tests checking plain encoding exist in pkg/publisher/s3/publisher_test.go, pkg/s3/types_test.go, and others, confirming that files uploaded with s3helper.EncodingPlain are correctly handled.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 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: 0

🧹 Nitpick comments (3)
pkg/publisher/s3/publisher.go (2)

65-67: Defaulting to archive encoding is reasonable.
Consider logging at debug or trace level if no encoding is specified, to help with troubleshooting.


129-192: Directory publishing is implemented well.
To enhance performance on large directories, consider supporting concurrent uploads. If partial success is acceptable, you may want to continue walking after individual file upload failures.

pkg/s3/types.go (1)

97-106: LGTM! Consider adding documentation.

The Encoding type and its validation are well-designed. Consider adding documentation to describe the purpose and usage of each encoding type.

+// Encoding represents the type of encoding used for S3 objects
 type Encoding string

 const (
+    // EncodingGzip represents gzip compression encoding
     EncodingGzip  Encoding = "gzip"
+    // EncodingPlain represents no compression encoding
     EncodingPlain Encoding = "plain"
 )

+// IsValid checks if the encoding is one of the supported types
 func (e Encoding) IsValid() bool {
     return e == EncodingGzip || e == EncodingPlain
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e1bdc53 and a5f42d9.

📒 Files selected for processing (7)
  • cmd/util/opts/publisher_specconfig.go (1 hunks)
  • cmd/util/opts/publisher_specconfig_test.go (3 hunks)
  • pkg/publisher/s3/publisher.go (3 hunks)
  • pkg/publisher/s3/publisher_test.go (2 hunks)
  • pkg/s3/test/suite.go (2 hunks)
  • pkg/s3/types.go (2 hunks)
  • pkg/s3/types_test.go (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: build / Build Binary (windows, amd64)
  • GitHub Check: build / Build Binary (darwin, arm64)
  • GitHub Check: build / Build Binary (darwin, amd64)
  • GitHub Check: build / Build Binary (linux, armv6)
  • GitHub Check: build / Build Binary (linux, armv7)
  • GitHub Check: build / Build Binary (linux, arm64)
  • GitHub Check: build / Build Binary (linux, amd64)
  • GitHub Check: lint / lint
🔇 Additional comments (13)
pkg/publisher/s3/publisher.go (3)

7-7: Good use of filepath import for directory traversal.
No issues spotted here.


61-63: Explicit handling for plain encoding.
This branching approach is clear and avoids confusion with other encodings. Ensure you have test coverage for unknown encodings.
[approve]


69-74: New publishArchive method.
This function is concise and well-structured for creating and uploading a compressed archive. Good job handling the temporary file cleanup.

cmd/util/opts/publisher_specconfig_test.go (4)

35-36: Lowercase keys for S3 parameters.
Aligns with the new approach of consistently lowercasing S3 keys in the spec. Looks good!


46-50: Maintaining lowercase key consistency with S3.
This ensures a uniform parameter format throughout the codebase.


53-64: Test coverage for new encoding parameter.
Great addition to confirm correctness of plain encoding handling.


71-73: Final set of lowercase keys in S3 config.
All tested variants are consistent now. No concerns here.

cmd/util/opts/publisher_specconfig.go (1)

103-119: Consolidated S3 option handling in params map.
This simplifies the logic and preserves flexibility for new parameters (like encoding). If needed, consider validating non-empty values for bucket and key to avoid misconfigurations.

pkg/s3/types_test.go (2)

29-29: LGTM! Good test coverage for encoding field.

The test cases thoroughly validate both plain and gzip encoding with proper case sensitivity handling.

Also applies to: 45-45, 52-52, 68-68, 75-75, 91-91


143-153: LGTM! Good error handling test coverage.

The test case properly validates error handling for invalid encoding values.

pkg/s3/types.go (1)

108-126: LGTM! Clean integration of encoding field.

The encoding field is well-integrated into the PublisherSpec struct with proper validation.

pkg/publisher/s3/publisher_test.go (1)

154-218: LGTM! Comprehensive test coverage.

The test cases thoroughly validate:

  • Both plain and gzip encoding
  • Various path patterns and edge cases
  • Proper handling of checksums and version IDs based on encoding
pkg/s3/test/suite.go (1)

149-163: LGTM! Clean refactor to support encoding.

The helper methods are well-updated to support the new encoding type with clear path generation logic.

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)
pkg/downloader/s3signed/downloader_test.go (1)

82-99: Good test coverage, but could be more descriptive.

The test effectively verifies that uncompressed downloads are not supported with pre-signed URLs, which aligns with the documented limitations. However, consider these improvements:

  1. The comment on line 90 should be updated as we're testing an unsigned URL.
  2. Add an error message assertion to verify the specific failure reason.
-	// download signed url
+	// attempt to download unsigned url
 	downloadParentPath, err := os.MkdirTemp(s.TempDir, "")
 	s.Require().NoError(err)

 	_, err = s.downloader.FetchResult(s.Ctx, downloader.DownloadItem{
 		Result:     &storageSpec,
 		ParentPath: downloadParentPath,
 	})
-	s.Require().Error(err)
+	s.Require().Error(err)
+	s.Contains(err.Error(), "unsupported storage source type", "should fail with unsupported source type error")
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a5f42d9 and a20383a.

📒 Files selected for processing (1)
  • pkg/downloader/s3signed/downloader_test.go (2 hunks)
🔇 Additional comments (1)
pkg/downloader/s3signed/downloader_test.go (1)

56-80: LGTM! Clean transition to the new encoding type.

The test has been updated to use the new EncodingGzip constant while maintaining the same robust verification flow.

@wdbaruni wdbaruni merged commit 8ae8a00 into main Feb 5, 2025
13 of 14 checks passed
@wdbaruni wdbaruni deleted the eng-606-support-plain-encoding-for-s3-results branch February 5, 2025 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant