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: implement object storage delete validations for warehouse destinations #5456

Merged
merged 3 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions warehouse/internal/model/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import backendconfig "github.com/rudderlabs/rudder-server/backend-config"

const (
VerifyingObjectStorage = "Verifying Object Storage"
VerifyingObjectStorageDelete = "Verifying delete permissions in object storage"
achettyiitr marked this conversation as resolved.
Show resolved Hide resolved
VerifyingConnections = "Verifying Connections"
VerifyingCreateSchema = "Verifying Create Schema"
VerifyingCreateAndAlterTable = "Verifying Create and Alter Table"
Expand Down
7 changes: 7 additions & 0 deletions warehouse/validations/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ func StepsToValidate(dest *backendconfig.DestinationT) *model.StepsResponse {
ID: len(steps) + 1,
Name: model.VerifyingObjectStorage,
}}
cleanupObjectStorageFiles, _ := dest.Config[model.CleanupObjectStorageFilesSetting.String()].(bool)
if cleanupObjectStorageFiles {
steps = append(steps, &model.Step{
ID: len(steps) + 1,
Name: model.VerifyingObjectStorageDelete,
})
}

switch destType {
case warehouseutils.GCSDatalake, warehouseutils.AzureDatalake:
Expand Down
38 changes: 38 additions & 0 deletions warehouse/validations/steps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,27 @@ func TestValidationSteps(t *testing.T) {
DestinationDefinition: backendconfig.DestinationDefinitionT{
Name: warehouseutils.GCSDatalake,
},
Config: map[string]interface{}{
model.CleanupObjectStorageFilesSetting.String(): false,
},
},
steps: []string{model.VerifyingObjectStorage},
},
{
name: "GCS with cleanup enabled",
dest: backendconfig.DestinationT{
DestinationDefinition: backendconfig.DestinationDefinitionT{
Name: warehouseutils.GCSDatalake,
},
Config: map[string]interface{}{
model.CleanupObjectStorageFilesSetting.String(): true,
},
},
steps: []string{
model.VerifyingObjectStorage,
model.VerifyingObjectStorageDelete,
},
},
{
name: "Azure",
dest: backendconfig.DestinationT{
Expand Down Expand Up @@ -83,6 +101,26 @@ func TestValidationSteps(t *testing.T) {
model.VerifyingLoadTable,
},
},
{
name: "RS with cleanup enabled",
dest: backendconfig.DestinationT{
DestinationDefinition: backendconfig.DestinationDefinitionT{
Name: warehouseutils.RS,
},
Config: map[string]interface{}{
model.CleanupObjectStorageFilesSetting.String(): true,
},
},
steps: []string{
model.VerifyingObjectStorage,
model.VerifyingObjectStorageDelete,
model.VerifyingConnections,
model.VerifyingCreateSchema,
model.VerifyingCreateAndAlterTable,
model.VerifyingFetchSchema,
model.VerifyingLoadTable,
},
},
}

for _, tc := range testCases {
Expand Down
40 changes: 40 additions & 0 deletions warehouse/validations/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
table string
}

type objectStorageDelete struct {
destination *backendconfig.DestinationT
}

type DestinationValidator interface {
Validate(ctx context.Context, dest *backendconfig.DestinationT) *model.DestinationValidationResponse
}
Expand Down Expand Up @@ -220,6 +224,10 @@
manager: operations,
table: getTable(dest),
}, nil
case model.VerifyingObjectStorageDelete:
return &objectStorageDelete{
destination: dest,
}, nil
}

return nil, fmt.Errorf("invalid step: %s", step)
Expand Down Expand Up @@ -322,6 +330,24 @@
return nil
}

func (osd *objectStorageDelete) Validate(ctx context.Context) error {
var (
tempPath string
err error
uploadObject filemanager.UploadedFile
)
if tempPath, err = CreateTempLoadFile(osd.destination); err != nil {
return fmt.Errorf("creating temp load file: %w", err)
}

Check warning on line 341 in warehouse/validations/validate.go

View check run for this annotation

Codecov / codecov/patch

warehouse/validations/validate.go#L340-L341

Added lines #L340 - L341 were not covered by tests
if uploadObject, err = uploadFile(ctx, osd.destination, tempPath); err != nil {
return fmt.Errorf("upload file: %w", err)
}

Check warning on line 344 in warehouse/validations/validate.go

View check run for this annotation

Codecov / codecov/patch

warehouse/validations/validate.go#L343-L344

Added lines #L343 - L344 were not covered by tests
if err = deleteFile(ctx, osd.destination, uploadObject.ObjectName); err != nil {
return fmt.Errorf("delete file: %w", err)
}

Check warning on line 347 in warehouse/validations/validate.go

View check run for this annotation

Codecov / codecov/patch

warehouse/validations/validate.go#L346-L347

Added lines #L346 - L347 were not covered by tests
return nil
}

// CreateTempLoadFile creates a temporary load file
func CreateTempLoadFile(dest *backendconfig.DestinationT) (string, error) {
var (
Expand Down Expand Up @@ -402,6 +428,20 @@
return output, nil
}

func deleteFile(ctx context.Context, dest *backendconfig.DestinationT, location string) error {
var (
err error
fm filemanager.FileManager
)
if fm, err = createFileManager(dest); err != nil {
return fmt.Errorf("create file manager: %w", err)
}

Check warning on line 438 in warehouse/validations/validate.go

View check run for this annotation

Codecov / codecov/patch

warehouse/validations/validate.go#L437-L438

Added lines #L437 - L438 were not covered by tests
if err = fm.Delete(ctx, []string{location}); err != nil {
return fmt.Errorf("delete file: %w", err)
}

Check warning on line 441 in warehouse/validations/validate.go

View check run for this annotation

Codecov / codecov/patch

warehouse/validations/validate.go#L440-L441

Added lines #L440 - L441 were not covered by tests
return nil
}

func downloadFile(ctx context.Context, dest *backendconfig.DestinationT, location string) error {
var (
err error
Expand Down
17 changes: 17 additions & 0 deletions warehouse/validations/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ func TestValidator(t *testing.T) {
})
})

t.Run("Object Storage Delete", func(t *testing.T) {
v, err := validations.NewValidator(ctx, model.VerifyingObjectStorageDelete, &backendconfig.DestinationT{
DestinationDefinition: backendconfig.DestinationDefinitionT{
Name: warehouseutils.POSTGRES,
},
Config: map[string]interface{}{
"bucketProvider": provider,
"bucketName": bucket,
"accessKeyID": minioResource.AccessKeyID,
"secretAccessKey": minioResource.AccessKeySecret,
"endPoint": minioResource.Endpoint,
},
})
require.NoError(t, err)
require.NoError(t, v.Validate(ctx))
})

t.Run("Connections", func(t *testing.T) {
testCases := []struct {
name string
Expand Down
Loading