Rapporto di diagnostica della raccolta (#39)
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:
1 parent
bf03cb45a5
commit
badd1681a0
55 files changed
+5395
-134
No files matched your search
@@ -353,6 +353,7 @@ public sealed class DownloadQueue
|
||||
{
|
||||
await _storage.Media.MarkFailedAsync(media.Id, MediaState.Failed, "Indirizzo del file non valido.", _clock.Now, ct).ConfigureAwait(false);
|
||||
tally.Add(ref tally.Failed);
|
||||
Report(media, entry, DownloadStep.Failed, cause: DownloadCauses.BadAddress);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -382,33 +383,35 @@ public sealed class DownloadQueue
|
||||
switch (result.Outcome)
|
||||
{
|
||||
case FetchOutcome.Completed:
|
||||
await IngestAsync(account, entry, media, temp, maxBytes, tally, ct).ConfigureAwait(false);
|
||||
await IngestAsync(account, entry, media, temp, maxBytes, result.BudgetBytes, tally, ct).ConfigureAwait(false);
|
||||
return;
|
||||
case FetchOutcome.TooLarge:
|
||||
var limit = maxBytes is { } m ? ItalianText.Number(Math.Max(1, m / (1024 * 1024))) : "?";
|
||||
await _storage.Media.MarkFailedAsync(media.Id, MediaState.Skipped, $"Video oltre il limite di {limit} MB impostato per l'account.", _clock.Now, ct).ConfigureAwait(false);
|
||||
_retryAt.TryRemove(media.Id, out _);
|
||||
tally.Add(ref tally.Skipped);
|
||||
Report(media, entry, DownloadStep.Skipped);
|
||||
Report(media, entry, DownloadStep.Skipped, result.BudgetBytes);
|
||||
return;
|
||||
case FetchOutcome.HttpError when result.HttpStatus is { } status && _options.ExpiredStatuses.Contains(status):
|
||||
await ExpiredAsync(entry, media, tally, singlePostQueued, ct).ConfigureAwait(false);
|
||||
await ExpiredAsync(entry, media, tally, singlePostQueued, result.BudgetBytes, ct).ConfigureAwait(false);
|
||||
return;
|
||||
case FetchOutcome.HostNotAllowed:
|
||||
await _storage.Media.MarkFailedAsync(media.Id, MediaState.Failed, "L'indirizzo non è del CDN: non si scarica (specifica §6.5).", _clock.Now, ct).ConfigureAwait(false);
|
||||
_retryAt.TryRemove(media.Id, out _);
|
||||
tally.Add(ref tally.Failed);
|
||||
Report(media, entry, DownloadStep.Failed);
|
||||
Report(media, entry, DownloadStep.Failed, result.BudgetBytes, DownloadCauses.HostNotAllowed);
|
||||
return;
|
||||
case FetchOutcome.NetworkError when IsConnectionError(result.Error):
|
||||
// No connection at all (router restarting, cable out): every file would fail the same way.
|
||||
// No connection at all (router restarting, cable out): every file would fail the same way. Not the
|
||||
// file's fault (no attempt counted), but the report says why it is still waiting.
|
||||
PauseUntil(_clock.Now + _options.ConnectionPause, tally);
|
||||
Report(media, entry, DownloadStep.Retried, result.BudgetBytes, DownloadCauses.Connection);
|
||||
return;
|
||||
default:
|
||||
var error = result.HttpStatus is { } code
|
||||
? $"Il CDN ha risposto {code.ToString(CultureInfo.InvariantCulture)}."
|
||||
: $"Errore di rete durante lo scaricamento ({result.Error ?? "senza dettagli"}).";
|
||||
await RetryLaterAsync(entry, media, error, tally, ct).ConfigureAwait(false);
|
||||
await RetryLaterAsync(entry, media, error, tally, result.BudgetBytes, ct, DownloadCauses.Of(result.HttpStatus)).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -421,11 +424,12 @@ public sealed class DownloadQueue
|
||||
{
|
||||
await _storage.Media.MarkFailedAsync(media.Id, MediaState.Skipped, "Video oltre il limite impostato per l'account.", _clock.Now, CancellationToken.None).ConfigureAwait(false);
|
||||
tally.Add(ref tally.Skipped);
|
||||
Report(media, entry, DownloadStep.Skipped);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
// Disk full or similar: the file waits for a later pass (nothing was written under the final name).
|
||||
await RetryLaterAsync(entry, media, $"Scrittura non riuscita: {ex.GetType().Name}.", tally, CancellationToken.None).ConfigureAwait(false);
|
||||
await RetryLaterAsync(entry, media, $"Scrittura non riuscita: {ex.GetType().Name}.", tally, null, CancellationToken.None, DownloadCauses.Write).ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -455,14 +459,14 @@ public sealed class DownloadQueue
|
||||
/// A failure that may pass: the file waits for a later attempt, a little longer each time; after
|
||||
/// <see cref="DownloadOptions.MaxAttempts"/> failures it is «fallito».
|
||||
/// </summary>
|
||||
private async Task RetryLaterAsync(Entry entry, Media media, string error, Tally tally, CancellationToken ct)
|
||||
private async Task RetryLaterAsync(Entry entry, Media media, string error, Tally tally, long? bytes, CancellationToken ct, string? cause = null)
|
||||
{
|
||||
if (media.Attempts + 1 >= _options.MaxAttempts)
|
||||
{
|
||||
await _storage.Media.MarkFailedAsync(media.Id, MediaState.Failed, error, _clock.Now, ct).ConfigureAwait(false);
|
||||
_retryAt.TryRemove(media.Id, out _);
|
||||
tally.Add(ref tally.Failed);
|
||||
Report(media, entry, DownloadStep.Failed);
|
||||
Report(media, entry, DownloadStep.Failed, bytes, cause);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -474,10 +478,12 @@ public sealed class DownloadQueue
|
||||
}
|
||||
|
||||
tally.Add(ref tally.Retried);
|
||||
Report(media, entry, DownloadStep.Retried, bytes, cause);
|
||||
}
|
||||
|
||||
private async Task IngestAsync(Account account, Entry entry, Media media, string temp, long? maxBytes, Tally tally, CancellationToken ct)
|
||||
private async Task IngestAsync(Account account, Entry entry, Media media, string temp, long? maxBytes, long fileBytes, Tally tally, CancellationToken ct)
|
||||
{
|
||||
var bytes = fileBytes;
|
||||
MemoryStream? cover = null;
|
||||
try
|
||||
{
|
||||
@@ -489,6 +495,7 @@ public sealed class DownloadQueue
|
||||
{
|
||||
await _budget.RecordAsync(fetched.BudgetBytes, account.Id, CancellationToken.None).ConfigureAwait(false);
|
||||
tally.AddBytes(fetched.BudgetBytes);
|
||||
bytes += fetched.BudgetBytes;
|
||||
}
|
||||
|
||||
if (fetched.Outcome == FetchOutcome.HttpError && fetched.HttpStatus is { } status)
|
||||
@@ -526,13 +533,13 @@ public sealed class DownloadQueue
|
||||
if (saved.Outcome == MediaSaveOutcome.Stored)
|
||||
{
|
||||
tally.Add(ref tally.Stored);
|
||||
Report(media, entry, DownloadStep.Stored);
|
||||
Report(media, entry, DownloadStep.Stored, bytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
await IdenticalAsync(entry, media, saved.Identical!, ct).ConfigureAwait(false);
|
||||
tally.Add(ref tally.Duplicates);
|
||||
Report(media, entry, DownloadStep.Duplicate);
|
||||
Report(media, entry, DownloadStep.Duplicate, bytes);
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -582,7 +589,7 @@ public sealed class DownloadQueue
|
||||
/// A file whose renewed address is refused again and again ends «fallito» after
|
||||
/// <see cref="DownloadOptions.MaxAttempts"/> failures, instead of sending «Post singolo» to the site for ever.
|
||||
/// </summary>
|
||||
private async Task ExpiredAsync(Entry entry, Media media, Tally tally, ConcurrentDictionary<long, bool> singlePostQueued, CancellationToken ct)
|
||||
private async Task ExpiredAsync(Entry entry, Media media, Tally tally, ConcurrentDictionary<long, bool> singlePostQueued, long? bytes, CancellationToken ct)
|
||||
{
|
||||
_retryAt.TryRemove(media.Id, out _);
|
||||
if (entry.Kind != EntryKind.Story && media.Attempts + 1 >= _options.MaxAttempts)
|
||||
@@ -590,7 +597,7 @@ public sealed class DownloadQueue
|
||||
var attempts = ItalianText.Number(media.Attempts + 1);
|
||||
await _storage.Media.MarkFailedAsync(media.Id, MediaState.Failed, $"Indirizzo rifiutato anche dopo il rinnovo ({attempts} tentativi): il file resta «fallito».", _clock.Now, ct).ConfigureAwait(false);
|
||||
tally.Add(ref tally.Failed);
|
||||
Report(media, entry, DownloadStep.Failed);
|
||||
Report(media, entry, DownloadStep.Failed, bytes, DownloadCauses.RefusedAfterRenewal);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -604,7 +611,7 @@ public sealed class DownloadQueue
|
||||
};
|
||||
await _storage.Media.MarkFailedAsync(media.Id, entry.Kind == EntryKind.Story ? MediaState.Failed : MediaState.Expired, why, _clock.Now, ct).ConfigureAwait(false);
|
||||
tally.Add(ref tally.Expired);
|
||||
Report(media, entry, DownloadStep.Expired);
|
||||
Report(media, entry, DownloadStep.Expired, bytes);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -615,7 +622,7 @@ public sealed class DownloadQueue
|
||||
}
|
||||
|
||||
tally.Add(ref tally.Expired);
|
||||
Report(media, entry, DownloadStep.Expired);
|
||||
Report(media, entry, DownloadStep.Expired, bytes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -632,8 +639,8 @@ public sealed class DownloadQueue
|
||||
}
|
||||
}
|
||||
|
||||
private void Report(Media media, Entry entry, DownloadStep step) =>
|
||||
Progress?.Invoke(this, new DownloadProgress(media.Id, entry.Id, entry.AccountId, entry.Kind, step));
|
||||
private void Report(Media media, Entry entry, DownloadStep step, long? bytes = null, string? cause = null) =>
|
||||
Progress?.Invoke(this, new DownloadProgress(media.Id, entry.Id, entry.AccountId, entry.Kind, step, bytes) { Cause = cause });
|
||||
|
||||
/// <summary>The extension from the content (magic numbers), else from the kind of file.</summary>
|
||||
private static string Extension(string path, Media media)
|
||||
@@ -737,7 +744,44 @@ public enum DownloadStep
|
||||
Skipped,
|
||||
Expired,
|
||||
Failed,
|
||||
|
||||
/// <summary>Not settled: the file waits for a later attempt (a failure that may pass).</summary>
|
||||
Retried,
|
||||
}
|
||||
|
||||
/// <summary>Progress of the queue for the interface: identifiers only, never addresses.</summary>
|
||||
public sealed record DownloadProgress(long MediaId, long EntryId, long AccountId, EntryKind Kind, DownloadStep Step);
|
||||
/// <param name="Bytes">What crossed the network for this file (its cover included), when known.</param>
|
||||
public sealed record DownloadProgress(long MediaId, long EntryId, long AccountId, EntryKind Kind, DownloadStep Step, long? Bytes = null)
|
||||
{
|
||||
/// <summary>Why the file failed or waits for another attempt (<see cref="DownloadCauses"/>); null when it did not.</summary>
|
||||
public string? Cause { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Why a file failed or waits for another attempt, for the diagnostic report (issue #39): a closed list of codes,
|
||||
/// never an address or the text of an error.
|
||||
/// </summary>
|
||||
public static class DownloadCauses
|
||||
{
|
||||
/// <summary>A network error that is not a missing connection (the connection pauses the queue instead).</summary>
|
||||
public const string Network = "rete";
|
||||
|
||||
/// <summary>No connection at all: the queue pauses, the file waits without an attempt counted.</summary>
|
||||
public const string Connection = "connessione";
|
||||
|
||||
/// <summary>The file could not be written (disk full or similar).</summary>
|
||||
public const string Write = "scrittura";
|
||||
|
||||
/// <summary>The address of the file is not valid.</summary>
|
||||
public const string BadAddress = "indirizzo-non-valido";
|
||||
|
||||
/// <summary>The address is not of the CDN (spec §6.5).</summary>
|
||||
public const string HostNotAllowed = "host-non-ammesso";
|
||||
|
||||
/// <summary>The renewed address was refused again, too many times.</summary>
|
||||
public const string RefusedAfterRenewal = "rifiutato-dopo-rinnovo";
|
||||
|
||||
/// <summary>«http-404», «http-503»...: the status the CDN answered; <see cref="Network"/> without one.</summary>
|
||||
public static string Of(int? httpStatus) =>
|
||||
httpStatus is >= 100 and < 600 ? "http-" + httpStatus.Value.ToString(CultureInfo.InvariantCulture) : Network;
|
||||
}
|
||||
Reference in new issue
Block a user