enhanced DO collector again

This commit is contained in:
Oliver Kieselbach
2026-04-06 14:06:58 +02:00
parent fda81b8e50
commit e2d011f115
4 changed files with 31 additions and 6 deletions
@@ -36,6 +36,7 @@ namespace AutopilotMonitor.Agent.Core.Monitoring.Collectors
private bool _permanentlyDisabled;
private int _consecutiveErrors;
private volatile bool _dormant = true;
private int _collecting; // concurrency guard (0 = idle, 1 = collecting)
// Track which apps we already sent final do_telemetry for (prevents duplicate callbacks)
private readonly HashSet<string> _enrichedAppIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
@@ -92,6 +93,25 @@ namespace AutopilotMonitor.Agent.Core.Monitoring.Collectors
{
if (_permanentlyDisabled || _dormant) return;
// Concurrency guard: Runspace is not thread-safe. Skip if previous poll is still running.
if (Interlocked.CompareExchange(ref _collecting, 1, 0) != 0)
{
Logger.Debug("[DeliveryOptimizationCollector] Skipping poll — previous invocation still running");
return;
}
try
{
CollectCore();
}
finally
{
Interlocked.Exchange(ref _collecting, 0);
}
}
private void CollectCore()
{
// Guard: check if there's still work to do
var packageStates = _getPackageStates();
if (packageStates == null || packageStates.Count == 0) return;
@@ -325,7 +345,12 @@ namespace AutopilotMonitor.Agent.Core.Monitoring.Collectors
Data = new Dictionary<string, object>
{
["appId"] = appId,
["name"] = pkg.Name,
["appName"] = pkg.Name,
// UI-compatible fields (DownloadProgress.tsx reads these)
["bytesDownloaded"] = totalBytes,
["bytesTotal"] = fileSize,
["progressPercent"] = percentComplete,
// DO-specific fields
["doFileSize"] = fileSize,
["doTotalBytesDownloaded"] = totalBytes,
["doPercentComplete"] = percentComplete,
@@ -110,7 +110,7 @@ namespace AutopilotMonitor.Agent.Core.Monitoring.Core
// Delivery Optimization collector — polls OS-level DO status for peer caching telemetry
if (collectors?.EnableDeliveryOptimizationCollector != false && _enrollmentTracker != null)
{
var doInterval = collectors?.DeliveryOptimizationIntervalSeconds ?? 5;
var doInterval = collectors?.DeliveryOptimizationIntervalSeconds ?? 3;
_deliveryOptimizationCollector = new DeliveryOptimizationCollector(
_configuration.SessionId,
_configuration.TenantId,
@@ -1 +1 @@
854
855
@@ -249,10 +249,10 @@ namespace AutopilotMonitor.Shared.Models
/// <summary>
/// Interval in seconds for polling Get-DeliveryOptimizationStatus.
/// Only polls when active downloads are detected.
/// Default: 5 seconds
/// Only polls when active downloads are detected (dormant otherwise).
/// Default: 3 seconds
/// </summary>
public int DeliveryOptimizationIntervalSeconds { get; set; } = 5;
public int DeliveryOptimizationIntervalSeconds { get; set; } = 3;
/// <summary>
/// Creates default collector configuration