-
Notifications
You must be signed in to change notification settings - Fork 803
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
Use MySqlDataSource in AddMySql
by default
#2096
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e7917f8
Send a MySQL ping packet by default. Fixes #2031
bgrainger e58c262
Add AddMySql overload for MySqlDataSource.
bgrainger 479d8f0
Add package README for HealthChecks.MySql.
bgrainger d62373e
Merge master into mysql-data-source.
bgrainger f4af126
Use new MySqlHealthCheckOptions API.
bgrainger c58614c
Merge master into mysql-data-source.
bgrainger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
## MySQL Health Check | ||
|
||
This health check verifies the ability to communicate with a MySQL Server. | ||
It uses the provided [MySqlDataSource](https://mysqlconnector.net/api/mysqlconnector/mysqldatasourcetype/) or a connection string to connect to the server. | ||
|
||
### Defaults | ||
|
||
By default, the `MySqlDataSource` instance is resolved from service provider. | ||
(This should be the same as the instance being used by the application; do not create a new `MySqlDataSource` just for the health check.) | ||
The health check will send a MySQL "ping" packet to the server to verify connectivity. | ||
|
||
```csharp | ||
builder.Services | ||
.AddMySqlDataSource(builder.Configuration.GetConnectionString("mysql")) // using the MySqlConnector.DependencyInjection package | ||
.AddHealthChecks().AddMySql(); | ||
``` | ||
|
||
### Connection String | ||
|
||
You can also specify a connection string directly: | ||
|
||
```csharp | ||
builder.Services.AddHealthChecks().AddMySql(connectionString: "Server=...;User Id=...;Password=..."); | ||
``` | ||
|
||
This can be useful if you're not using `MySqlDataSource` in your application. | ||
|
||
### Customization | ||
|
||
You can additionally add the following parameters: | ||
|
||
- `healthQuery`: A query to run against the server. If `null` (the default), the health check will send a MySQL "ping" packet to the server. | ||
- `configure`: An action to configure the `MySqlConnection` object. This is called after the `MySqlConnection` is created but before the connection is opened. | ||
- `name`: The health check name. The default is `mysql`. | ||
- `failureStatus`: The `HealthStatus` that should be reported when the health check fails. Default is `HealthStatus.Unhealthy`. | ||
- `tags`: A list of tags that can be used to filter sets of health checks. | ||
- `timeout`: A `System.TimeSpan` representing the timeout of the check. | ||
|
||
```csharp | ||
builder.Services | ||
.AddMySqlDataSource(builder.Configuration.GetConnectionString("mysql")) | ||
.AddHealthChecks().AddMySql( | ||
healthQuery: "SELECT 1;", | ||
configure: conn => conn.ConnectTimeout = 3, | ||
name: "MySQL" | ||
); | ||
``` | ||
|
||
### Breaking changes | ||
|
||
In previous versions, `MySqlHealthCheck` defaulted to testing connectivity by sending a `SELECT 1;` query to the server. | ||
It has been changed to send a more efficient "ping" packet instead. | ||
To restore the previous behavior, specify `healthQuery: "SELECT 1;"` when registering the health check. | ||
|
||
While not a breaking change, it's now preferred to use `MySqlDataSource` instead of a connection string. | ||
This allows the health check to use the same connection pool as the rest of the application. | ||
This can be achieved by calling the `.AddMySql()` overload that has no required parameters. | ||
The health check assumes that a `MySqlDataSource` instance has been registered with the service provider and will retrieve it automatically. | ||
|
||
bgrainger marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
test/HealthChecks.MySql.Tests/HealthChecks.MySql.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We don't need these checks anymore, as the public ctors ensure that the state is always valid.
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.
For some reason I can't apply this suggestion. I am going to merge it now since it's not blocking
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.
#2129