-
Notifications
You must be signed in to change notification settings - Fork 180
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(server): multi region blob support #3653
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3642c58
works?
fabis94 5753fd3
lint fixes
fabis94 60b84bb
fixx
fabis94 3a3101a
fixx2
fabis94 57af145
more consistent addresses
fabis94 6074231
fix for s3Region
fabis94 0f77296
Merge branch 'main' into fabians/web-2296-multi-region-blobs
iainsproat 4df6795
fix(schema): multiRegionConfigV1Schema should refer to regionConfigSc…
iainsproat a06bc1c
Need to coerce the string 'true' to boolean true in zod schema
iainsproat b3ae082
Parsing a string from env var to boolean is messed up in zod
iainsproat 998f89b
Revert changes to createBucketIfNotExists schema
iainsproat 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 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 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 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 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 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 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 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 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
59 changes: 59 additions & 0 deletions
59
packages/server/modules/blobstorage/clients/objectStorage.ts
This file contains 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,59 @@ | ||
import { | ||
getS3AccessKey, | ||
getS3BucketName, | ||
getS3Endpoint, | ||
getS3Region, | ||
getS3SecretKey | ||
} from '@/modules/shared/helpers/envHelper' | ||
import { S3Client, S3ClientConfig } from '@aws-sdk/client-s3' | ||
import { Optional } from '@speckle/shared' | ||
|
||
export type ObjectStorage = { | ||
client: S3Client | ||
bucket: string | ||
} | ||
|
||
export type GetObjectStorageParams = { | ||
credentials: S3ClientConfig['credentials'] | ||
endpoint: S3ClientConfig['endpoint'] | ||
region: S3ClientConfig['region'] | ||
bucket: string | ||
} | ||
|
||
/** | ||
* Get object storage client | ||
*/ | ||
export const getObjectStorage = (params: GetObjectStorageParams): ObjectStorage => { | ||
const { bucket, credentials, endpoint, region } = params | ||
|
||
const config: S3ClientConfig = { | ||
credentials, | ||
endpoint, | ||
region, | ||
forcePathStyle: true | ||
} | ||
const client = new S3Client(config) | ||
return { client, bucket } | ||
} | ||
|
||
let mainObjectStorage: Optional<ObjectStorage> = undefined | ||
|
||
/** | ||
* Get main object storage client | ||
*/ | ||
export const getMainObjectStorage = (): ObjectStorage => { | ||
if (mainObjectStorage) return mainObjectStorage | ||
|
||
const mainParams: GetObjectStorageParams = { | ||
credentials: { | ||
accessKeyId: getS3AccessKey(), | ||
secretAccessKey: getS3SecretKey() | ||
}, | ||
endpoint: getS3Endpoint(), | ||
region: getS3Region(), | ||
bucket: getS3BucketName() | ||
} | ||
|
||
mainObjectStorage = getObjectStorage(mainParams) | ||
return mainObjectStorage | ||
} |
This file contains 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
23 changes: 23 additions & 0 deletions
23
packages/server/modules/blobstorage/domain/storageOperations.ts
This file contains 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,23 @@ | ||
import type stream from 'stream' | ||
import type { Readable } from 'stream' | ||
|
||
export type GetObjectStream = (params: { | ||
objectKey: string | ||
}) => Promise<stream.Readable> | ||
|
||
export type GetObjectAttributes = (params: { objectKey: string }) => Promise<{ | ||
fileSize: number | ||
}> | ||
|
||
type FileStream = string | Blob | Readable | Uint8Array | Buffer | ||
|
||
export type StoreFileStream = (args: { | ||
objectKey: string | ||
fileStream: FileStream | ||
}) => Promise<{ fileHash: string }> | ||
|
||
export type DeleteObject = (params: { objectKey: string }) => Promise<void> | ||
|
||
export type EnsureStorageAccess = (params: { | ||
createBucketIfNotExists: boolean | ||
}) => Promise<void> |
This file contains 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 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
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.
We don't seem to be ensuring that we can access all the region storage?
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.
That happens elsewhere (initializeRegisteredRegionClients())
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.
or is this a separate procedure from the one in the module's index.ts? why do we need to even invoke this if this gets validated on module init?
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.
multiregion/index.ts
->initializeRegisteredRegionClients() in multiregion/utils/blobStorageSelector
->initializeRegion
->ensureStorageAccessFactory
. (This tests each additional regions, but ignores the primary region from multi-region config file.)blobstorage/index.ts
->ensureStorageAccessFactory
(This tests the 'main' storage, which is configured via the original environment variables and not from the multi-region config file)We can ignore my comment at the top of this thread. And flipping from the original environment variables to the
primary
block of the multi-region config file can be done separately from this PR to align with the postgres database.