-
Notifications
You must be signed in to change notification settings - Fork 48
Update service memory mitigation: remove stale system health checks #266
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -61,9 +61,10 @@ $installedUpdates = Get-SolutionUpdate | where State -eq Installed | |||||
| $resourceIds = @( $installedUpdates | % { $_.ResourceId.Split('/')[-1] } ) | ||||||
| Write-Host "Found $($installedUpdates.Count) installed updates: $($resourceIds -join ", ")" | ||||||
| $removedHC = $false | ||||||
| if ($resourceIds.Count -gt 0) | ||||||
| { | ||||||
| $removedHC = $false | ||||||
| foreach ($resourceId in $resourceIds) | ||||||
| { | ||||||
| $healthCheckPath = Join-Path "C:\ClusterStorage\Infrastructure_1\Shares\SU1_Infrastructure_1\Updates\HealthCheck" $resourceId | ||||||
|
|
@@ -78,21 +79,37 @@ if ($resourceIds.Count -gt 0) | |||||
| Write-Host "No health check found for $resourceId at $healthCheckPath" | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| if ($removedHC) | ||||||
| $systemHealthPath = Join-Path "C:\ClusterStorage\Infrastructure_1\Shares\SU1_Infrastructure_1\Updates\HealthCheck" "System" | ||||||
| if (Test-Path $systemHealthPath) | ||||||
| { | ||||||
| $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 | ||||||
| } | ||||||
| else | ||||||
| { | ||||||
| Write-Host "No stale health checks found at $systemHealthPath" | ||||||
| } | ||||||
| } | ||||||
| if ($removedHC) | ||||||
| { | ||||||
| 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" | ||||||
|
||||||
| $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" |
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.
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 -SkipLastis 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).