Skip to content

Update service memory mitigation: remove stale system health checks#266

Open
alexbass112 wants to merge 1 commit intoAzure:mainfrom
alexbass112:user/alexbass/memory-tsg-update
Open

Update service memory mitigation: remove stale system health checks#266
alexbass112 wants to merge 1 commit intoAzure:mainfrom
alexbass112:user/alexbass/memory-tsg-update

Conversation

@alexbass112
Copy link
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings March 23, 2026 19:09
Copy link
Contributor

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

Updates an Azure Local TSG mitigation script intended to reduce Update Service memory pressure by cleaning up health check artifacts and clearing the Update Service cache when cleanup occurs.

Changes:

  • Moves $removedHC initialization outside the installed-updates loop and keeps cache-clear gated on whether anything was removed.
  • Adds logic to remove stale entries under the HealthCheck\System directory (keeping the most recent set).
  • Updates the cache-clear endpoint discovery to use the explicit Update Service cluster group name.

Comment on lines +87 to +92
$oldSystemChecks = Get-ChildItem $systemHealthCheckPath | sort LastWriteTime | select -SkipLast 10
if ($oldSystemChecks)
{
Write-Host "Some health checks were removed, so clearing update service cache."
$clientCert = ls Cert:\LocalMachine\My\ | ? Subject -match "URP" | sort NotAfter | select -last 1
$updateEndpoint = "https://$(Get-ClusterGroup *update* | % OwnerNode | % Name).$($env:USERDNSDOMAIN):4900"
$clearCacheResult = Invoke-WebRequest -Certificate $clientCert -UseBasicParsing -Uri "$updateEndpoint/caches/Update" -Method "Delete"
if ([int]::TryParse($clearCacheResult.Content, [ref]$null))
{
Write-Host "Removed $($clearCacheResult.Content) updates from the cache."
}
else
{
Write-Warning "Unexpected result from clearing the cache: $($clearCacheResult | Out-String)"
}
Write-Host "Removing $(oldSystemChecks.Count) old system health check results."
$removedHC = $true
$oldSystemChecks | Remove-Item -Force -Verbose
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

In the system health cleanup block, the script references $systemHealthCheckPath (undefined) instead of $systemHealthPath, and the log message uses $(oldSystemChecks.Count) without $ (will error in the subexpression). Additionally, Select-Object -SkipLast is not available in Windows PowerShell 5.1 (typical default on nodes), so this line will fail unless running PowerShell 7+. Update the path variable reference, fix the subexpression to use $oldSystemChecks, and use a PowerShell 5.1-compatible approach to keep the newest 10 items (e.g., sort descending and skip 10).

Copilot uses AI. Check for mistakes.
{
Write-Host "Some health checks were removed, so clearing update service cache."
$clientCert = ls Cert:\LocalMachine\My\ | ? Subject -match "URP" | sort NotAfter | select -last 1
$updateEndpoint = "https://$(Get-ClusterGroup "Azure Stack HCI Update Service Cluster Group" | % OwnerNode | % Name).$($env:USERDNSDOMAIN):4900"
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

This assignment to $updateEndpoint uses a double-quoted string that contains another double-quoted string inside the $() expression (Get-ClusterGroup "Azure Stack HCI Update Service Cluster Group"), which will break PowerShell parsing. Use single quotes for the cluster group name (or build the URL in multiple steps) so the outer string remains valid.

Suggested change
$updateEndpoint = "https://$(Get-ClusterGroup "Azure Stack HCI Update Service Cluster Group" | % OwnerNode | % Name).$($env:USERDNSDOMAIN):4900"
$updateEndpoint = "https://$(Get-ClusterGroup 'Azure Stack HCI Update Service Cluster Group' | % OwnerNode | % Name).$($env:USERDNSDOMAIN):4900"

Copilot uses AI. Check for mistakes.
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.

2 participants