Skip to content

Feature/redis async factory - #2483

Closed
maikebing wants to merge 168 commits into
Xabaril:masterfrom
DotNetDiag:feature/redis-async-factory
Closed

Feature/redis async factory#2483
maikebing wants to merge 168 commits into
Xabaril:masterfrom
DotNetDiag:feature/redis-async-factory

Conversation

@maikebing

Copy link
Copy Markdown
Contributor
<!--  Thanks for sending a pull request!
-->

**What this PR does / why we need it**:

Adds a cancellation-aware asynchronous Redis connection factory:

```csharp
AddRedis(
    Func<IServiceProvider, CancellationToken, Task<IConnectionMultiplexer>> connectionMultiplexerFactory,
    ...)

This PR originates from the proposal in [DotNetDiag/HealthChecks#37](DotNetDiag#37). The issue describes scenarios where Redis credentials, connection strings, or the IConnectionMultiplexer are only available after asynchronous initialization.

The new overload defers factory execution until the health check runs, forwards the health check cancellation token, and handles cancellation as a timeout result. Applications can resolve credentials or connection strings inside the factory while retaining ownership of a shared IConnectionMultiplexer.

The implementation is based on the useful part of upstream [Xabaril PR #2305](#2305), but does not copy its delegate-keyed connection cache behavior. Existing string-based Redis connection caching remains unchanged.

Which issue(s) this PR fixes:

Closes #37

Special notes for your reviewer:

  • This is an additive, backward-compatible API change.
  • The async factory is invoked lazily during health-check execution, not during service registration.
  • The provided CancellationToken is passed to the factory.
  • Async factory cancellation returns the existing Healthcheck timed out result.
  • The async factory is intentionally multiplexer-based; asynchronous connection-string or credential resolution can be performed inside the factory.
  • Tests cover lazy invocation, successful health-check execution, cancellation-token propagation, and cancellation handling.
  • Documentation and usage samples have been updated.
  • The upstream PR was used as the starting point, but was not merged verbatim because its delegate-keyed cache could break reuse of connections with the same connection string.

Does this PR introduce a user-facing change?:

Yes. It introduces a new AddRedis overload for asynchronous IConnectionMultiplexer factories.

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Unit tests passing
  • End-to-end tests passing
  • Extended the documentation
  • Provided sample for the feature
 

belairgrics and others added 30 commits April 25, 2025 10:16
…s all health check projects and add outdated packages JSON file.
- Changed the .NET SDK version from 9.0.x to 10.0.x in multiple GitHub Actions workflows for health checks.
- Updated Directory.Packages.props to support .NET 10.0.
- Modified target frameworks in various HealthChecks.UI projects to use $(DefaultNetCoreTargetFrameworks).
- Removed unnecessary PackageReference for Microsoft.Extensions.Diagnostics.HealthChecks in HealthChecks.Prometheus.Metrics and HealthChecks.Publisher.Prometheus projects.
- Adjusted FunctionalTests project to exclude HealthChecks.UI files and updated package references.
- Enhanced nullability annotations in HttpClientExtensions and HostBuilderHelper classes.
- Create a new workflow `nuget_release_on_version_tag.yml` that triggers on version tag pushes.
- Validate semantic versioning for tags and resolve the previous version tag.
- Detect changed packages and determine which ones need to be built and published.
- Implement a matrix strategy to publish packages based on detected changes.
- Ensure proper permissions for accessing contents and writing packages.
… logic

- Added permissions for contents and packages in multiple CI workflows.
- Changed tags-ignore to tags for versioning in CI workflows.
- Inherited secrets in reusable CI workflow calls.
- Introduced a new script `get-release-scope.ps1` to determine release scope based on tags and project references.
- Enhanced reusable CI workflow to handle versioning and package publishing.
- Created a reusable UI CD workflow for HealthChecks UI projects.
- Updated HealthChecks Solr CI workflow to include release scope determination and conditional publishing.
maikebing and others added 28 commits May 10, 2026 14:52
…althChecks.UI/npm_and_yarn-31fdac4bcf

build(deps): bump the npm_and_yarn group across 1 directory with 6 updates
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 6 to 7.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](codecov/codecov-action@v6...v7)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [actions/checkout](https://github.com/actions/checkout) from 6 to 7.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v6...v7)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
@maikebing maikebing closed this Aug 16, 2026
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 44.06780% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.29%. Comparing base (72d9abf) to head (32e63b2).
⚠️ Report is 41 commits behind head on master.

Files with missing lines Patch % Lines
...ks.UI.Image/Configuration/AzureAppConfiguration.cs 0.00% 10 Missing ⚠️
...mage/Extensions/IEndpointRouteBuilderExtensions.cs 0.00% 10 Missing ⚠️
...hecks.UI.Image/Extensions/HttpRequestExtensions.cs 78.78% 4 Missing and 3 partials ⚠️
...mage/Extensions/IConfigurationBuilderExtensions.cs 0.00% 3 Missing ⚠️
...ild/docker-images/HealthChecks.UI.Image/Startup.cs 0.00% 2 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2483      +/-   ##
==========================================
- Coverage   66.88%   62.29%   -4.60%     
==========================================
  Files         268      284      +16     
  Lines        8730    10072    +1342     
  Branches      631      737     +106     
==========================================
+ Hits         5839     6274     +435     
- Misses       2723     3568     +845     
- Partials      168      230      +62     
Flag Coverage Δ
ApplicationStatus 28.67% <ø> (ø)
ArangoDb 28.30% <ø> (ø)
Aws.S3 15.52% <ø> (ø)
Aws.SecretsManager 15.82% <ø> (ø)
Aws.Sns ?
Aws.Sqs ?
Aws.SystemsManager 15.82% <ø> (ø)
Azure.IoTHub 34.75% <ø> (+20.92%) ⬆️
AzureApplicationInsights 16.56% <ø> (ø)
AzureBlobStorage 27.46% <ø> (+1.03%) ⬆️
AzureDigitalTwin 37.15% <ø> (ø)
AzureEventHubs 17.46% <ø> (ø)
AzureFileStorage 26.42% <ø> (ø)
AzureKeyVault 30.08% <ø> (-0.41%) ⬇️
AzureQueueStorage 27.46% <ø> (+1.03%) ⬆️
AzureSearch 20.27% <ø> (+2.66%) ⬆️
AzureServiceBus 73.29% <ø> (+0.81%) ⬆️
AzureTableStorage 33.97% <ø> (+6.00%) ⬆️
Consul 24.32% <ø> (ø)
ContainerRegistry 44.65% <ø> (?)
CosmosDb 29.45% <ø> (ø)
Dapr 13.74% <ø> (-0.77%) ⬇️
DocumentDb ?
DuckDb 41.11% <ø> (?)
DynamoDb 13.29% <ø> (ø)
Elasticsearch 47.00% <ø> (-0.67%) ⬇️
EventStore 64.57% <ø> (-0.58%) ⬇️
EventStore.gRPC 24.82% <ø> (-0.69%) ⬇️
Gcp.CloudFirestore 13.33% <ø> (ø)
Gcp.CloudStorage 31.33% <ø> (?)
Grafana 47.36% <ø> (?)
Gremlin 25.00% <ø> (ø)
Hangfire 12.10% <ø> (ø)
Harbor 54.90% <ø> (?)
IbmMQ 28.20% <ø> (-2.57%) ⬇️
InfluxDB 14.50% <ø> (-1.04%) ⬇️
Kafka ?
Kubernetes 40.07% <ø> (-1.48%) ⬇️
Milvus ?
MongoDb ?
MySql ?
NTPServer 33.87% <ø> (?)
Nats 16.40% <ø> (-56.37%) ⬇️
Npgsql ?
OpenIdConnectServer 42.48% <ø> (ø)
Oracle 63.92% <ø> (ø)
Prometheus.Metrics 29.80% <ø> (ø)
Publisher.ApplicationInsights 16.06% <ø> (+0.79%) ⬆️
Publisher.CloudWatch 20.00% <ø> (-0.34%) ⬇️
Publisher.Datadog 16.56% <ø> (-0.64%) ⬇️
Publisher.Prometheus 18.75% <ø> (ø)
Publisher.Seq 39.68% <ø> (-1.06%) ⬇️
Qdrant ?
RabbitMQ ?
RavenDb ?
Redis ?
SendGrid 17.21% <ø> (ø)
SignalR 24.67% <ø> (-1.30%) ⬇️
SqlServer ?
Sqlite 28.20% <ø> (+2.32%) ⬆️
System 42.56% <ø> (-1.03%) ⬇️
UI 55.82% <44.06%> (-10.05%) ⬇️
Uris 61.86% <ø> (-0.29%) ⬇️
Vault 60.48% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RedisCheck should switch to new StackExchange.Redis library

9 participants