Files
rdp-proxy/scripts/fabric/c19y-remote-workspace-mailbox-resume-telemetry-smoke.ps1
2026-05-12 21:02:29 +03:00

170 lines
9.1 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\c19y-remote-workspace-mailbox-resume-telemetry-smoke-result.json"
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).ProviderPath
$sourceResultPath = "artifacts\c19y-remote-workspace-mailbox-resume-source-result.json"
$consumerID = "rdp-worker-probe"
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-ResumeTelemetryReport {
param(
[object]$Sink,
[object]$BaselineSink,
[string]$AdapterSessionID,
[int64]$ResumeSequence,
[int]$SkippedCount,
[int]$ReturnedCount
)
if ($null -eq $Sink) { return $false }
$baselineResume = [int64](Get-PropertyValue -Item $BaselineSink -Name "mailbox_resume_read_total" -Default 0)
$baselineAfter = [int64](Get-PropertyValue -Item $BaselineSink -Name "mailbox_after_sequence_read_total" -Default 0)
$baselineReturned = [int64](Get-PropertyValue -Item $BaselineSink -Name "mailbox_returned_total" -Default 0)
$baselineSkipped = [int64](Get-PropertyValue -Item $BaselineSink -Name "mailbox_skipped_total" -Default 0)
return (
[string](Get-PropertyValue -Item $Sink -Name "schema_version" -Default "") -eq "rap.remote_workspace_adapter_sink_report.v1" -and
[string](Get-PropertyValue -Item $Sink -Name "payload_traffic" -Default "") -eq "none" -and
[int64](Get-PropertyValue -Item $Sink -Name "mailbox_resume_read_total" -Default 0) -ge ($baselineResume + 2) -and
[int64](Get-PropertyValue -Item $Sink -Name "mailbox_after_sequence_read_total" -Default 0) -ge ($baselineAfter + 2) -and
[int64](Get-PropertyValue -Item $Sink -Name "mailbox_returned_total" -Default 0) -ge ($baselineReturned + 8) -and
[int64](Get-PropertyValue -Item $Sink -Name "mailbox_skipped_total" -Default 0) -ge ($baselineSkipped + 3) -and
[string](Get-PropertyValue -Item $Sink -Name "last_mailbox_adapter_session_id" -Default "") -eq $AdapterSessionID -and
[string](Get-PropertyValue -Item $Sink -Name "last_mailbox_resume_from" -Default "") -eq "ack" -and
[int64](Get-PropertyValue -Item $Sink -Name "last_mailbox_resume_sequence" -Default -1) -eq $ResumeSequence -and
[string](Get-PropertyValue -Item $Sink -Name "last_mailbox_resume_consumer_id" -Default "") -eq $consumerID -and
[int64](Get-PropertyValue -Item $Sink -Name "last_mailbox_after_sequence" -Default -1) -eq $ResumeSequence -and
[int](Get-PropertyValue -Item $Sink -Name "last_mailbox_skipped_count" -Default -1) -eq $SkippedCount -and
[int](Get-PropertyValue -Item $Sink -Name "last_mailbox_returned_count" -Default -1) -eq $ReturnedCount
)
}
$entryNode = Get-NodeByName -Name $EntryNodeName
$baseline = Get-RemoteWorkspaceSinkReports -NodeID $entryNode.id
$baselineWorkloadSink = $baseline.workload_sink
$baselineTelemetrySink = $baseline.telemetry_sink
$source = & powershell -ExecutionPolicy Bypass -File (Join-Path $PSScriptRoot "c19x-remote-workspace-mailbox-consumer-resume-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
$adapterSessionID = [string](Get-PropertyValue -Item $sourceResult -Name "adapter_session_id" -Default "")
$resumeAck = Get-PropertyValue -Item $sourceResult -Name "resume_ack" -Default $null
$resumeAckJson = Get-PropertyValue -Item $resumeAck -Name "json" -Default $null
$resumeSequence = [int64](Get-PropertyValue -Item $resumeAckJson -Name "resume_sequence" -Default 0)
$skippedCount = [int](Get-PropertyValue -Item $resumeAckJson -Name "skipped_count" -Default 0)
$returnedCount = [int](Get-PropertyValue -Item $resumeAckJson -Name "returned_count" -Default 0)
$observed = $null
$deadline = (Get-Date).AddSeconds(90)
while ((Get-Date) -lt $deadline) {
Start-Sleep -Seconds 5
$observed = Get-RemoteWorkspaceSinkReports -NodeID $entryNode.id
if (
(Test-ResumeTelemetryReport -Sink $observed.workload_sink -BaselineSink $baselineWorkloadSink -AdapterSessionID $adapterSessionID -ResumeSequence $resumeSequence -SkippedCount $skippedCount -ReturnedCount $returnedCount) -and
(Test-ResumeTelemetryReport -Sink $observed.telemetry_sink -BaselineSink $baselineTelemetrySink -AdapterSessionID $adapterSessionID -ResumeSequence $resumeSequence -SkippedCount $skippedCount -ReturnedCount $returnedCount)
) {
break
}
}
if ($null -eq $observed) {
$observed = Get-RemoteWorkspaceSinkReports -NodeID $entryNode.id
}
$checks = [ordered]@{
source_smoke_passed = ([bool]$sourceResult.passed)
adapter_session_id_present = ($adapterSessionID -match "^rap-rw-adapter-session-[0-9a-f]{24}$")
resume_ack_shape_visible = ([string](Get-PropertyValue -Item $resumeAckJson -Name "resume_from" -Default "") -eq "ack" -and $resumeSequence -gt 0 -and $skippedCount -eq 1 -and $returnedCount -eq 2)
workload_resume_telemetry_visible = (Test-ResumeTelemetryReport -Sink $observed.workload_sink -BaselineSink $baselineWorkloadSink -AdapterSessionID $adapterSessionID -ResumeSequence $resumeSequence -SkippedCount $skippedCount -ReturnedCount $returnedCount)
telemetry_resume_telemetry_visible = (Test-ResumeTelemetryReport -Sink $observed.telemetry_sink -BaselineSink $baselineTelemetrySink -AdapterSessionID $adapterSessionID -ResumeSequence $resumeSequence -SkippedCount $skippedCount -ReturnedCount $returnedCount)
}
$failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key })
$result = [ordered]@{
schema_version = "c19y.remote_workspace_mailbox_resume_telemetry_smoke.v1"
source_result_path = $sourceFile
cluster_id = $ClusterID
entry_node = [ordered]@{ id = $entryNode.id; name = $entryNode.name }
adapter_session_id = $adapterSessionID
baseline = $baseline
source = $sourceResult
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 "C19Y remote workspace mailbox resume telemetry smoke failed. Result: $fullResultPath Failed: $($failed -join ', ')"
}
Write-Host "C19Y remote workspace mailbox resume telemetry smoke passed. Result: $fullResultPath"
$result