Files
rdp-proxy/scripts/fabric/c19l-remote-workspace-adapter-session-lifecycle-smoke.ps1
T
2026-05-12 21:02:29 +03:00

166 lines
8.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]$EntryNodeName = "test-1",
[string]$ExitNodeName = "test-2",
[string]$EntryBaseUrl = "http://192.168.200.61:19131",
[string]$ResultPath = "artifacts\c19l-remote-workspace-adapter-session-lifecycle-smoke-result.json"
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).ProviderPath
$sourceResultPath = "artifacts\c19l-remote-workspace-adapter-session-source-result.json"
function Invoke-Api {
param([string]$Method, [string]$Path, [object]$Body = $null)
$uri = "$ApiBaseUrl$Path"
if ($null -eq $Body) { return Invoke-RestMethod -Method $Method -Uri $uri -TimeoutSec 30 }
return Invoke-RestMethod -Method $Method -Uri $uri -ContentType "application/json" -Body ($Body | ConvertTo-Json -Depth 80) -TimeoutSec 30
}
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 Get-NodeByName {
param([string]$Name)
$nodes = (Invoke-Api -Method GET -Path "/clusters/$ClusterID/nodes?actor_user_id=$ActorUserID").nodes
$node = @($nodes | Where-Object { $_.name -eq $Name }) | Select-Object -First 1
if ($null -eq $node) { throw "Node '$Name' was not found in cluster $ClusterID" }
return $node
}
function Get-RemoteWorkspaceSinkReports {
param([string]$NodeID)
$workloadStatus = $null
$workloadSink = $null
$telemetry = $null
$telemetrySink = $null
$statuses = (Invoke-Api -Method GET -Path "/clusters/$ClusterID/nodes/$NodeID/workloads/status?actor_user_id=$ActorUserID").workload_statuses
$workloadStatus = @($statuses | Where-Object { $_.service_type -eq "rdp-worker" } | Select-Object -First 1)
if ($null -ne $workloadStatus) {
$workloadSink = Get-PropertyValue -Item $workloadStatus.status_payload -Name "remote_workspace_adapter_sink" -Default $null
}
$telemetryItems = @((Invoke-Api -Method GET -Path "/clusters/$ClusterID/nodes/$NodeID/telemetry?actor_user_id=$ActorUserID&limit=10").telemetry)
$telemetry = $telemetryItems | Select-Object -First 1
if ($null -ne $telemetry) {
$telemetryPayload = Get-PropertyValue -Item $telemetry -Name "payload" -Default $null
$telemetrySink = Get-PropertyValue -Item $telemetryPayload -Name "remote_workspace_adapter_sink_report" -Default $null
}
return [ordered]@{
workload_status = $workloadStatus
workload_sink = $workloadSink
telemetry = $telemetry
telemetry_sink = $telemetrySink
}
}
function Test-LifecycleReport {
param(
[object]$Sink,
[string]$AdapterSessionID,
[int64]$BaselineCreated,
[int64]$BaselineBound,
[int64]$BaselineBackpressure
)
if ($null -eq $Sink) { return $false }
return (
[string](Get-PropertyValue -Item $Sink -Name "current_adapter_session_id" -Default "") -eq $AdapterSessionID -and
[string](Get-PropertyValue -Item $Sink -Name "current_session_lifecycle_state" -Default "") -eq "backpressure" -and
[int64](Get-PropertyValue -Item $Sink -Name "current_session_delivery_count" -Default 0) -ge 1 -and
[int64](Get-PropertyValue -Item $Sink -Name "current_session_backpressure_count" -Default 0) -ge 1 -and
[int64](Get-PropertyValue -Item $Sink -Name "current_session_dropped_frames" -Default 0) -ge 3 -and
[int64](Get-PropertyValue -Item $Sink -Name "active_session_count" -Default 0) -ge 1 -and
[int64](Get-PropertyValue -Item $Sink -Name "session_created_total" -Default 0) -ge ($BaselineCreated + 1) -and
[int64](Get-PropertyValue -Item $Sink -Name "session_bound_total" -Default 0) -ge ($BaselineBound + 1) -and
[int64](Get-PropertyValue -Item $Sink -Name "session_backpressure_total" -Default 0) -ge ($BaselineBackpressure + 1) -and
[int64](Get-PropertyValue -Item $Sink -Name "session_ttl_seconds" -Default 0) -gt 0 -and
[string](Get-PropertyValue -Item $Sink -Name "current_session_created_at" -Default "") -match "T" -and
[string](Get-PropertyValue -Item $Sink -Name "current_session_bound_at" -Default "") -match "T" -and
[string](Get-PropertyValue -Item $Sink -Name "current_session_last_activity_at" -Default "") -match "T"
)
}
$entryNode = Get-NodeByName -Name $EntryNodeName
$baseline = Get-RemoteWorkspaceSinkReports -NodeID $entryNode.id
$baselineSink = if ($null -ne $baseline.workload_sink) { $baseline.workload_sink } else { $baseline.telemetry_sink }
$baselineCreated = [int64](Get-PropertyValue -Item $baselineSink -Name "session_created_total" -Default 0)
$baselineBound = [int64](Get-PropertyValue -Item $baselineSink -Name "session_bound_total" -Default 0)
$baselineBackpressure = [int64](Get-PropertyValue -Item $baselineSink -Name "session_backpressure_total" -Default 0)
$source = & powershell -ExecutionPolicy Bypass -File (Join-Path $PSScriptRoot "c19i-remote-workspace-adapter-queue-smoke.ps1") `
-ApiBaseUrl $ApiBaseUrl `
-ClusterID $ClusterID `
-ActorUserID $ActorUserID `
-EntryNodeName $EntryNodeName `
-ExitNodeName $ExitNodeName `
-EntryBaseUrl $EntryBaseUrl `
-ResultPath $sourceResultPath
$sourceFile = Join-Path $repoRoot $sourceResultPath
$sourceResult = Get-Content -Raw -Path $sourceFile | ConvertFrom-Json
$ingressBody = $sourceResult.droppable_overflow.body
$delivery = $ingressBody.adapter_delivery
$adapterSessionID = [string](Get-PropertyValue -Item $ingressBody -Name "adapter_session_id" -Default "")
$observed = $null
$deadline = (Get-Date).AddSeconds(90)
while ((Get-Date) -lt $deadline) {
Start-Sleep -Seconds 5
$observed = Get-RemoteWorkspaceSinkReports -NodeID $entryNode.id
if (
(Test-LifecycleReport -Sink $observed.workload_sink -AdapterSessionID $adapterSessionID -BaselineCreated $baselineCreated -BaselineBound $baselineBound -BaselineBackpressure $baselineBackpressure) -and
(Test-LifecycleReport -Sink $observed.telemetry_sink -AdapterSessionID $adapterSessionID -BaselineCreated $baselineCreated -BaselineBound $baselineBound -BaselineBackpressure $baselineBackpressure)
) {
break
}
}
if ($null -eq $observed) {
$observed = Get-RemoteWorkspaceSinkReports -NodeID $entryNode.id
}
$checks = [ordered]@{
source_smoke_passed = ([bool]$sourceResult.passed)
receipt_session_lifecycle_probe_bound = ([string](Get-PropertyValue -Item $delivery -Name "session_lifecycle_state" -Default "") -eq "probe_bound")
receipt_session_created_at_present = ([string](Get-PropertyValue -Item $delivery -Name "session_created_at" -Default "") -match "T")
receipt_session_bound_at_present = ([string](Get-PropertyValue -Item $delivery -Name "session_bound_at" -Default "") -match "T")
receipt_session_activity_present = ([string](Get-PropertyValue -Item $delivery -Name "session_last_activity_at" -Default "") -match "T")
receipt_session_delivery_count = ([int64](Get-PropertyValue -Item $delivery -Name "session_delivery_count" -Default 0) -ge 1)
workload_lifecycle_visible = (Test-LifecycleReport -Sink $observed.workload_sink -AdapterSessionID $adapterSessionID -BaselineCreated $baselineCreated -BaselineBound $baselineBound -BaselineBackpressure $baselineBackpressure)
telemetry_lifecycle_visible = (Test-LifecycleReport -Sink $observed.telemetry_sink -AdapterSessionID $adapterSessionID -BaselineCreated $baselineCreated -BaselineBound $baselineBound -BaselineBackpressure $baselineBackpressure)
}
$failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key })
$result = [ordered]@{
schema_version = "c19l.remote_workspace_adapter_session_lifecycle_smoke.v1"
source_result_path = $sourceFile
cluster_id = $ClusterID
entry_node = [ordered]@{ id = $entryNode.id; name = $entryNode.name }
adapter_session_id = $adapterSessionID
baseline = $baseline
delivery = $delivery
observed = $observed
checks = $checks
failed_checks = $failed
passed = ($failed.Count -eq 0)
}
$fullResultPath = Join-Path $repoRoot $ResultPath
$resultDir = Split-Path -Parent $fullResultPath
if ($resultDir) { New-Item -ItemType Directory -Force -Path $resultDir | Out-Null }
$result | ConvertTo-Json -Depth 100 | Set-Content -Encoding UTF8 -Path $fullResultPath
if (-not $result.passed) {
throw "C19L remote workspace adapter session lifecycle smoke failed. Result: $fullResultPath Failed: $($failed -join ', ')"
}
Write-Host "C19L remote workspace adapter session lifecycle smoke passed. Result: $fullResultPath"
$result