Replace Valkey with DragonFly as session store and caching solution#43
Replace Valkey with DragonFly as session store and caching solution#43
Conversation
…solution - Updated docker-compose files to replace Valkey services with DragonFly services (master, replica, and proxy). - Modified health checks and connection strings to use DragonFly. - Updated documentation to reflect the changes from Valkey to DragonFly, including caching and session management. - Implemented DragonFlyTicketStore for ASP.NET Core authentication ticket storage. - Added DragonflyOptions for configuration settings related to DragonFly. - Updated integration tests to remove Valkey references and use DragonFly. - Configured HAProxy for DragonFly in Docker Compose and added Kubernetes deployment instructions for DragonFly.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request transitions the application's in-memory data store from Valkey to DragonFly. This change impacts session management, output caching, and data protection, aiming to leverage DragonFly's performance benefits and robust high-availability features. The update involves comprehensive configuration adjustments across development and production environments, alongside detailed documentation to support the new infrastructure. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request successfully replaces Valkey with DragonFly for caching and session storage. The changes are comprehensive, covering application code, configuration, documentation, testing, and infrastructure for both development (single-node) and production (HA with master-replica and proxy). The implementation is solid, introducing configurable timeouts for DragonFly connections and a resilient connection setup. I've found a couple of issues in the documentation where docker compose commands will fail due to referencing services from the wrong compose file. I've also included a suggestion to improve the clarity of memory limit configuration in the new Kubernetes manifest for DragonFly.
| ```bash | ||
| # Start only the databases and Keycloak | ||
| docker compose up -d postgres mongodb keycloak valkey | ||
| docker compose up -d postgres mongodb keycloak dragonfly-master dragonfly-replica dragonfly-proxy |
There was a problem hiding this comment.
The docker compose command references services (dragonfly-master, dragonfly-replica, dragonfly-proxy) that are defined in docker-compose.production.yml, not the default docker-compose.yml. This command will fail as-is. To use the HA setup for local infrastructure, you should specify the production compose file.
| docker compose up -d postgres mongodb keycloak dragonfly-master dragonfly-replica dragonfly-proxy | |
| docker compose -f docker-compose.production.yml up -d postgres mongodb keycloak dragonfly-master dragonfly-replica dragonfly-proxy |
|
|
||
| ```bash | ||
| ASPIRE_OTLP_GRPC_PORT=18889 ASPIRE_OTLP_HTTP_PORT=18890 docker compose --profile aspire up -d postgres mongodb keycloak-db keycloak valkey alloy prometheus loki tempo grafana aspire-dashboard | ||
| ASPIRE_OTLP_GRPC_PORT=18889 ASPIRE_OTLP_HTTP_PORT=18890 docker compose --profile aspire up -d postgres mongodb keycloak-db keycloak dragonfly-master dragonfly-replica dragonfly-proxy alloy prometheus loki tempo grafana aspire-dashboard |
There was a problem hiding this comment.
The docker compose command references services (dragonfly-master, dragonfly-replica, dragonfly-proxy) that are defined in docker-compose.production.yml, while other services in the command (like alloy and aspire-dashboard) are in the default docker-compose.yml. This will cause the command to fail. For a local development setup with observability, using the single dragonfly service from docker-compose.yml is more appropriate and resolves the conflict.
| ASPIRE_OTLP_GRPC_PORT=18889 ASPIRE_OTLP_HTTP_PORT=18890 docker compose --profile aspire up -d postgres mongodb keycloak-db keycloak dragonfly-master dragonfly-replica dragonfly-proxy alloy prometheus loki tempo grafana aspire-dashboard | |
| ASPIRE_OTLP_GRPC_PORT=18889 ASPIRE_OTLP_HTTP_PORT=18890 docker compose --profile aspire up -d postgres mongodb keycloak-db keycloak dragonfly alloy prometheus loki tempo grafana aspire-dashboard |
| memory: 512Mi | ||
| args: | ||
| - "--maxmemory" | ||
| - "512mb" |
There was a problem hiding this comment.
The container memory limit is set to 512Mi (in limits), while the DragonFly maxmemory argument is set to 512mb. While 512mb (megabytes) is less than 512Mi (mebibytes), using the same number 512 can be confusing. To improve clarity and avoid potential misconfiguration, consider making the numbers different. For example, setting maxmemory to 500mb makes it explicit that it's below the container's 512Mi limit.
- "500mb"There was a problem hiding this comment.
Pull request overview
This PR migrates the template’s Redis-compatible backing services from Valkey to DragonFly across application code, test infrastructure, configuration, Docker/Kubernetes assets, and documentation.
Changes:
- Replace Valkey-based caching/session-store wiring with DragonFly equivalents (options, DI registrations, health check name).
- Update Docker Compose (dev + production HA topology with HAProxy) and add Kubernetes operator manifests/docs for DragonFly.
- Refresh docs and test helpers to reference DragonFly configuration keys and components.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/APITemplate.Tests/Integration/Helpers/TestServiceHelper.cs | Updates test DI helpers to remove/replace DragonFly-backed services during integration tests. |
| tests/APITemplate.Tests/Integration/Helpers/TestConfigurationHelper.cs | Switches base test config key from Valkey to Dragonfly. |
| src/APITemplate.Infrastructure/Security/DragonflyTicketStore.cs | Renames ticket store to DragonFly variant for BFF cookie session storage. |
| src/APITemplate.Application/Common/Options/ValkeyOptions.cs | Removes Valkey options type. |
| src/APITemplate.Application/Common/Options/DragonflyOptions.cs | Introduces DragonFly options with connection + timeout settings. |
| src/APITemplate.Api/Extensions/AuthenticationServiceCollectionExtensions.cs | Registers DragonflyTicketStore as the cookie session store. |
| src/APITemplate.Api/Extensions/ApiServiceCollectionExtensions.cs | Replaces Valkey wiring with DragonFly (multiplexer config, cache, data protection, health check). |
| src/APITemplate.Api/appsettings.Development.json | Updates dev config section name to Dragonfly. |
| README.md | Updates documentation references and diagrams from Valkey to DragonFly. |
| infrastructure/observability/prometheus/rules/apitemplate-alerts.yml | Updates alert rule selector to use dragonfly health check label. |
| infrastructure/kubernetes/dragonfly/README.md | Adds Kubernetes operator deployment instructions for DragonFly. |
| infrastructure/kubernetes/dragonfly/dragonfly.yml | Adds DragonFly CR manifest for operator-managed HA. |
| infrastructure/dragonfly/haproxy.cfg | Adds HAProxy TCP routing config for master/replica topology. |
| docs/testing.md | Updates test helper documentation from Valkey to DragonFly. |
| docs/README.md | Updates docs index entry to reference DragonFly in caching guide. |
| docs/observability.md | Updates compose command and tracing wording from Valkey to DragonFly. |
| docs/CACHING.md | Rewrites caching guide for DragonFly, including HA topologies and config keys. |
| docs/AUTHENTICATION.md | Updates authentication/session-store diagrams and text from Valkey to DragonFly. |
| docker-compose.yml | Replaces Valkey container with DragonFly for local dev compose. |
| docker-compose.production.yml | Introduces DragonFly master/replica + HAProxy topology and updates API env var. |
| .vscode/tasks.json | Updates VS Code task service list from valkey to dragonfly. |
| .vscode/launch.json | Updates debug env var key from Valkey__ConnectionString to Dragonfly__ConnectionString. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
|
||
| public int ConnectTimeoutMs { get; init; } = DefaultConnectTimeoutMs; | ||
|
|
| - ./infrastructure/dragonfly/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro | ||
| ``` | ||
|
|
||
| The API connects to `dragonfly-proxy:6379`. Direct master access is available on port `6380` for debugging. |
| | `Keycloak__resource` | Client ID | | ||
| | `Keycloak__credentials__secret` | Client secret | | ||
| | `Valkey__ConnectionString` | Valkey/Redis connection string | | ||
| | `DragonFly__ConnectionString` | DragonFly/Redis connection string | |
| VK[(DragonFly)] | ||
| EF ---> DB | ||
| Mongo ---> MDB | ||
| REST -..-> VK |
Transition from Valkey to DragonFly for session management and caching, updating configurations, documentation, and integration tests accordingly. Implement DragonFly-specific options and health checks, and configure Docker and Kubernetes deployments for DragonFly.