Skip to content
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

Add support for customising AWS SDK client config #3114

Merged
merged 11 commits into from
Jul 13, 2024

Conversation

dhickie
Copy link
Contributor

@dhickie dhickie commented May 23, 2024

This is a proposed solution to resolve #3109. Instead of simply adding an optional ServiceURL parameter when configuring the AWS connection, I opted for an optional Action in which the client can customise any of the config that's common to all AWS service clients. This seemed like a more flexible option rather than needing to add more and more parameters piecemeal as more use cases come up.

@iancooper I'm open to ideas on how best to test this - as the AWS clients are constructed and then disposed during function calls, there's no easy way to inspect them to ensure they've got the correct configuration. One option would be to make use of LocalStack to try pointing AWS clients to a different service URL, but that seems like a fairly substantial departure from the current testing style.

@CLAassistant
Copy link

CLAassistant commented May 23, 2024

CLA assistant check
All committers have signed the CLA.

@iancooper
Copy link
Member

This is a proposed solution to resolve #3109. Instead of simply adding an optional ServiceURL parameter when configuring the AWS connection, I opted for an optional Action in which the client can customise any of the config that's common to all AWS service clients. This seemed like a more flexible option rather than needing to add more and more parameters piecemeal as more use cases come up.

Good idea, we do that for Kafka and it's probably a pattern that we can usefully extend elsewhere to allow interception; it helps to future proof us against properties of brokers that we don't have wrapped yet.

@iancooper
Copy link
Member

iancooper commented May 23, 2024

@iancooper I'm open to ideas on how best to test this - as the AWS clients are constructed and then disposed during function calls, there's no easy way to inspect them to ensure they've got the correct configuration. One option would be to make use of LocalStack to try pointing AWS clients to a different service URL, but that seems like a fairly substantial departure from the current testing style.

If a test depends on infrastructure we tend to put it in its own library. We have a programmer tests approach, so touching infrastructure is fine, but we want fast tests so we tend to try to separate out tests for specific transports (we still have slower core tests due to how we test background processes, which we might want to separate out at some point - but a different issue).

So here it could make sense to have tests that run this against LocalStack. A larger refactoring of how we do this would allow you to configure whether you want to run our AWS tests against cloud infra or LocalStack. That could be useful for folks who like LocalStack, though I would always want CI to be against cloud infra. So I think that for a first step we could just create a separate AWS.LocalStack library and put tests in there that deal with features that explicitly support that model. We would also need to add that into our GA CI script.

We probably need to update the docs as well, but I can talk you through that directly as GitBook's lack of support for multiple versions of the docs has meant we have to solve some problems there with tooling.

Just an opinion, other opinions welcome though

@dhickie
Copy link
Contributor Author

dhickie commented May 23, 2024

Another option just occurred to me - since this change is about supporting general customisation of AWS clients and not necessarily about using LocalStack specifically, another option would be to implement an HttpClientFactory for the test which returns an HttpClient with a custom DelegatingHandler that logs something about the request. The HttpClientFactory can then be passed to the AWS client configuration, so if something gets logged by the delegating handler then we know it used the custom config.

That feels a bit more straightforward than making this about LocalStack in particular.

@iancooper
Copy link
Member

Another option just occurred to me -

That works. Agreed it is not a LocalStack test, but functionality we need for localstack

Copy link
Member

@iancooper iancooper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions, but none of them are significant. So approved, up to you if you want to change based on that feedback

{
_snsClient = new AmazonSimpleNotificationServiceClient(credentials, region);
var config = new AmazonSimpleNotificationServiceConfig
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should follow the pattern elsewhere of encapsulating this in a CreateSnsClient method. I like symmetry but its just an opinion

{
_region = region;

_stsClient = new AmazonSecurityTokenServiceClient(credentials, region);
var config = new AmazonSecurityTokenServiceConfig
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again should we replicate the pattern of making this a method; it's possible if we do that we may be able to extract a helper class that encapsulates this logic. We can just make that a dependency we new up in the constructor, no need to DI it in, but we save on repeated logic amongst these classes.

{
_snsClient = new AmazonSimpleNotificationServiceClient(credentials, region);
var config = new AmazonSimpleNotificationServiceConfig
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above comment on extracting this

@iancooper iancooper added 2 - In Progress feature request v10 Allocal to a v10 release .NET Pull requests that update .net code labels May 24, 2024
@dhickie
Copy link
Contributor Author

dhickie commented May 24, 2024

@iancooper Yep that makes sense, I've pulled out construction of AWS clients to a factory class instead.

I noticed that the AWS tests and some of the Dynamo tests are failing currently for reasons that don't seem related to this PR - is that to be expected?

Copy link
Member

@iancooper iancooper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. Thank you.

@iancooper
Copy link
Member

@iancooper Yep that makes sense, I've pulled out construction of AWS clients to a factory class instead.

I noticed that the AWS tests and some of the Dynamo tests are failing currently for reasons that don't seem related to this PR - is that to be expected?

Hmmm, let me take a look.

@dhickie
Copy link
Contributor Author

dhickie commented May 29, 2024

@iancooper Any luck looking at the failing tests?

@iancooper
Copy link
Member

Not had a chance. Will try to look before the weekend

# Conflicts:
#	src/Paramore.Brighter.MessagingGateway.AWSSQS/SqsMessageProducer.cs
@dhickie
Copy link
Contributor Author

dhickie commented Jul 9, 2024

@iancooper This seems like another occurrence of the transient issue with the command processor tests - is it worth just retrying to check?

@iancooper
Copy link
Member

@iancooper This seems like another occurrence of the transient issue with the command processor tests - is it worth just retrying to check?

Yeah, let me see if I can persuade it to build; still not sure why that issue pops up

@dhickie
Copy link
Contributor Author

dhickie commented Jul 11, 2024

@iancooper This is now up to date with master, but we have a return of our old friend Value cannot be null. (Parameter 'factory')

@iancooper iancooper merged commit 1fe77a0 into BrighterCommand:master Jul 13, 2024
16 of 18 checks passed
@iancooper
Copy link
Member

@dhickie merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Done feature request .NET Pull requests that update .net code v10 Allocal to a v10 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Support setting a service URL when configuring an AWSMessagingGatewayConnection
4 participants