-
Notifications
You must be signed in to change notification settings - Fork 20
Share S3 client between CRR tasks #2642
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
base: development/9.1
Are you sure you want to change the base?
Conversation
Hello kerkesni,My role is to assist you with the merge of this Available options
Available commands
Status report is not available. |
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files
... and 3 files with indirect coverage changes
@@ Coverage Diff @@
## development/9.1 #2642 +/- ##
===================================================
+ Coverage 73.63% 73.83% +0.19%
===================================================
Files 201 202 +1
Lines 13439 13516 +77
===================================================
+ Hits 9896 9979 +83
+ Misses 3533 3527 -6
Partials 10 10
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
f02a2ff
to
602390c
Compare
602390c
to
3e1ccf1
Compare
@@ -358,6 +362,14 @@ class QueueProcessor extends EventEmitter { | |||
} | |||
} | |||
|
|||
_setupClientsManager() { | |||
if (this.destConfig.auth.type !== libConstants.authTypeAssumeRole) { |
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.
Maybe a comment here explaining why it is limited to assume role type would be great
const DELETE_INACTIVE_CREDENTIALS_INTERVAL = 1000 * 60 * 30; // 30m | ||
const MAX_INACTIVE_DURATION = 1000 * 60 * 60 * 2; // 2hr |
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.
If these are role sessions, they will likely expire before this timeout? Shall we link each set of creds with their expiration date (updated each time we refresh them)?
const roleName = _extractRoleNameFromRole(targetRole); | ||
this.clientManager = new ClientManager({ | ||
id: accountId, | ||
_setupAssumeRoleDestClient(targetRole) { |
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.
Due to how errors are reported as null in case of issue, should we at least add some logs?
} | ||
|
||
_setupDestClients(targetRole, log) { | ||
this.destBackbeatHost = this.destHosts.pickHost(); |
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.
is destBackbeatHost
really a class attribute: should it not be just a parameter of _setupAssumeRoleDestClient
?
if (this.destConfig.auth.type === authTypeAssumeRole) { | ||
this._setupAssumeRoleDestClient(targetRole); |
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.
since we have an asbtraction (clientManager), can't we just rely on it to create the client in any case?
i.e. maybe introduce an abstract class "ClientFactory", with 2 implementations...
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.
note that it may be worth having 3 implementations:
- CredentialsManager-based "AssumeRole" implementation
- the simpler _createCredentials based implementation used in the 'else' branch of thsi functioj
CachedClientFactory
adapter, which could be used on top of either implementation (as needed)
const client = this.s3Clients[clientId]; | ||
|
||
if (client) { | ||
return client; |
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.
when we go through here, the credentials (credentials = this.credentialsManager.getCredentials
) are not used --> useless to do it
const client = this.backbeatClients[clientId]; | ||
|
||
if (client) { | ||
return client; |
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.
same, credentials not used in that case
const config = this._configs[clientId]; | ||
if (!config) { | ||
return null; | ||
} | ||
|
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.
useless, this would mean client is null
* @param {String} clientId - The client id. | ||
* @return {AWS.S3} The S3 client instance to make requests with | ||
*/ | ||
getS3Client(clientId) { |
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.
the structure of getS3Client and getBackbeatClient is very redundant : probably should be refactored with a _getClient
function, maybe something like
_getClient(clients /* map */, clientId /* string */, createClient /* func */) {
const client = clients[clientId];
if (client) {
return client;
}
const config = this._configs[clientId];
if (!config) {
return null;
}
const credentials = this.credentialsManager.getCredentials({
id: clientId,
accountId: config.accountId,
stsConfig: config.stsConfig,
authConfig: config.authConfig,
});
if (credentials === null) {
return null;
}
const client = createClient(config, credentials);
this.s3Clients[clientId] = client;
return client;
}
Share the same S3 clients (and their credentials) between multiple CRR tasks of the same site.
The
ClientsManager
class is an improved version ofClientManager
that allows handling multiple clients with different auth configs. For now we still keep theClientManager
class to limit the scope of this PR, but code that uses it should be updated to use the newer class. This will be done in another PR.Issue: BB-663