fix(telemetry): restore worker agent delivery and truthful system status
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$ContainerName = "ndc-mission-core-perception-worker",
|
||||
[string]$HealthUrl = "http://127.0.0.1:18020/health"
|
||||
[string]$HealthUrl = "http://127.0.0.1:18020/health",
|
||||
[string]$RuntimeSnapshot = "C:\ProgramData\NDC\MissionCore\telemetry-agent\perception\current.json"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
@@ -18,6 +19,46 @@ $stageIds = @(
|
||||
)
|
||||
$health = $null
|
||||
$collectorState = "unavailable"
|
||||
# A fresh full-profile export supersedes the historical service. Presence of an
|
||||
# expired/broken export is NOT permission to relabel a legacy model as current.
|
||||
if (Test-Path -LiteralPath $RuntimeSnapshot -PathType Leaf) {
|
||||
$runtime = $null
|
||||
try {
|
||||
$item = Get-Item -LiteralPath $RuntimeSnapshot
|
||||
$age = ([DateTime]::UtcNow - $item.LastWriteTimeUtc).TotalSeconds
|
||||
if ($item.Length -le 8192 -and $age -ge -1 -and $age -le 5) {
|
||||
$stream = [IO.File]::Open($RuntimeSnapshot, 'Open', 'Read', 'ReadWrite')
|
||||
try {
|
||||
$bytes = New-Object byte[] 8193
|
||||
$count = $stream.Read($bytes, 0, $bytes.Length)
|
||||
if ($count -le 8192) {
|
||||
$runtime = [Text.Encoding]::UTF8.GetString($bytes, 0, $count) | ConvertFrom-Json
|
||||
}
|
||||
} finally { $stream.Dispose() }
|
||||
if ($runtime.schema_version -ne 'missioncore.perception-runtime-observation/v1') {
|
||||
$runtime = $null
|
||||
}
|
||||
}
|
||||
} catch { $runtime = $null }
|
||||
$samples = foreach ($stageId in $stageIds) {
|
||||
$sample = [ordered]@{
|
||||
stage_id = $stageId
|
||||
stage_state = 'unavailable'
|
||||
service_state = 'unavailable'
|
||||
collector_state = 'unavailable'
|
||||
}
|
||||
if ($runtime) {
|
||||
$sample.collector_state = 'live'
|
||||
foreach ($name in @('service_state', 'profile_name', 'active_request_id',
|
||||
'input_state', 'wait_reason', 'live_children', 'input_pauses', 'pending_bundles', 'buffer_bytes')) {
|
||||
$sample[$name] = $runtime.$name
|
||||
}
|
||||
}
|
||||
[pscustomobject]$sample
|
||||
}
|
||||
@($samples) | ConvertTo-Json -Compress -Depth 4
|
||||
exit 0
|
||||
}
|
||||
try {
|
||||
$healthJson = docker exec $ContainerName python3 -c `
|
||||
"import urllib.request;print(urllib.request.urlopen('$HealthUrl',timeout=2).read().decode())" `
|
||||
@@ -68,13 +109,13 @@ $completedRuns = if ($health -and $null -ne $health.completed_runs) {
|
||||
[int64]$health.completed_runs
|
||||
}
|
||||
else {
|
||||
[int64]0
|
||||
[int64]-1
|
||||
}
|
||||
$failedRuns = if ($health -and $null -ne $health.failed_runs) {
|
||||
[int64]$health.failed_runs
|
||||
}
|
||||
else {
|
||||
[int64]0
|
||||
[int64]-1
|
||||
}
|
||||
$modelLoadSeconds = if ($health -and $null -ne $health.model_load_seconds) {
|
||||
[double]$health.model_load_seconds
|
||||
|
||||
Reference in New Issue
Block a user