-
Notifications
You must be signed in to change notification settings - Fork 155
chore(parameters): apply UA to AWS SDK clients used by Parameters #1577
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
chore(parameters): apply UA to AWS SDK clients used by Parameters #1577
Conversation
Thanks for the PR, looking also at #1575, what happens if as a customer I do this: import { Tracer } from '@aws-lambda-powertools/tracer';
import { SecretsProvider } from '@aws-lambda-powertools/parameters/secrets';
import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
const tracer = new Tracer({});
const customClient = new SecretsManagerClient({});
tracer.captureAWSv3Client(customClient);
const provider = new SecretsProvider({ awsSdkV3Client: customClient }); This is an use case that we suggest/call out in the docs (see callout box). Does this attach the middleware twice? If so, does this result in the UA being appended twice? Same applies to Idempotency and all other providers. |
Good catch with duplicate attachment.
It fails to add two middlewares with identical name, we catch the error and continue with user code execution. We could extend the header for each utility, similar how .NET does. For example |
It's good that we don't halt execution, but we still log a warning that could be misleading. I'm going to open an issue to remember working on this asap. |
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.
I have left a comment on the testing to improve the assertion on the newly added middleware.
Also I have opened an issue #1578 to continue the discussion above about multiple addUserAgentMiddleware
calls.
@@ -43,6 +49,8 @@ describe('Class: AppConfigProvider', () => { | |||
serviceId: 'AppConfigData', | |||
}) | |||
); | |||
|
|||
expect(userAgentSpy).toHaveBeenCalled(); |
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 client
inside the provider is public and can be accessed via provider.client
. This means you should be able to test like you did in the commons
module by doing:
expect(provider.client.middlewareStack.identify()).toContain(
'addPowertoolsToUserAgent: POWERTOOLS,USER_AGENT'
);
I think that would be preferable to changing the import (* as ..
) and selecting the module in the spy.
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.
I think that would be preferable to changing the import (* as ..) and selecting the module in the spy.
Can you elaborate? Curious to hear about the benefits.
I want to avoid to test the internals of the commons
module and the dependencies behaviour. Imho, we should only check the call has happened downstream, otherwise we replicate the assertion logic in different places which makes it harder to change in the future. For instance, if we rename the middleware from addPowertoolsUserAgent
to something else, we'd need to revisit every utility that called this method.
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.
Based on the way that the Jest spy is written, if we rename addPowertoolsUserAgent
to something else the test would also break:
const userAgentSpy = jest.spyOn(
UserAgentMiddleware,
'addUserAgentMiddleware' // if function name changes, this spy also breaks
);
However I see your point and agree. I tend to avoid setting spies on imports but I can't think of a better way of doing it without reworking the constructor (which si not worth it), so let's leave it this way!
In case of #1578 we agreed to attach only one user agent middleware for a client. If the client is used in multiple utilities, we check if a middleware is present and skip the second call, first come first serve. We will revisit the strategy at later points to align with other languages. |
Description of your changes
Add user agent to clients user by parameters utility.
Related issues, RFCs
Issue number: closes #1537
Checklist
Breaking change checklist
Is it a breaking change?: NO
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.