-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: Reopen for integration test about add s3 storage-based registry store in Go feature server #5352
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
franciscojavierarceo
merged 7 commits into
feast-dev:master
from
iamcodingcat:dev/go/feature-server/registry/s3
May 15, 2025
Merged
fix: Reopen for integration test about add s3 storage-based registry store in Go feature server #5352
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
69c80fc
fix: upgrade protobuf version, make `protos` directory beforehand
younghun-jo-levit-com 466cdd0
feat: add aws s3 storage based registry store
younghun-jo-levit-com 5734012
chore: add aws s3 api related pkgs
younghun-jo-levit-com 70bd018
style: remove my custom comment
younghun-jo-levit-com 6a8f614
refact: separate s3 registry file from `local.go`
younghun-jo-levit-com dc576af
feat: add if-statement in Makefile on linux arm64 os-platform
iamcodingcat 4862622
feat: add test-code for s3 registry store
iamcodingcat 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
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
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,94 @@ | ||
| package registry | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "io/ioutil" | ||
| "net/url" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/aws/aws-sdk-go-v2/service/s3" | ||
| ) | ||
|
|
||
| func TestGetOnlineFeaturesS3Registry(t *testing.T) { | ||
| mockS3Client := &MockS3Client{ | ||
| GetObjectFn: func(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error) { | ||
| return &s3.GetObjectOutput{ | ||
| Body: ioutil.NopCloser(strings.NewReader("mock data")), | ||
| }, nil | ||
| }, | ||
| DeleteObjectFn: func(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error) { | ||
| return &s3.DeleteObjectOutput{}, nil | ||
| }, | ||
| } | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| config *RepoConfig | ||
| }{ | ||
| { | ||
| name: "redis with simple features", | ||
| config: &RepoConfig{ | ||
| Project: "feature_repo", | ||
| Registry: map[string]interface{}{ | ||
| "path": "s3://test-bucket/path/to/registry.db", | ||
| }, | ||
| Provider: "aws", | ||
| }, | ||
| }, | ||
| } | ||
| for _, test := range tests { | ||
| registryConfig, err := test.config.GetRegistryConfig() | ||
| if err != nil { | ||
| t.Errorf("Error getting registry config. msg: %s", err.Error()) | ||
| } | ||
| r := &Registry{ | ||
| project: test.config.Project, | ||
| cachedRegistryProtoTtl: time.Duration(registryConfig.CacheTtlSeconds) * time.Second, | ||
| } | ||
| _ = registryConfig.RegistryStoreType | ||
| registryPath := registryConfig.Path | ||
| uri, err := url.Parse(registryPath) | ||
| if err != nil { | ||
| t.Errorf("Error parsing registry path. msg: %s", err.Error()) | ||
| } | ||
| if registryStoreType, ok := REGISTRY_STORE_CLASS_FOR_SCHEME[uri.Scheme]; ok { | ||
| switch registryStoreType { | ||
| case "S3RegistryStore": | ||
| registryStore := &S3RegistryStore{ | ||
| filePath: registryConfig.Path, | ||
| s3Client: mockS3Client, | ||
| } | ||
| r.registryStore = registryStore | ||
| err := r.InitializeRegistry() | ||
| if err != nil { | ||
| t.Errorf("Error initializing registry. msg: %s. registry path=%q", err.Error(), registryPath) | ||
| } | ||
| default: | ||
| t.Errorf("Only S3RegistryStore is supported on this testing. got=%s", registryStoreType) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // MockS3Client is mock client for testing s3 registry store | ||
| type MockS3Client struct { | ||
| GetObjectFn func(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error) | ||
| DeleteObjectFn func(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error) | ||
| } | ||
|
|
||
| func (m *MockS3Client) GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error) { | ||
| if m.GetObjectFn != nil { | ||
| return m.GetObjectFn(ctx, params) | ||
| } | ||
| return nil, errors.New("not implemented") | ||
| } | ||
|
|
||
| func (m *MockS3Client) DeleteObject(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error) { | ||
| if m.DeleteObjectFn != nil { | ||
| return m.DeleteObjectFn(ctx, params) | ||
| } | ||
| return nil, errors.New("not implemented") | ||
| } |
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,109 @@ | ||
| package registry | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "io/ioutil" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/aws/aws-sdk-go-v2/aws" | ||
| awsConfig "github.com/aws/aws-sdk-go-v2/config" | ||
| "github.com/aws/aws-sdk-go-v2/service/s3" | ||
| "github.com/feast-dev/feast/go/protos/feast/core" | ||
|
|
||
| "google.golang.org/protobuf/proto" | ||
| ) | ||
|
|
||
| // S3ClientInterface define interface of s3.Client for making mocking s3 client and testing it | ||
| type S3ClientInterface interface { | ||
| GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error) | ||
| DeleteObject(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error) | ||
| } | ||
|
|
||
| // A S3RegistryStore is a S3 object storage-based implementation of the RegistryStore interface | ||
| type S3RegistryStore struct { | ||
| filePath string | ||
| s3Client S3ClientInterface | ||
| } | ||
|
|
||
| // NewS3RegistryStore creates a S3RegistryStore with the given configuration | ||
| func NewS3RegistryStore(config *RegistryConfig, repoPath string) *S3RegistryStore { | ||
| var lr S3RegistryStore | ||
| ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
| defer cancel() | ||
|
|
||
| cfg, err := awsConfig.LoadDefaultConfig(ctx) | ||
| if err != nil { | ||
| lr = S3RegistryStore{ | ||
| filePath: config.Path, | ||
| } | ||
| } else { | ||
| lr = S3RegistryStore{ | ||
| filePath: config.Path, | ||
| s3Client: s3.NewFromConfig(cfg), | ||
| } | ||
| } | ||
| return &lr | ||
| } | ||
|
|
||
| func (r *S3RegistryStore) GetRegistryProto() (*core.Registry, error) { | ||
| bucket, key, err := r.parseS3Path() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
| defer cancel() | ||
| output, err := r.s3Client.GetObject(ctx, | ||
| &s3.GetObjectInput{ | ||
| Bucket: aws.String(bucket), | ||
| Key: aws.String(key), | ||
| }) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| defer output.Body.Close() | ||
|
|
||
| data, err := ioutil.ReadAll(output.Body) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| registry := &core.Registry{} | ||
| if err := proto.Unmarshal(data, registry); err != nil { | ||
| return nil, err | ||
| } | ||
| return registry, nil | ||
| } | ||
|
|
||
| func (r *S3RegistryStore) UpdateRegistryProto(rp *core.Registry) error { | ||
| return errors.New("not implemented in S3RegistryStore") | ||
| } | ||
|
|
||
| func (r *S3RegistryStore) Teardown() error { | ||
| bucket, key, err := r.parseS3Path() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
| defer cancel() | ||
| _, err = r.s3Client.DeleteObject(ctx, | ||
| &s3.DeleteObjectInput{ | ||
| Bucket: aws.String(bucket), | ||
| Key: aws.String(key), | ||
| }) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (r *S3RegistryStore) parseS3Path() (string, string, error) { | ||
| path := strings.TrimPrefix(r.filePath, "s3://") | ||
| parts := strings.SplitN(path, "/", 2) | ||
| if len(parts) != 2 { | ||
| return "", "", errors.New("invalid S3 file path format") | ||
| } | ||
| return parts[0], parts[1], nil | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.