Files
rdp-proxy/scripts/fabric/c18z109-breadcrumb-freshness-window-smoke.ps1
2026-05-12 21:02:29 +03:00

125 lines
6.7 KiB
PowerShell

param(
[string]$ApiBaseUrl = "http://192.168.200.61:18121/api/v1",
[string]$ClusterID = "cfc0743d-d960-49fb-9de8-96e063d5e4aa",
[string]$ActorUserID = "f67d943f-5397-4b3a-a229-695fe67ad700",
[string]$ExpectedBackendImage = "rap-backend:fabric-service-channel-0.2.281-c18z109",
[string]$DockerSSH = "test-docker",
[string]$ResultPath = "artifacts\c18z109-breadcrumb-freshness-window-smoke-result.json"
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$repoRoot = (Resolve-Path (Join-Path $scriptDir "..\..")).ProviderPath
$runId = "c18z109-" + (Get-Date -Format "yyyyMMdd-HHmmss")
function Invoke-Api {
param([string]$Method, [string]$Path, [object]$Body = $null)
$params = @{ Method = $Method; Uri = "$ApiBaseUrl$Path"; TimeoutSec = 30 }
if ($null -ne $Body) {
$params.ContentType = "application/json"
$params.Body = ($Body | ConvertTo-Json -Depth 60)
}
return Invoke-RestMethod @params
}
function Get-PropertyValue {
param([object]$Item, [string]$Name, [object]$Default = $null)
if ($null -eq $Item) { return $Default }
$property = $Item.PSObject.Properties[$Name]
if ($null -eq $property) { return $Default }
return $property.Value
}
function Find-EventByReason {
param([object[]]$Events, [string]$Reason)
return @($Events | Where-Object { (Get-PropertyValue -Item $_.payload -Name "reason" -Default "") -eq $Reason }) | Select-Object -First 1
}
$checks = [ordered]@{}
$backendImage = (& ssh $DockerSSH "docker inspect rap_test_backend --format '{{.Config.Image}}'").Trim()
$checks.backend_expected_image_deployed = ($backendImage -eq $ExpectedBackendImage)
$health = (Invoke-Api -Method GET -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-health?actor_user_id=$ActorUserID&limit=50").rebuild_health
$breakdown = @($health.feedback_breakdowns | Where-Object {
(Get-PropertyValue -Item $_ -Name "feedback_source" -Default "") -ne "" -and
(Get-PropertyValue -Item $_ -Name "feedback_channel_id" -Default "") -ne "" -and
(Get-PropertyValue -Item $_ -Name "feedback_violation_status" -Default "") -ne ""
}) | Select-Object -First 1
$checks.rebuild_health_has_feedback_breakdown = ($null -ne $breakdown)
if ($null -eq $breakdown) {
$failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key })
throw "C18Z109 breadcrumb freshness smoke failed before breadcrumb audit: $($failed -join ', ')"
}
$reason = "synthetic c18z109 breadcrumb freshness $runId"
Invoke-Api -Method POST -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-incidents/investigations" -Body @{
actor_user_id = $ActorUserID
feedback_source = $breakdown.feedback_source
feedback_channel_id = $breakdown.feedback_channel_id
feedback_violation_status = $breakdown.feedback_violation_status
drilldown_source = "rebuild_health_feedback_breakdown"
reason = $reason
} | Out-Null
$currentPayload = Invoke-Api -Method GET -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-investigations/breadcrumbs?actor_user_id=$ActorUserID&limit=20&current_window_seconds=3600&history_window_seconds=86400"
$currentBreadcrumbs = $currentPayload.rebuild_investigation_breadcrumbs
$currentEvent = Find-EventByReason -Events @($currentBreadcrumbs.events) -Reason $reason
$currentHint = Get-PropertyValue -Item $currentEvent -Name "correlation_hints" -Default $null
$currentCounts = Get-PropertyValue -Item $currentBreadcrumbs.summary -Name "counts_by_breadcrumb_status" -Default $null
Start-Sleep -Seconds 2
$stalePayload = Invoke-Api -Method GET -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-investigations/breadcrumbs?actor_user_id=$ActorUserID&limit=20&current_window_seconds=1&history_window_seconds=86400"
$staleBreadcrumbs = $stalePayload.rebuild_investigation_breadcrumbs
$staleEvent = Find-EventByReason -Events @($staleBreadcrumbs.events) -Reason $reason
$staleHint = Get-PropertyValue -Item $staleEvent -Name "correlation_hints" -Default $null
$staleCounts = Get-PropertyValue -Item $staleBreadcrumbs.summary -Name "counts_by_breadcrumb_status" -Default $null
$expiredPayload = Invoke-Api -Method GET -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-investigations/breadcrumbs?actor_user_id=$ActorUserID&limit=20&current_window_seconds=1&history_window_seconds=1"
$expiredBreadcrumbs = $expiredPayload.rebuild_investigation_breadcrumbs
$expiredEvent = Find-EventByReason -Events @($expiredBreadcrumbs.events) -Reason $reason
$expiredHint = Get-PropertyValue -Item $expiredEvent -Name "correlation_hints" -Default $null
$expiredCounts = Get-PropertyValue -Item $expiredBreadcrumbs.summary -Name "counts_by_breadcrumb_status" -Default $null
$checks.current_event_marked_current = ((Get-PropertyValue -Item $currentHint -Name "breadcrumb_status" -Default "") -eq "current")
$checks.current_summary_counts_current = ((Get-PropertyValue -Item $currentCounts -Name "current" -Default 0) -ge 1)
$checks.stale_event_marked_stale = ((Get-PropertyValue -Item $staleHint -Name "breadcrumb_status" -Default "") -eq "stale")
$checks.stale_summary_counts_stale = ((Get-PropertyValue -Item $staleCounts -Name "stale" -Default 0) -ge 1)
$checks.expired_event_marked_expired = ((Get-PropertyValue -Item $expiredHint -Name "breadcrumb_status" -Default "") -eq "expired")
$checks.expired_summary_counts_expired = ((Get-PropertyValue -Item $expiredCounts -Name "expired" -Default 0) -ge 1)
$checks.window_values_returned = (
(Get-PropertyValue -Item $currentBreadcrumbs -Name "current_window_seconds" -Default 0) -eq 3600 -and
(Get-PropertyValue -Item $currentBreadcrumbs -Name "history_window_seconds" -Default 0) -eq 86400
)
$failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key })
$result = [ordered]@{
schema_version = "c18z109.breadcrumb_freshness_window_smoke.v1"
run_id = $runId
cluster_id = $ClusterID
passed = ($failed.Count -eq 0)
checks = $checks
failed_checks = $failed
summary = [ordered]@{
backend_image = $backendImage
current_event_id = if ($null -ne $currentEvent) { $currentEvent.id } else { $null }
current_status = Get-PropertyValue -Item $currentHint -Name "breadcrumb_status" -Default ""
stale_status = Get-PropertyValue -Item $staleHint -Name "breadcrumb_status" -Default ""
expired_status = Get-PropertyValue -Item $expiredHint -Name "breadcrumb_status" -Default ""
}
}
$target = Join-Path $repoRoot $ResultPath
$result | ConvertTo-Json -Depth 60 | Set-Content -Path $target -Encoding UTF8
if ($failed.Count -gt 0) {
throw "C18Z109 breadcrumb freshness smoke failed: $($failed -join ', ')"
}
Write-Host "C18Z109 breadcrumb freshness smoke passed. Result: $target"
$result