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: enhances S3Download to filter by traced table names #1374

Merged
merged 5 commits into from
Jun 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
updates S3Download to take into account table names
staheri14 committed Jun 4, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
staheri14 Sanaz Taheri
commit 67b90c23885af4921cff727db149812a8c2c7349
71 changes: 43 additions & 28 deletions pkg/trace/fileserver.go
Original file line number Diff line number Diff line change
@@ -259,7 +259,9 @@ func (lt *LocalTracer) PushAll() error {

// S3Download downloads files that match some prefix from an S3 bucket to a
// local directory dst.
func S3Download(dst, prefix string, cfg S3Config) error {
// tableNames is a list of traced jsonl file names to download. If it is empty, all traces are downloaded.
// tableNames should not have .jsonl suffix.
func S3Download(dst, prefix string, fileNames []string, cfg S3Config) error {
// Ensure local directory structure exists
err := os.MkdirAll(dst, os.ModePerm)
if err != nil {
@@ -288,37 +290,50 @@ func S3Download(dst, prefix string, cfg S3Config) error {

err = s3Svc.ListObjectsV2Pages(input, func(page *s3.ListObjectsV2Output, lastPage bool) bool {
for _, content := range page.Contents {
localFilePath := filepath.Join(dst, prefix, strings.TrimPrefix(*content.Key, prefix))
fmt.Printf("Downloading %s to %s\n", *content.Key, localFilePath)
key := *content.Key

// Create the directories in the path
if err := os.MkdirAll(filepath.Dir(localFilePath), os.ModePerm); err != nil {
return false
// If no fileNames are specified, download all files
if len(fileNames) == 0 {
fileNames = append(fileNames, strings.TrimPrefix(key, prefix))
}

// Create a file to write the S3 Object contents to.
f, err := os.Create(localFilePath)
if err != nil {
return false
}

resp, err := s3Svc.GetObject(&s3.GetObjectInput{
Bucket: aws.String(cfg.BucketName),
Key: aws.String(*content.Key),
})
if err != nil {
f.Close()
continue
for _, filename := range fileNames {
// Add .jsonl suffix to the fileNames
fullFilename := filename + ".jsonl"
if strings.HasSuffix(key, fullFilename) {
localFilePath := filepath.Join(dst, prefix, strings.TrimPrefix(key, prefix))
fmt.Printf("Downloading %s to %s\n", key, localFilePath)

// Create the directories in the path
if err := os.MkdirAll(filepath.Dir(localFilePath), os.ModePerm); err != nil {
return false
}

// Create a file to write the S3 Object contents to.
f, err := os.Create(localFilePath)
if err != nil {
return false
}

resp, err := s3Svc.GetObject(&s3.GetObjectInput{
Bucket: aws.String(cfg.BucketName),
Key: aws.String(key),
})
if err != nil {
f.Close()
continue
}
defer resp.Body.Close()

// Copy the contents of the S3 object to the local file
if _, err := io.Copy(f, resp.Body); err != nil {
return false
}

fmt.Printf("Successfully downloaded %s to %s\n", key, localFilePath)
f.Close()
}
}
defer resp.Body.Close()

// Copy the contents of the S3 object to the local file
if _, err := io.Copy(f, resp.Body); err != nil {
return false
}

fmt.Printf("Successfully downloaded %s to %s\n", *content.Key, localFilePath)
f.Close()
}
return !lastPage // continue paging
})
Loading