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 Aspire.MySqlConnector #825

Merged
merged 14 commits into from Nov 18, 2023
Merged

Add Aspire.MySqlConnector #825

merged 14 commits into from Nov 18, 2023

Conversation

bgrainger
Copy link
Contributor

Using the component name "Aspire.MySqlConnector" to leave the door open for "Aspire.MySql.Data" (based on the MySql.Data library) in the future.

Fixes #786

Using the component name "Aspire.MySqlConnector" to leave the door open for "Aspire.MySql.Data" (based on the MySql.Data library) in the future.
@bgrainger
Copy link
Contributor Author

As per my comment I'd be very happy for Aspire to be "opinionated" about MySQL libraries, and just call this component "Aspire.MySql" instead of "Aspire.MySqlConnector". (MySql.Data doesn't implement DbDataSource and it's not clear if/when that library will implement any new ADO.NET features.)

@mitchdenny
Copy link
Member

This is awesome. We should also think about what the AppHost side of things might look like in this PR. For example:

var builder = DistributedApplication.CreateBuilder(args);
var mysql = builder.AddMySql("mysql");

var backend = builder.AddProject<Projects.Backend>("backend")
   .WithReference(mysql);

You can checkout code in src/Aspire.Hosting/Postgres as an example. The AppHost doesn't really need to choose between one MySQL provider or another - at this layer its just about getting the inner loop up and running by spinning up a container locally for the dev.

@DamianEdwards
Copy link
Member

New packages will need to be mirrored before PR checks can pass I think?

@eerhardt
Copy link
Member

New packages will need to be mirrored before PR checks can pass I think?

I'll take care of the mirroring in the morning.

@bgrainger - can you also add tests? See

for examples.

<IsPackable>true</IsPackable>
<PackageTags>$(ComponentDatabasePackageTags) mysqlconnector mysql sql</PackageTags>
<Description>A MySQL client that integrates with Aspire, including health checks, metrics, logging, and telemetry.</Description>
<PackageIconFullPath>$(SharedDir)SQL_256x.png</PackageIconFullPath>
Copy link
Member

Choose a reason for hiding this comment

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

@DamianEdwards - should this have the same icon as the https://www.nuget.org/packages/MySqlConnector/ package?

image

Copy link
Member

Choose a reason for hiding this comment

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

That would be ideal, assuming we have permission to do so 😀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created the MySqlConnector package icon (using free sources) and will give any necessary permission to include it here.


internal static class MySqlConnectorCommon
{
public static void AddMySqlMetrics(MeterProviderBuilder meterProviderBuilder)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure we need this given we only have 1 component. Is there an EntityFramework "MySqlConnector" library?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The EF Core library built on top of MySqlConnector is https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm happy to add support for that too, but will probably do it as a separate PR.

@danmoseley
Copy link
Member

danmoseley commented Nov 15, 2023

FYI @ajcvickers @roji for awareness of more data related Aspire packages...

@mitchdenny
Copy link
Member

@bgrainger I've just had a look through the AppModel side of the PR and everything looks in order (great work!).

@roji
Copy link
Member

roji commented Nov 15, 2023

Great to see this @bgrainger!

After this we can also add the Pomelo EF provider for MySQL (/cc @lauxjpn).

Using the component name "Aspire.MySqlConnector" to leave the door open for "Aspire.MySql.Data" (based on the MySql.Data library) in the future.

On this... Unlike the situation with SQL Server and PostgreSQL, where there really is basically only one (main) driver (SqlClient and Npgsql respectively), with MySql there really are two - the community MySqlConnector being wrapped here (with the Pomelo EF connector built on top of it) and the "official" providers from Oracle. I'm definitely a big supporter of the former pair - and also of the idea of being opinionated in Aspire - but I think we should continue to include the driver name here (i.e. Aspire.MySqlConnector rather than Aspire.MySql).

Note that even for Npgsql we have Aspire.Npgsql (rather than Aspire.PostgreSQL).

@bgrainger
Copy link
Contributor Author

I'm planning to come back and add Pomelo EF support, but will probably do that as a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

@DamianEdwards do we need perms to include this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll revert this, to avoid any possible problems over asset permissions.

Copy link
Member

Choose a reason for hiding this comment

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

From my reading, we'd need written permission to use the logo. I can work offline to enquire about that.

@joperezr
Copy link
Member

Added MySqlConnector.DependencyInjection and AspNetCore.HealthChecks.MySql to dotnet-public feed. I'll re-run CI now.

@joperezr
Copy link
Member

/azp run dotnet.aspire

Copy link

Pull request contains merge conflicts.

Conflicts:
	Directory.Packages.props
@danmoseley
Copy link
Member

It'd be great to have a MySql sample (in https://github.com/dotnet/aspire-samples) once this is in, if you're interested in that followup.

@danmoseley
Copy link
Member

Maybe we should leave the logo out for now, so we're not waiting on Damian to talk to Oracle.

Copy link
Member

@eerhardt eerhardt 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 looking really great! Thank you for your contribution, @bgrainger. (and on the first day we made the repo public 😄.

I just have a few comments.

Regarding the name of the component. What you have in your current code is correct. See the policy at:

## Naming
- Each component's name should contain just an `Aspire.` prefix.
- When component is built around `ABC` client library, it should contain the client library name in its name. Example: `Aspire.ABC`.

Since this component is built around MySqlConnector, the correct name for it is Aspire.MySqlConnector.

src/Aspire.Hosting/MySql/MySqlContainerResource.cs Outdated Show resolved Hide resolved
<TargetFramework>$(NetCurrent)</TargetFramework>
<IsPackable>true</IsPackable>
<PackageTags>$(ComponentDatabasePackageTags) mysqlconnector mysql sql</PackageTags>
<Description>A MySQL client that integrates with Aspire, including health checks, metrics, logging, and telemetry.</Description>
Copy link
Member

Choose a reason for hiding this comment

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

Does MySQL need a ® sign after it, like we do for PostgreSQL?

src/Components/Telemetry.md Show resolved Hide resolved
Comment on lines +79 to +81
ConnectionString = serviceKey is null
? sp.GetRequiredService<MySqlDataSource>().ConnectionString
: sp.GetRequiredKeyedService<MySqlDataSource>(serviceKey).ConnectionString
Copy link
Member

Choose a reason for hiding this comment

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

How do you feel about opening a PR to https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks to make this consistent with Npgsql? We shouldn't be creating another DbDataSource and checking the health of that. Instead, we should be using the same DbDataSource instance as the app is using. That way if that DbDataSource ever gets corrupt, the health check is accurate. From the Components README:

- Consider whether the Health Check should reuse the same client object registered in DI by the component or not. Reusing the same client object has the advantages of getting the same configuration, logging, etc during the health check.

See also Xabaril/AspNetCore.Diagnostics.HealthChecks#1832

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good; I have another reason to open a PR there, too: Xabaril/AspNetCore.Diagnostics.HealthChecks#2031.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

src/Components/Telemetry.md Show resolved Hide resolved
tests/Aspire.MySqlConnector.Tests/ConformanceTests.cs Outdated Show resolved Hide resolved
@danmoseley danmoseley added the area-components Issues pertaining to Aspire Component packages label Nov 16, 2023
@bgrainger bgrainger marked this pull request as draft November 16, 2023 18:50
This allows us to use the built-in support for keyed services.
}
else
{
throw new DistributedApplicationException("Parent resource connection string was null.");
Copy link
Member

Choose a reason for hiding this comment

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

@eerhardt should we start moving these things to a resx? I assume we won't localize unless the base libraries start to localize. So perhaps there isn't much value.

Copy link
Member

Choose a reason for hiding this comment

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

ASP.NET Core doesn't have a lot of its exception messages in resx's either. For example

https://github.com/dotnet/aspnetcore/blob/f8f03ea3764826d009f7ceb9bb91e482ce4a3fa9/src/Shared/Json/JsonSerializerExtensions.cs#L26

If we ever needed to localize our exceptions, it wouldn't be that hard to find these. But odds are, after 8 years of .NET Core System.* libraries not being localized, I'd be surprised if it ever happens.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed.

@bgrainger
Copy link
Contributor Author

Needs dotnet-public to be updated with v2.3.1 of MySqlConnector and MySqlConnector.DependencyInjection packages.

@danmoseley
Copy link
Member

Needs dotnet-public to be updated with v2.3.1 of MySqlConnector and MySqlConnector.DependencyInjection packages.

I kicked that, should be about 10 minutes.

@danmoseley danmoseley closed this Nov 17, 2023
@danmoseley danmoseley reopened this Nov 17, 2023
@danmoseley
Copy link
Member

the package was mirrored and the build succeeds.

Conflicts:
	Directory.Packages.props
@eerhardt
Copy link
Member

@bgrainger - any reason this is in "Draft"? I didn't see a reason it was marked draft.

@bgrainger
Copy link
Contributor Author

Put it in draft while I waited to update to MySqlConnector 2.3.1; ready for review now.

@bgrainger bgrainger marked this pull request as ready for review November 17, 2023 18:07
Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

This looks great. Thanks again, @bgrainger! The unresolved comments can be addressed in follow up PRs. I think this is ready to be merged.

I'll wait until EOD before mering this, to allow for any additional feedback from other reviewers.

@eerhardt eerhardt merged commit e097223 into dotnet:main Nov 18, 2023
3 checks passed
@davidfowl
Copy link
Member

Amazing 🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-components Issues pertaining to Aspire Component packages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add MySQL Aspire Component
8 participants