Skip to content

Add Aspire.MySqlConnector - #825

Merged
Eric Erhardt (eerhardt) merged 14 commits into
microsoft:mainfrom
mysql-net:mysql
Nov 18, 2023
Merged

Eric Erhardt (eerhardt) merged 14 commits into
microsoft:mainfrom
mysql-net:mysql

Conversation

@bgrainger

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

@eerhardt

Copy link
Copy Markdown
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.

Bradley Grainger (@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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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

Dan Moseley (danmoseley) commented Nov 15, 2023 •

Copy link
Copy Markdown
Contributor

FYI Arthur Vickers (@ajcvickers) Shay Rojansky (@roji) for awareness of more data related Aspire packages...

@mitchdenny

Copy link
Copy Markdown
Member

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

@roji

Copy link
Copy Markdown
Member

Great to see this Bradley Grainger (@bgrainger)!

After this we can also add the Pomelo EF provider for MySQL (/cc Laurents Meyer (@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
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Damian Edwards (@DamianEdwards) do we need perms to include this

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

@joperezr

Copy link
Copy Markdown
Member

/azp run dotnet.aspire

@azure-pipelines

Copy link
Copy Markdown
Pull request contains merge conflicts.

Conflicts:
	Directory.Packages.props
@danmoseley

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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

@eerhardt Eric Erhardt (eerhardt) left a comment

Copy link
Copy Markdown
Member

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, Bradley Grainger (@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:

https://github.com/dotnet/aspire/blob/ab931f067195a7af0468c18974b864c51a2963cd/src/Components/README.md?plain=1#L5-L8

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

<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
Copy Markdown
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?

Comment thread src/Components/Telemetry.md Resolved
Comment on lines +79 to +81
ConnectionString = serviceKey is null
? sp.GetRequiredService<MySqlDataSource>().ConnectionString
: sp.GetRequiredKeyedService<MySqlDataSource>(serviceKey).ConnectionString

Copy link
Copy Markdown
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:

https://github.com/dotnet/aspire/blob/ab931f067195a7af0468c18974b864c51a2963cd/src/Components/README.md?plain=1#L68

See also Xabaril/AspNetCore.Diagnostics.HealthChecks#1832

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread src/Components/Telemetry.md Resolved
@danmoseley Dan Moseley (danmoseley) added the area-integrations Issues pertaining to Aspire Integrations packages label Nov 16, 2023
@bgrainger
Bradley Grainger (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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Eric Erhardt (@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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed.

@bgrainger

Copy link
Copy Markdown
Contributor Author

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

@danmoseley

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

the package was mirrored and the build succeeds.

Conflicts:
	Directory.Packages.props
@eerhardt

Copy link
Copy Markdown
Member

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

@bgrainger

Copy link
Copy Markdown
Contributor Author

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

@bgrainger
Bradley Grainger (bgrainger) marked this pull request as ready for review November 17, 2023 18:07

@eerhardt Eric Erhardt (eerhardt) left a comment

Copy link
Copy Markdown
Member

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, Bradley Grainger (@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
Eric Erhardt (eerhardt) merged commit e097223 into microsoft:main Nov 18, 2023
@davidfowl

Copy link
Copy Markdown
Collaborator

Amazing 🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-integrations Issues pertaining to Aspire Integrations packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add MySQL Aspire Component

8 participants