-
Notifications
You must be signed in to change notification settings - Fork 0
LOGC-6: Implement S3 uploader #10
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,10 @@ name: tests | |
| on: | ||
| push: | ||
|
|
||
| permissions: | ||
| contents: read | ||
| packages: read | ||
|
|
||
| jobs: | ||
| build-test: | ||
| name: Build and test | ||
|
|
@@ -21,6 +25,19 @@ jobs: | |
| with: | ||
| go-version: '1.24' | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Login to Registry | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.repository_owner }} | ||
| password: ${{ github.token }} | ||
|
|
||
| - name: Start Workbench | ||
| uses: scality/[email protected] | ||
|
|
||
| - name: Start ClickHouse | ||
| run: docker compose up -d | ||
|
|
||
|
|
@@ -52,6 +69,12 @@ jobs: | |
| name: log-courier | ||
| path: ./bin/log-courier | ||
|
|
||
| - name: Stop Workbench | ||
| if: always() | ||
| run: | | ||
| workbench logs | ||
| workbench down | ||
|
|
||
| - name: Stop ClickHouse | ||
| if: always() | ||
| run: | | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Generated by workbench | ||
| /* | ||
| !values.yaml | ||
| !.gitignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| global: | ||
| log_level: info | ||
|
|
||
| features: | ||
| scuba: | ||
| enabled: false | ||
| enable_service_user: false | ||
|
|
||
|
|
||
| cloudserver: | ||
| image: ghcr.io/scality/cloudserver:7.70.77 | ||
|
|
||
| vault: | ||
| image: ghcr.io/scality/vault:7.81.0 | ||
|
|
||
| s3_metadata: | ||
| image: ghcr.io/scality/metadata:8.19.0-standalone | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| package s3 | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "time" | ||
|
|
||
| "github.com/aws/aws-sdk-go-v2/aws" | ||
| "github.com/aws/aws-sdk-go-v2/aws/retry" | ||
| "github.com/aws/aws-sdk-go-v2/config" | ||
| "github.com/aws/aws-sdk-go-v2/credentials" | ||
| "github.com/aws/aws-sdk-go-v2/service/s3" | ||
| ) | ||
|
|
||
| const ( | ||
| defaultRegion = "us-east-1" | ||
| ) | ||
|
|
||
| // Client wraps S3 client | ||
| type Client struct { | ||
| s3Client *s3.Client | ||
| } | ||
|
|
||
| // Config holds S3 client configuration | ||
| type Config struct { | ||
| Endpoint string | ||
| AccessKeyID string | ||
| SecretAccessKey string | ||
| MaxRetryAttempts int | ||
| MaxBackoffDelay time.Duration | ||
| } | ||
|
|
||
| // NewClient creates a new S3 client | ||
| func NewClient(ctx context.Context, cfg Config) (*Client, error) { | ||
| if cfg.AccessKeyID == "" || cfg.SecretAccessKey == "" { | ||
| return nil, fmt.Errorf("access key ID and secret access key are required") | ||
| } | ||
|
|
||
| var optFns []func(*config.LoadOptions) error | ||
|
|
||
| // Set region and credentials | ||
| optFns = append(optFns, | ||
| config.WithRegion(defaultRegion), | ||
| config.WithCredentialsProvider( | ||
| credentials.NewStaticCredentialsProvider( | ||
| cfg.AccessKeyID, | ||
| cfg.SecretAccessKey, | ||
| "", | ||
| ), | ||
| ), | ||
| ) | ||
|
|
||
| // Set retry configuration if non-zero values provided | ||
| if cfg.MaxRetryAttempts > 0 || cfg.MaxBackoffDelay > 0 { | ||
| optFns = append(optFns, config.WithRetryer(func() aws.Retryer { | ||
| retryer := retry.NewStandard() | ||
| var result aws.Retryer = retryer | ||
| if cfg.MaxRetryAttempts > 0 { | ||
| result = retry.AddWithMaxAttempts(result, cfg.MaxRetryAttempts) | ||
| } | ||
| if cfg.MaxBackoffDelay > 0 { | ||
| result = retry.AddWithMaxBackoffDelay(result, cfg.MaxBackoffDelay) | ||
| } | ||
| return result | ||
| })) | ||
| } | ||
|
|
||
| awsCfg, err := config.LoadDefaultConfig(ctx, optFns...) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to load AWS config: %w", err) | ||
| } | ||
|
|
||
| // Create S3 client | ||
| s3ClientOpts := []func(*s3.Options){} | ||
|
|
||
| // Set endpoint | ||
| if cfg.Endpoint != "" { | ||
| s3ClientOpts = append(s3ClientOpts, func(o *s3.Options) { | ||
| o.BaseEndpoint = aws.String(cfg.Endpoint) | ||
| o.UsePathStyle = true // Required for non-AWS S3-compatible services | ||
| }) | ||
| } | ||
|
|
||
| s3Client := s3.NewFromConfig(awsCfg, s3ClientOpts...) | ||
|
|
||
| return &Client{s3Client: s3Client}, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package s3 | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/aws/aws-sdk-go-v2/aws" | ||
| "github.com/aws/aws-sdk-go-v2/service/s3" | ||
| ) | ||
|
|
||
| // Uploader uploads log objects to S3 | ||
| type Uploader struct { | ||
| client *Client | ||
| } | ||
|
|
||
| // NewUploader creates a new uploader | ||
| func NewUploader(client *Client) *Uploader { | ||
| return &Uploader{client: client} | ||
| } | ||
|
|
||
| // Upload uploads a log object to the specified bucket. | ||
| // Retries are handled automatically by the SDK client based on its retry configuration. | ||
| func (u *Uploader) Upload(ctx context.Context, bucket, key string, content []byte) error { | ||
BourgoisMickael marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _, err := u.client.s3Client.PutObject(ctx, &s3.PutObjectInput{ | ||
| Bucket: aws.String(bucket), | ||
| Key: aws.String(key), | ||
| Body: bytes.NewReader(content), | ||
| ContentType: aws.String("text/plain"), | ||
| }) | ||
|
|
||
| if err != nil { | ||
| return fmt.Errorf("failed to upload to S3: bucket=%s, key=%s: %w", bucket, key, err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/scality/Federation/blob/development/9.5/group_vars/all#L203
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we cannot directly bump to version 9, we need to update the cloud server config. I created https://scality.atlassian.net/browse/WKBCH-9 to do it separately.