115 lines
5.6 KiB
PowerShell
115 lines
5.6 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\c18z108-dedicated-breadcrumbs-smoke-result.json"
|
|
)
|
|
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$repoRoot = (Resolve-Path (Join-Path $scriptDir "..\..")).ProviderPath
|
|
$runId = "c18z108-" + (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
|
|
}
|
|
|
|
$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 "C18Z108 dedicated breadcrumbs smoke failed before breadcrumb audit: $($failed -join ', ')"
|
|
}
|
|
|
|
$feedbackSource = $breakdown.feedback_source
|
|
$feedbackChannelID = $breakdown.feedback_channel_id
|
|
$feedbackViolationStatus = $breakdown.feedback_violation_status
|
|
$reason = "synthetic c18z108 dedicated breadcrumbs"
|
|
|
|
Invoke-Api -Method POST -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-incidents/investigations" -Body @{
|
|
actor_user_id = $ActorUserID
|
|
feedback_source = $feedbackSource
|
|
feedback_channel_id = $feedbackChannelID
|
|
feedback_violation_status = $feedbackViolationStatus
|
|
drilldown_source = "rebuild_health_feedback_breakdown"
|
|
reason = $reason
|
|
} | Out-Null
|
|
|
|
$payload = Invoke-Api -Method GET -Path "/clusters/$ClusterID/fabric/service-channels/rebuild-investigations/breadcrumbs?actor_user_id=$ActorUserID&limit=20"
|
|
$breadcrumbs = $payload.rebuild_investigation_breadcrumbs
|
|
$events = Get-PropertyValue -Item $breadcrumbs -Name "events" -Default @()
|
|
$summary = Get-PropertyValue -Item $breadcrumbs -Name "summary" -Default $null
|
|
$event = @($events | Where-Object {
|
|
(Get-PropertyValue -Item $_.payload -Name "reason" -Default "") -eq $reason -and
|
|
(Get-PropertyValue -Item $_.payload -Name "feedback_channel_id" -Default "") -eq $feedbackChannelID
|
|
}) | Select-Object -First 1
|
|
$hint = Get-PropertyValue -Item $event -Name "correlation_hints" -Default $null
|
|
$statusCounts = Get-PropertyValue -Item $summary -Name "counts_by_current_diagnostic_status" -Default $null
|
|
$sourceCounts = Get-PropertyValue -Item $summary -Name "counts_by_feedback_source" -Default $null
|
|
$violationCounts = Get-PropertyValue -Item $summary -Name "counts_by_feedback_violation_status" -Default $null
|
|
|
|
$checks.dedicated_breadcrumbs_returned = ($null -ne $breadcrumbs)
|
|
$checks.dedicated_event_found = ($null -ne $event)
|
|
$checks.summary_returned = ($null -ne $summary)
|
|
$checks.summary_total_matches_events = ((Get-PropertyValue -Item $summary -Name "total_count" -Default -1) -eq @($events).Count)
|
|
$checks.summary_counts_breakdown_active = ((Get-PropertyValue -Item $statusCounts -Name "breakdown_active" -Default 0) -ge 1)
|
|
$checks.summary_counts_feedback_source = ((Get-PropertyValue -Item $sourceCounts -Name $feedbackSource -Default 0) -ge 1)
|
|
$checks.summary_counts_feedback_violation = ((Get-PropertyValue -Item $violationCounts -Name $feedbackViolationStatus -Default 0) -ge 1)
|
|
$checks.event_keeps_correlation_hint = ((Get-PropertyValue -Item $hint -Name "current_diagnostic_status" -Default "") -eq "breakdown_active")
|
|
|
|
$failed = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key })
|
|
$result = [ordered]@{
|
|
schema_version = "c18z108.dedicated_breadcrumbs_smoke.v1"
|
|
run_id = $runId
|
|
cluster_id = $ClusterID
|
|
feedback_channel_id = $feedbackChannelID
|
|
passed = ($failed.Count -eq 0)
|
|
checks = $checks
|
|
failed_checks = $failed
|
|
summary = [ordered]@{
|
|
backend_image = $backendImage
|
|
audit_event_id = if ($null -ne $event) { $event.id } else { $null }
|
|
total_count = Get-PropertyValue -Item $summary -Name "total_count" -Default 0
|
|
correlated_count = Get-PropertyValue -Item $summary -Name "correlated_count" -Default 0
|
|
}
|
|
}
|
|
|
|
$target = Join-Path $repoRoot $ResultPath
|
|
$result | ConvertTo-Json -Depth 60 | Set-Content -Path $target -Encoding UTF8
|
|
|
|
if ($failed.Count -gt 0) {
|
|
throw "C18Z108 dedicated breadcrumbs smoke failed: $($failed -join ', ')"
|
|
}
|
|
|
|
Write-Host "C18Z108 dedicated breadcrumbs smoke passed. Result: $target"
|
|
$result
|