-
Notifications
You must be signed in to change notification settings - Fork 230
feat(pqlmanifest): implement S3 polling support for PQL manifest #2726
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 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5d0a372
feat(pqlmanifest): implement StorageFetcher for manifest retrieval an…
StarpTech 54e0f0b
Merge branch 'main' into dustin/support-s3-poling-for-pql-manifest
StarpTech c1bd70a
Merge branch 'main' into dustin/support-s3-poling-for-pql-manifest
StarpTech 590de81
feat(pqlmanifest): enhance S3 manifest fetching with conditional requ…
StarpTech 062c098
Merge branch 'main' into dustin/support-s3-poling-for-pql-manifest
StarpTech bd0c422
feat(pqlmanifest): add configurable manifest file name for S3 polling
StarpTech 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
Some comments aren't visible on the classic Files Changed page.
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
46 changes: 46 additions & 0 deletions
46
router/internal/persistedoperation/pqlmanifest/storage_fetcher.go
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,46 @@ | ||
| package pqlmanifest | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| // StorageFetcher adapts a ReadManifest-style function (e.g. from an S3 or CDN | ||
| // storage client) to the ManifestFetcher interface used by the Poller. | ||
| // Unlike the CDN Fetcher which uses HTTP ETags for conditional requests, | ||
| // StorageFetcher always downloads the manifest and compares the revision field | ||
| // to determine whether it changed. | ||
| type StorageFetcher struct { | ||
| readManifest func(ctx context.Context, objectPath string) (*Manifest, error) | ||
| objectPath string | ||
| logger *zap.Logger | ||
| } | ||
|
|
||
| func NewStorageFetcher( | ||
| readManifest func(ctx context.Context, objectPath string) (*Manifest, error), | ||
| objectPath string, | ||
| logger *zap.Logger, | ||
| ) *StorageFetcher { | ||
| if logger == nil { | ||
| logger = zap.NewNop() | ||
| } | ||
| return &StorageFetcher{ | ||
| readManifest: readManifest, | ||
| objectPath: objectPath, | ||
| logger: logger.With(zap.String("component", "pql_storage_fetcher")), | ||
| } | ||
| } | ||
|
|
||
| func (f *StorageFetcher) Fetch(ctx context.Context, currentRevision string) (*Manifest, bool, error) { | ||
| manifest, err := f.readManifest(ctx, f.objectPath) | ||
| if err != nil { | ||
| return nil, false, err | ||
| } | ||
|
|
||
| if manifest.Revision == currentRevision { | ||
| return nil, false, nil | ||
| } | ||
|
|
||
| return manifest, true, nil | ||
| } |
119 changes: 119 additions & 0 deletions
119
router/internal/persistedoperation/pqlmanifest/storage_fetcher_test.go
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,119 @@ | ||
| package pqlmanifest | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| func TestStorageFetcher(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| t.Run("first fetch with empty revision returns manifest", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| manifest := &Manifest{ | ||
| Version: 1, | ||
| Revision: "rev-1", | ||
| Operations: map[string]string{"h1": "query { a }"}, | ||
| } | ||
| fetcher := NewStorageFetcher( | ||
| func(_ context.Context, _ string) (*Manifest, error) { | ||
| return manifest, nil | ||
| }, | ||
| "ops/manifest.json", | ||
| zap.NewNop(), | ||
| ) | ||
|
|
||
| result, changed, err := fetcher.Fetch(context.Background(), "") | ||
| require.NoError(t, err) | ||
| require.True(t, changed) | ||
| require.Equal(t, manifest, result) | ||
| }) | ||
|
|
||
| t.Run("same revision returns no change", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| fetcher := NewStorageFetcher( | ||
| func(_ context.Context, _ string) (*Manifest, error) { | ||
| return &Manifest{ | ||
| Version: 1, | ||
| Revision: "rev-1", | ||
| Operations: map[string]string{"h1": "query { a }"}, | ||
| }, nil | ||
| }, | ||
| "ops/manifest.json", | ||
| zap.NewNop(), | ||
| ) | ||
|
|
||
| result, changed, err := fetcher.Fetch(context.Background(), "rev-1") | ||
| require.NoError(t, err) | ||
| require.False(t, changed) | ||
| require.Nil(t, result) | ||
| }) | ||
|
|
||
| t.Run("different revision returns updated manifest", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| manifest := &Manifest{ | ||
| Version: 1, | ||
| Revision: "rev-2", | ||
| Operations: map[string]string{"h1": "query { a }", "h2": "query { b }"}, | ||
| } | ||
| fetcher := NewStorageFetcher( | ||
| func(_ context.Context, _ string) (*Manifest, error) { | ||
| return manifest, nil | ||
| }, | ||
| "ops/manifest.json", | ||
| zap.NewNop(), | ||
| ) | ||
|
|
||
| result, changed, err := fetcher.Fetch(context.Background(), "rev-1") | ||
| require.NoError(t, err) | ||
| require.True(t, changed) | ||
| require.Equal(t, manifest, result) | ||
| }) | ||
|
|
||
| t.Run("read error is propagated", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| fetcher := NewStorageFetcher( | ||
| func(_ context.Context, _ string) (*Manifest, error) { | ||
| return nil, fmt.Errorf("s3 connection refused") | ||
| }, | ||
| "ops/manifest.json", | ||
| zap.NewNop(), | ||
| ) | ||
|
|
||
| result, changed, err := fetcher.Fetch(context.Background(), "rev-1") | ||
| require.Error(t, err) | ||
| require.Contains(t, err.Error(), "s3 connection refused") | ||
| require.False(t, changed) | ||
| require.Nil(t, result) | ||
| }) | ||
|
|
||
| t.Run("passes correct object path", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| var receivedPath string | ||
| fetcher := NewStorageFetcher( | ||
| func(_ context.Context, objectPath string) (*Manifest, error) { | ||
| receivedPath = objectPath | ||
| return &Manifest{ | ||
| Version: 1, | ||
| Revision: "rev-1", | ||
| Operations: map[string]string{}, | ||
| }, nil | ||
| }, | ||
| "my-prefix/operations/manifest.json", | ||
| zap.NewNop(), | ||
| ) | ||
|
|
||
| _, _, err := fetcher.Fetch(context.Background(), "") | ||
| require.NoError(t, err) | ||
| require.Equal(t, "my-prefix/operations/manifest.json", receivedPath) | ||
| }) | ||
| } |
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.