-
-
Notifications
You must be signed in to change notification settings - Fork 852
Test-DbaAvailabilityGroup - Add comprehensive AG health monitoring #9885
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
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
53119b9
Test-DbaAvailabilityGroup - Add comprehensive AG health monitoring
github-actions[bot] 8994670
Test-DbaAvailabilityGroup - Add comprehensive integration tests for -…
github-actions[bot] 1d60c49
Fix typo in Test-DbaAvailabilityGroup -HealthCheck parameter
github-actions[bot] 5e13435
CLAUDE.md, Test-DbaAvailabilityGroup - Document Microsoft SMO typo an…
github-actions[bot] 9f8e057
CLAUDE.md - Merge development branch updates with PR branch changes
github-actions[bot] c589b84
Merge branch 'development' into claude/issue-2190-20251029-1419
potatoqualitee 5553aba
Merge branch 'development' into claude/issue-2190-20251029-1419
potatoqualitee 1195c89
Test-DbaAvailabilityGroup - Use direct PSCustomObject casting for ord…
github-actions[bot] 5353cf6
CLAUDE.md - Add guidance for preserving Position attributes when mode…
github-actions[bot] 5ac8603
Merge branch 'development' into claude/issue-2190-20251029-1419
potatoqualitee 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -48,6 +48,10 @@ function Test-DbaAvailabilityGroup { | |
| Validates that the most recent database backup chain can be used for AG database addition. | ||
| Enables validation using existing backups instead of creating new ones, but requires the last backup to be a transaction log backup. Use this to test AG readiness with your current backup strategy. | ||
|
|
||
| .PARAMETER HealthCheck | ||
| Performs comprehensive health monitoring of the Availability Group similar to SSMS AG Dashboard. | ||
| Returns detailed replica and database synchronization status including queue sizes, LSN information, and performance metrics. Use this to monitor AG health, identify synchronization issues, or troubleshoot failover readiness. | ||
|
|
||
| .PARAMETER EnableException | ||
| By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message. | ||
| This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting. | ||
|
|
@@ -73,21 +77,27 @@ function Test-DbaAvailabilityGroup { | |
| PS C:\> Test-DbaAvailabilityGroup -SqlInstance SQL2016 -AvailabilityGroup TestAG1 -AddDatabase AdventureWorks -SeedingMode Automatic | ||
|
|
||
| Test if database AdventureWorks can be added to the Availability Group TestAG1 with automatic seeding. | ||
|
|
||
| .EXAMPLE | ||
| PS C:\> Test-DbaAvailabilityGroup -SqlInstance SQL2016 -AvailabilityGroup TestAG1 -HealthCheck | ||
|
|
||
| Performs comprehensive health monitoring of TestAG1, returning detailed synchronization status for all replicas and databases similar to SSMS AG Dashboard. | ||
| #> | ||
| [CmdletBinding()] | ||
| param ( | ||
| [Parameter(Mandatory = $true, Position = 0)] | ||
| [Parameter(Mandatory)] | ||
| [DbaInstanceParameter]$SqlInstance, | ||
| [PSCredential]$SqlCredential, | ||
| [Parameter(Mandatory = $true)] | ||
| [Parameter(Mandatory)] | ||
| [string]$AvailabilityGroup, | ||
| [DbaInstanceParameter[]]$Secondary, | ||
| [PSCredential]$SecondarySqlCredential, | ||
| [string[]]$AddDatabase, | ||
| [ValidateSet('Automatic', 'Manual')] | ||
| [ValidateSet("Automatic", "Manual")] | ||
| [string]$SeedingMode, | ||
| [string]$SharedPath, | ||
| [switch]$UseLastBackup, | ||
| [switch]$HealthCheck, | ||
| [switch]$EnableException | ||
| ) | ||
| process { | ||
|
|
@@ -110,22 +120,74 @@ function Test-DbaAvailabilityGroup { | |
| return | ||
| } | ||
|
|
||
| if ($ag.LocalReplicaRole -ne 'Primary') { | ||
| if (-not $HealthCheck -and $ag.LocalReplicaRole -ne 'Primary') { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, if HealthCheck param is passed but it's not Primary, this will not get called. Should this always be if we are not on the primary replica no matter health check or not? |
||
| Stop-Function -Message "LocalReplicaRole of replica $server is not Primary, but $($ag.LocalReplicaRole). Please connect to the current primary replica $($ag.PrimaryReplica)." | ||
| return | ||
| } | ||
|
|
||
| # Test for health of Availability Group | ||
|
|
||
| # Later: Get replica and database states like in SSMS dashboard | ||
| # Now: Just test for ConnectionState -eq 'Connected' | ||
| if ($HealthCheck) { | ||
| # Comprehensive health monitoring similar to SSMS AG Dashboard | ||
| # Returns detailed database replica state information for all replicas | ||
|
|
||
| foreach ($replica in $ag.AvailabilityReplicas) { | ||
| $replicaId = $replica.UniqueId | ||
| $replicaStates = $ag.DatabaseReplicaStates | Where-Object AvailabilityReplicaId -eq $replicaId | ||
|
|
||
| # Note on further development: | ||
| # As long as there are no databases in the Availability Group, test for RollupSynchronizationState is not useful | ||
| foreach ($db in $ag.AvailabilityDatabases) { | ||
| $databaseReplicaState = $replicaStates | Where-Object AvailabilityDateabaseId -eq $db.UniqueId | ||
| if ($null -eq $databaseReplicaState) { | ||
| continue | ||
| } | ||
|
|
||
| # The primary replica always has the best information about all the replicas. | ||
| # We can maybe also connect to the secondary replicas and test their view of the situation, but then only test the local replica. | ||
| [PSCustomObject]@{ | ||
| ComputerName = $ag.ComputerName | ||
| InstanceName = $ag.InstanceName | ||
| SqlInstance = $ag.SqlInstance | ||
| AvailabilityGroup = $ag.Name | ||
| PrimaryReplica = $ag.PrimaryReplica | ||
| ReplicaServerName = $databaseReplicaState.AvailabilityReplicaServerName | ||
| ReplicaRole = $databaseReplicaState.ReplicaRole | ||
| ReplicaAvailabilityMode = $replica.AvailabilityMode | ||
| ReplicaFailoverMode = $replica.FailoverMode | ||
| ReplicaConnectionState = $replica.ConnectionState | ||
| ReplicaJoinState = $replica.JoinState | ||
| ReplicaSynchronizationState = $replica.RollupSynchronizationState | ||
| DatabaseName = $databaseReplicaState.AvailabilityDatabaseName | ||
| SynchronizationState = $databaseReplicaState.SynchronizationState | ||
| IsFailoverReady = $databaseReplicaState.IsFailoverReady | ||
| IsJoined = $databaseReplicaState.IsJoined | ||
| IsSuspended = $databaseReplicaState.IsSuspended | ||
| SuspendReason = $databaseReplicaState.SuspendReason | ||
| EstimatedRecoveryTime = $databaseReplicaState.EstimatedRecoveryTime | ||
| EstimatedDataLoss = $databaseReplicaState.EstimatedDataLoss | ||
| SynchronizationPerformance = $databaseReplicaState.SynchronizationPerformance | ||
| LogSendQueueSize = $databaseReplicaState.LogSendQueueSize | ||
| LogSendRate = $databaseReplicaState.LogSendRate | ||
| RedoQueueSize = $databaseReplicaState.RedoQueueSize | ||
| RedoRate = $databaseReplicaState.RedoRate | ||
| FileStreamSendRate = $databaseReplicaState.FileStreamSendRate | ||
| EndOfLogLSN = $databaseReplicaState.EndOfLogLSN | ||
| RecoveryLSN = $databaseReplicaState.RecoveryLSN | ||
| TruncationLSN = $databaseReplicaState.TruncationLSN | ||
| LastCommitLSN = $databaseReplicaState.LastCommitLSN | ||
| LastCommitTime = $databaseReplicaState.LastCommitTime | ||
| LastHardenedLSN = $databaseReplicaState.LastHardenedLSN | ||
| LastHardenedTime = $databaseReplicaState.LastHardenedTime | ||
| LastReceivedLSN = $databaseReplicaState.LastReceivedLSN | ||
| LastReceivedTime = $databaseReplicaState.LastReceivedTime | ||
| LastRedoneLSN = $databaseReplicaState.LastRedoneLSN | ||
| LastRedoneTime = $databaseReplicaState.LastRedoneTime | ||
| LastSentLSN = $databaseReplicaState.LastSentLSN | ||
| LastSentTime = $databaseReplicaState.LastSentTime | ||
| } | ||
| } | ||
| } | ||
| return | ||
| } | ||
|
|
||
| # Basic connectivity test for non-HealthCheck scenarios | ||
| $failure = $false | ||
| foreach ($replica in $ag.AvailabilityReplicas) { | ||
| if ($replica.ConnectionState -ne 'Connected') { | ||
|
|
@@ -138,7 +200,6 @@ function Test-DbaAvailabilityGroup { | |
| return | ||
| } | ||
|
|
||
|
|
||
| # For now, just output the base information. | ||
|
|
||
| if (-not $AddDatabase) { | ||
|
|
||
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.
Not 100 percent sure, but this might be a breaking change. I think
Position = 0is needed to be able to useTest-DbaAvailabilityGroup $sqlInstance [...]instead ofTest-DbaAvailabilityGroup -SqlInstance $sqlInstance [...]. This is not consistent in our code base.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.
good point, ill tell it to keep positional parameters.
@claude pls update claude.md again to say dont mess with the positional params when removing the mandatory=true
Uh oh!
There was an error while loading. Please reload this page.
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.
Claude finished @potatoqualitee's task —— View job
CLAUDE.md updated with positional parameter guidance ✓
Task List:
Summary
Successfully updated CLAUDE.md with comprehensive guidance about preserving
Positionattributes when modernizing parameter syntax.Changes made:
Added critical guideline in the "PARAMETER ATTRIBUTES" section:
Positionattributes when modernizing fromMandatory = $truetoMandatoryUpdated code examples to show:
[Parameter(Mandatory, Position = 0)](modern syntax, Position preserved)[Parameter(Mandatory = $true, Position = 0)](outdated PSv2 syntax)[Parameter(Mandatory)]when Position was in the original (breaking change)Enhanced verification checklist with new requirement:
Updated golden rules (now 12 rules):
The guidance ensures that when modernizing parameter attributes, commands remain backward compatible and users can still use positional syntax (e.g.,
Test-DbaAvailabilityGroup $instanceinstead ofTest-DbaAvailabilityGroup -SqlInstance $instance).View commit |