Skip to content

feat: aurora connection tracker plugin#250

Open
gagan-kaur786 wants to merge 44 commits intoaws:mainfrom
gagan-kaur786:feat/aurora-connection-tracker
Open

feat: aurora connection tracker plugin#250
gagan-kaur786 wants to merge 44 commits intoaws:mainfrom
gagan-kaur786:feat/aurora-connection-tracker

Conversation

@gagan-kaur786
Copy link
Copy Markdown
Collaborator

@gagan-kaur786 gagan-kaur786 commented Mar 9, 2026

Summary

feat: add aurora connection tracker plugin

Description

Adds the aurora connection tracker plugin. This plugin tracks all the opened connections. In the event of a cluster failover, this plugin will close all the impacted connections. If no plugins are explicitly specified, this plugin is enabled by default.

Additional Reviewers

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copilot AI review requested due to automatic review settings March 9, 2026 19:40
@gagan-kaur786 gagan-kaur786 marked this pull request as draft March 9, 2026 19:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements the Aurora Connection Tracker Plugin for the .NET AWS wrapper. It tracks all opened database connections keyed by RDS instance endpoint and aliases (when no RDS instance endpoint is found) and closes stale connections to the old writer after a cluster failover, preventing applications from accidentally using connections that now point to a reader.

Changes:

  • New AuroraConnectionTrackerPlugin and OpenedConnectionTracker classes providing connection lifecycle interception and thread-safe tracking
  • Plugin registration in ConnectionPluginChainBuilder and PluginCodes
  • Supporting spec docs (requirements and design) and resource strings for logging

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
AuroraConnectionTrackerPlugin.cs Core plugin: intercepts open/execute/close to track connections and detect writer changes
OpenedConnectionTracker.cs Thread-safe tracking map; handles populate, invalidate, remove, and background pruning
AuroraConnectionTrackerPluginFactory.cs Factory that creates plugin instances
ConnectionPluginChainBuilder.cs Registers the new plugin factory and assigns execution weight 400
PluginCodes.cs Adds the "auroraConnectionTracker" plugin code constant
Resources.resx Adds localized log/error message strings for the tracker
requirements.md Spec requirements document for the feature
design.md Detailed design document including architecture, data models, and testing strategy
Files not reviewed (1)
  • AwsWrapperDataProvider/Properties/Resources.Designer.cs: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

try
{
string cleanHost = RdsUtils.RemovePort(key);
if (!RdsUtils.IsRdsInstance(cleanHost))
Copy link
Copy Markdown
Contributor

@karenc-bq karenc-bq Mar 17, 2026

Choose a reason for hiding this comment

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

We should try to see if this host is tracked regardless, in case it is a custom endpoint

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, will be updated as part of tracking custom endpoints change.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

@gagan-kaur786 gagan-kaur786 marked this pull request as ready for review March 19, 2026 17:41
@kenrickyap
Copy link
Copy Markdown
Contributor

Let's make sure the existing integration test is passing and that we fix the existing linting errors

Copy link
Copy Markdown
Contributor

@kenrickyap kenrickyap left a comment

Choose a reason for hiding this comment

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

minor nits, LGTM

/// <param name="connection">The database connection to track.</param>
public void PopulateOpenedConnectionQueue(HostSpec hostSpec, DbConnection connection)
{
EnsurePruneLoopRunning();
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.

Do we need this verification here if we already have it in the constructor?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is kept for two potential cases: (1) if the background prune task faults unexpectedly and silently dies, or (2) ReleaseResources() is called but the same tracker instance continues to be used, the constructor won't re-run, so the loop stays dead. This check ensures that every time we track a new connection, we verify the loop is still running and restart it if needed. The cost is negligible- one lock check per connection open.

{
{ PluginCodes.ConnectTime, new Lazy<IConnectionPluginFactory>(() => new ConnectTimePluginFactory()) },
{ PluginCodes.ExecutionTime, new Lazy<IConnectionPluginFactory>(() => new ExecutionTimePluginFactory()) },
{ PluginCodes.AuroraConnectionTracker, new Lazy<IConnectionPluginFactory>(() => new AuroraConnectionTrackerPluginFactory()) },
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.

I think this particular list follows the alphabetical order

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not really. But I've updated the sequence to match plugin weights order, same as in PluginWeightByPluginFactoryType.

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.

5 participants