Rapporto di diagnostica della raccolta (#39)
verifica / controlli (push) Successful in 18s
verifica / prove (push) Successful in 13m5s
verifica / installatore (push) Successful in 4m11s
verifica / immagine (push) Successful in 14m4s

Dopo una prova dal vivo andata male, Alberto deve poter mandare un solo file che
spieghi perché, senza che nessuno veda dati di altre persone. Attività ha ora il
pulsante «Diagnostica», che scarica il rapporto delle sessioni degli ultimi 14 giorni:
pagine aperte e forma degli indirizzi, risposte per tipo, stato e dimensione con ciò
che i lettori ne hanno fatto, struttura stretta delle forme sconosciute, ricette,
segnali, permessi negati, file in coda e scaricati, e il motivo di ogni arresto.

Nel rapporto entrano solo valori da elenchi chiusi, numeri, orari e forme: mai nomi,
indirizzi completi, codici, cursori, cookie o pezzi di risposte. Le forme degli
indirizzi e la regola delle chiavi-dato passano dalla sonda a Core, e la sonda le
richiama. Il registratore non lancia mai eccezioni verso la raccolta e tiene i file in
Dati/diagnostica per 14 giorni.

Prova che il rapporto non contiene valori, con controlli di mutazione; tre giri di
revisione avversaria (25 difetti confermati, tutti corretti).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-13 14:41:34 +01:00
1 parent bf03cb45a5
commit badd1681a0
55 files changed
+5395 -134

No files matched your search

+43 -15
View File
@@ -198,7 +198,7 @@ public sealed class ResponseTap : IAsyncDisposable
{
if (_inFlight.TryRemove(key, out _))
{
NotifyDropped(key);
NotifyDropped(key, BodyDropReason.Reconnected);
}
}
@@ -273,17 +273,22 @@ public sealed class ResponseTap : IAsyncDisposable
private void OnLoadingFinished(JsonElement p)
{
if (!p.TryGetProperty("requestId", out var idElement) || idElement.GetString() is not { } requestId
|| !_inFlight.TryRemove(requestId, out var pending))
if (!p.TryGetProperty("requestId", out var idElement) || idElement.GetString() is not { } requestId)
{
return;
}
var length = p.TryGetProperty("encodedDataLength", out var len) && len.TryGetDouble(out var d) ? d : 0;
NotifyLoadingFinished(requestId, length);
if (!_inFlight.TryRemove(requestId, out var pending))
{
return;
}
if (length > _options.MaxBodyBytes)
{
Interlocked.Increment(ref _skipped);
NotifyDropped(requestId);
NotifyDropped(requestId, BodyDropReason.TooLarge);
return;
}
@@ -295,7 +300,7 @@ public sealed class ResponseTap : IAsyncDisposable
if (p.TryGetProperty("requestId", out var idElement) && idElement.GetString() is { } requestId
&& _inFlight.TryRemove(requestId, out _))
{
NotifyDropped(requestId);
NotifyDropped(requestId, BodyDropReason.LoadingFailed);
}
}
@@ -318,7 +323,7 @@ public sealed class ResponseTap : IAsyncDisposable
{
if (key != loader && _inFlight.TryRemove(key, out _))
{
NotifyDropped(key);
NotifyDropped(key, BodyDropReason.FrameNavigated);
}
}
Publish(frame.TryGetProperty("url", out var u) ? u.GetString() : null, sameDocument: false);
@@ -373,7 +378,7 @@ public sealed class ResponseTap : IAsyncDisposable
// One unexpected body must not stop the capture of the following ones. Only the type: the message
// of a parsing error may quote the body.
_log.Warn($"Cattura: errore imprevisto nella lettura di una risposta ({ex.GetType().Name}).");
NotifyDropped(pending.Descriptor.RequestId);
NotifyDropped(pending.Descriptor.RequestId, BodyDropReason.Unexpected);
}
}
}
@@ -394,7 +399,7 @@ public sealed class ResponseTap : IAsyncDisposable
if (consumers.Length == 0)
{
NotifyDropped(descriptor.RequestId);
NotifyDropped(descriptor.RequestId, BodyDropReason.NoConsumers);
return;
}
@@ -408,16 +413,22 @@ public sealed class ResponseTap : IAsyncDisposable
// The body may already be evicted from the browser's buffer, or the page navigated away.
Interlocked.Increment(ref _bodyErrors);
_log.Debug($"Cattura: corpo non disponibile ({ex.GetType().Name}).");
NotifyDropped(descriptor.RequestId);
NotifyDropped(descriptor.RequestId, ex is TimeoutException ? BodyDropReason.Timeout : BodyDropReason.Unavailable);
return;
}
var delivered = bytes is null ? 0
: pending.IsPageDocument ? await ConsumeDocumentAsync(descriptor, bytes, consumers, ct).ConfigureAwait(false)
if (bytes is null)
{
NotifyDropped(descriptor.RequestId, BodyDropReason.Unavailable);
return;
}
var delivered = pending.IsPageDocument
? await ConsumeDocumentAsync(descriptor, bytes, consumers, ct).ConfigureAwait(false)
: await ConsumeBodyAsync(descriptor, bytes, consumers, ct).ConfigureAwait(false);
if (delivered == 0)
{
NotifyDropped(descriptor.RequestId);
NotifyDropped(descriptor.RequestId, pending.IsPageDocument ? BodyDropReason.NoJsonBlock : BodyDropReason.NotJson);
}
}
@@ -515,14 +526,31 @@ public sealed class ResponseTap : IAsyncDisposable
return decoded;
}
/// <summary>Tells the observers that a body they may be waiting for will not come.</summary>
private void NotifyDropped(string requestId)
/// <summary>Tells the observers that a body they may be waiting for will not come, and why.</summary>
private void NotifyDropped(string requestId, BodyDropReason reason)
{
foreach (var observer in SnapshotObservers())
{
try
{
observer.OnBodyDropped(requestId);
observer.OnBodyDropped(requestId, reason);
}
catch (Exception ex)
{
_log.Warn("Cattura: errore in un osservatore delle risposte.", ex);
}
}
}
/// <summary>Tells the observers how many bytes a response took on the network (every response, read or not).</summary>
private void NotifyLoadingFinished(string requestId, double encodedBytes)
{
var bytes = encodedBytes is > 0 and < long.MaxValue ? (long)encodedBytes : 0;
foreach (var observer in SnapshotObservers())
{
try
{
observer.OnLoadingFinished(requestId, bytes);
}
catch (Exception ex)
{
+27 -1
View File
@@ -5,6 +5,7 @@ using Febe.Browser.Hosting;
using Febe.Browser.Targets;
using Febe.Core.Abstractions;
using Febe.Core.Collection;
using Febe.Core.Collection.Diagnostics;
using Febe.Core.Collection.Downloads;
using Febe.Core.Collection.Readers;
using Febe.Core.Collection.Recipes;
@@ -84,6 +85,12 @@ public sealed record CollectionPipelineOptions
public Func<bool>? UserOwnsPage { get; init; }
public IBrowserLog? Log { get; init; }
/// <summary>
/// The recorder of the diagnostic report (issue #39): it observes the responses of the page, the readers, the
/// recipes, the stop signals and the download queue. Null: nothing is recorded.
/// </summary>
public CollectionDiagnostics? Diagnostics { get; init; }
}
/// <summary>
@@ -138,7 +145,8 @@ public sealed class CollectionPipeline : IAsyncDisposable
var tap = new ResponseTap(options.Cdp, site.Hosts, options.Clock, options.Log);
var signals = new SignalDetector(rules, options.Breaker, options.Clock) { UserOwnsPage = options.UserOwnsPage };
var capture = new CaptureCollector(new ShapeReader(vocabulary), options.Clock);
var diagnostics = options.Diagnostics;
var capture = new CaptureCollector(new ShapeReader(vocabulary), options.Clock) { Diagnostics = diagnostics };
var driver = new BrowserPageDriver(options.Cdp, targets, site.Hosts, options.Clock, options.Random, new BrowserDriverOptions
{
SiteBaseUrl = site.BaseUrl,
@@ -160,6 +168,7 @@ public sealed class CollectionPipeline : IAsyncDisposable
DataBudget = options.DataBudget,
Breaker = options.Breaker,
Options = options.Recipes,
Diagnostics = diagnostics,
});
var downloads = new DownloadQueue(
options.Storage,
@@ -176,6 +185,18 @@ public sealed class CollectionPipeline : IAsyncDisposable
pipeline._subscriptions.Add(tap.AddConsumer(signals));
pipeline._subscriptions.Add(tap.AddObserver(capture));
pipeline._subscriptions.Add(tap.AddConsumer(capture));
if (diagnostics is not null)
{
diagnostics.SiteMap = siteMap;
pipeline._subscriptions.Add(tap.AddObserver(diagnostics));
EventHandler<Signal> signalRaised = (_, signal) => diagnostics.SignalRaised(signal);
signals.SignalRaised += signalRaised;
pipeline._subscriptions.Add(new Unsubscribe(() => signals.SignalRaised -= signalRaised));
EventHandler<DownloadProgress> progress = (_, step) => diagnostics.DownloadSettled(step);
downloads.Progress += progress;
pipeline._subscriptions.Add(new Unsubscribe(() => downloads.Progress -= progress));
}
await tap.StartAsync(ct).ConfigureAwait(false);
return pipeline;
}
@@ -189,4 +210,9 @@ public sealed class CollectionPipeline : IAsyncDisposable
await Tap.DisposeAsync().ConfigureAwait(false);
}
private sealed class Unsubscribe(Action action) : IDisposable
{
public void Dispose() => action();
}
}